-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: leleliu008 <[email protected]>
- Loading branch information
1 parent
3ecfc2c
commit c77f25a
Showing
18 changed files
with
363 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#include <unistd.h> | ||
|
||
#include <git2.h> | ||
|
||
static int git_submodule_foreach_callback(git_submodule * submodule, const char * name, void * payload) { | ||
unsigned int status = 0; | ||
|
||
int ret = git_submodule_status(&status, (git_repository*)payload, name, GIT_SUBMODULE_IGNORE_UNTRACKED); | ||
|
||
if (ret != GIT_OK) { | ||
const git_error * error = git_error_last(); | ||
fprintf(stderr, "%s\n", error->message); | ||
return ret; | ||
} | ||
|
||
printf("status of (%s):%u\n", name, status); | ||
|
||
return git_submodule_update(submodule, true, NULL); | ||
} | ||
|
||
int do_git_submodule_update_init(const char * gitRepoPath) { | ||
git_libgit2_init(); | ||
|
||
git_repository * gitRepo = NULL; | ||
|
||
// https://libgit2.org/libgit2/#HEAD/group/repository/git_repository_init | ||
int ret = git_repository_init(&gitRepo, gitRepoPath, false); | ||
|
||
if (ret != GIT_OK) { | ||
const git_error * error = git_error_last(); | ||
fprintf(stderr, "%s\n", error->message); | ||
} | ||
|
||
ret = git_submodule_foreach(gitRepo, git_submodule_foreach_callback, gitRepo); | ||
|
||
if (ret != GIT_OK) { | ||
const git_error * error = git_error_last(); | ||
fprintf(stderr, "%s\n", error->message); | ||
} | ||
|
||
git_repository_free(gitRepo); | ||
|
||
git_libgit2_shutdown(); | ||
|
||
return ret; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc == 1) { | ||
printf("%s [ -C <WORKING-DIR> ]\n", argv[0]); | ||
return 0; | ||
} | ||
|
||
const char * workingDirPath = "."; | ||
|
||
for (int i = 1; i < argc; i++) { | ||
if (strcmp(argv[i], "-C") == 0) { | ||
i++; | ||
workingDirPath = argv[i]; | ||
|
||
if (workingDirPath == NULL) { | ||
fprintf(stderr, "-C option should have non-empty value."); | ||
return 1; | ||
} | ||
} else { | ||
fprintf(stderr, "unrecognized option: %s", argv[i]); | ||
return 2; | ||
} | ||
} | ||
|
||
return do_git_submodule_update_init(workingDirPath); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,21 @@ | ||
// http://blog.fpliu.com/it/software/mbedTLS/include/base64.h | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <base64.h> | ||
|
||
#include "base64_mbedtls.h" | ||
|
||
size_t get_base64_encode_output_length_in_bytes(size_t inputBufferSizeInBytes) { | ||
//看看需要分配多少个字节 | ||
//编码后,长度变为原来的4/3倍 | ||
size_t n = inputBufferSizeInBytes / 3U + (((inputBufferSizeInBytes % 3U) == 0) ? 0U : 1U); | ||
return (n << 2); | ||
} | ||
|
||
int base64_encode(char* outputBuffer, size_t outputBufferSizeInBytes, unsigned char* inputBuffer, size_t inputBufferSizeInBytes) { | ||
size_t writtenToOutputBufferCountInBytes = 0U; | ||
if (0 == mbedtls_base64_encode((unsigned char*)outputBuffer, outputBufferSizeInBytes, &writtenToOutputBufferCountInBytes, inputBuffer, inputBufferSizeInBytes)) { | ||
return 0; | ||
} else { | ||
return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL; | ||
} | ||
int base64_encode(char * outputBuffer, size_t outputBufferSizeInBytes, unsigned char * inputBuffer, size_t inputBufferSizeInBytes) { | ||
size_t writtenSizeInBytes; | ||
return mbedtls_base64_encode((unsigned char*)outputBuffer, outputBufferSizeInBytes, &writtenSizeInBytes, inputBuffer, inputBufferSizeInBytes); | ||
} | ||
|
||
int base64_decode(unsigned char* outputBuffer, size_t outputBufferSizeInBytes, size_t* writtenToOutputBufferCountInBytes, char* input) { | ||
size_t inputBufferSizeInBytes = strlen(input); | ||
|
||
//base64编码的字符串的长度必须是4的整数倍 | ||
if ((inputBufferSizeInBytes & 3U) != 0U) { | ||
return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; | ||
} | ||
|
||
if (0 == mbedtls_base64_decode(outputBuffer, outputBufferSizeInBytes, writtenToOutputBufferCountInBytes, (unsigned char *)input, inputBufferSizeInBytes)) { | ||
return 0; | ||
} else { | ||
return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; | ||
} | ||
int base64_decode(unsigned char * outputBuffer, size_t outputBufferSizeInBytes, size_t * writtenSizeInBytes, char * inputBuffer, size_t inputBufferSizeInBytes) { | ||
return mbedtls_base64_decode(outputBuffer, outputBufferSizeInBytes, writtenSizeInBytes, (unsigned char *)inputBuffer, inputBufferSizeInBytes); | ||
} |
Oops, something went wrong.