diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cat-file.c | 10 | ||||
-rw-r--r-- | examples/fetch.c | 6 | ||||
-rw-r--r-- | examples/for-each-ref.c | 4 | ||||
-rw-r--r-- | examples/general.c | 43 | ||||
-rw-r--r-- | examples/log.c | 2 | ||||
-rw-r--r-- | examples/ls-remote.c | 2 | ||||
-rw-r--r-- | examples/rev-list.c | 10 | ||||
-rw-r--r-- | examples/rev-parse.c | 2 | ||||
-rw-r--r-- | examples/show-index.c | 4 |
9 files changed, 59 insertions, 24 deletions
diff --git a/examples/cat-file.c b/examples/cat-file.c index b81e9a8da..741edb484 100644 --- a/examples/cat-file.c +++ b/examples/cat-file.c @@ -49,7 +49,7 @@ static void show_blob(const git_blob *blob) static void show_tree(const git_tree *tree) { size_t i, max_i = (int)git_tree_entrycount(tree); - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; const git_tree_entry *te; for (i = 0; i < max_i; ++i) { @@ -70,7 +70,7 @@ static void show_tree(const git_tree *tree) static void show_commit(const git_commit *commit) { unsigned int i, max_i; - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_commit_tree_id(commit)); printf("tree %s\n", oidstr); @@ -90,7 +90,7 @@ static void show_commit(const git_commit *commit) static void show_tag(const git_tag *tag) { - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_tag_target_id(tag));; printf("object %s\n", oidstr); @@ -125,7 +125,7 @@ int lg2_cat_file(git_repository *repo, int argc, char *argv[]) { struct catfile_options o = { ".", NULL, 0, 0 }; git_object *obj = NULL; - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; parse_opts(&o, argc, argv); @@ -133,7 +133,7 @@ int lg2_cat_file(git_repository *repo, int argc, char *argv[]) "Could not resolve", o.rev); if (o.verbose) { - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_object_id(obj)); printf("%s %s\n--\n", diff --git a/examples/fetch.c b/examples/fetch.c index 2b5ed1112..bbd882cfb 100644 --- a/examples/fetch.c +++ b/examples/fetch.c @@ -15,17 +15,17 @@ static int progress_cb(const char *str, int len, void *data) */ static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data) { - char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1]; + char a_str[GIT_OID_SHA1_HEXSIZE+1], b_str[GIT_OID_SHA1_HEXSIZE+1]; (void)data; git_oid_fmt(b_str, b); - b_str[GIT_OID_HEXSZ] = '\0'; + b_str[GIT_OID_SHA1_HEXSIZE] = '\0'; if (git_oid_is_zero(a)) { printf("[new] %.20s %s\n", b_str, refname); } else { git_oid_fmt(a_str, a); - a_str[GIT_OID_HEXSZ] = '\0'; + a_str[GIT_OID_SHA1_HEXSIZE] = '\0'; printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname); } diff --git a/examples/for-each-ref.c b/examples/for-each-ref.c index 020dab474..a0706741a 100644 --- a/examples/for-each-ref.c +++ b/examples/for-each-ref.c @@ -5,7 +5,7 @@ static int show_ref(git_reference *ref, void *data) { git_repository *repo = data; git_reference *resolved = NULL; - char hex[GIT_OID_HEXSZ+1]; + char hex[GIT_OID_SHA1_HEXSIZE+1]; const git_oid *oid; git_object *obj; @@ -16,7 +16,7 @@ static int show_ref(git_reference *ref, void *data) oid = git_reference_target(resolved ? resolved : ref); git_oid_fmt(hex, oid); - hex[GIT_OID_HEXSZ] = 0; + hex[GIT_OID_SHA1_HEXSIZE] = 0; check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJECT_ANY), "Unable to lookup object", hex); diff --git a/examples/general.c b/examples/general.c index 2127ec0e1..7f44cd786 100644 --- a/examples/general.c +++ b/examples/general.c @@ -129,7 +129,7 @@ int lg2_general(git_repository *repo, int argc, char** argv) */ static void oid_parsing(git_oid *oid) { - char out[GIT_OID_HEXSZ+1]; + char out[GIT_OID_SHA1_HEXSIZE+1]; char hex[] = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"; printf("*Hex to Raw*\n"); @@ -142,7 +142,11 @@ static void oid_parsing(git_oid *oid) * this throughout the example for storing the value of the current SHA * key we're working with. */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(oid, hex, GIT_OID_SHA1); +#else git_oid_fromstr(oid, hex); +#endif /* * Once we've converted the string into the oid value, we can get the raw @@ -152,7 +156,7 @@ static void oid_parsing(git_oid *oid) * char hex value. */ printf("\n*Raw to Hex*\n"); - out[GIT_OID_HEXSZ] = '\0'; + out[GIT_OID_SHA1_HEXSIZE] = '\0'; /** * If you have a oid, you can easily get the hex value of the SHA as well. @@ -173,7 +177,7 @@ static void oid_parsing(git_oid *oid) */ static void object_database(git_repository *repo, git_oid *oid) { - char oid_hex[GIT_OID_HEXSZ+1] = { 0 }; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 }; const unsigned char *data; const char *str_type; int error; @@ -266,7 +270,7 @@ static void commit_writing(git_repository *repo) git_tree *tree; git_commit *parent; git_signature *author, *committer; - char oid_hex[GIT_OID_HEXSZ+1] = { 0 }; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 }; printf("\n*Commit Writing*\n"); @@ -287,9 +291,14 @@ static void commit_writing(git_repository *repo) * parents. Here we're creating oid objects to create the commit with, * but you can also use */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1); + git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); +#else git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1"); - git_tree_lookup(&tree, repo, &tree_id); git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); +#endif + git_tree_lookup(&tree, repo, &tree_id); git_commit_lookup(&parent, repo, &parent_id); /** @@ -345,7 +354,7 @@ static void commit_parsing(git_repository *repo) const git_signature *author, *cmtter; git_commit *commit, *parent; git_oid oid; - char oid_hex[GIT_OID_HEXSZ+1]; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1]; const char *message; unsigned int parents, p; int error; @@ -353,7 +362,11 @@ static void commit_parsing(git_repository *repo) printf("\n*Commit Parsing*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"); +#endif error = git_commit_lookup(&commit, repo, &oid); check_error(error, "looking up commit"); @@ -422,7 +435,11 @@ static void tag_parsing(git_repository *repo) * We create an oid for the tag object if we know the SHA and look it up * the same way that we would a commit (or any other object). */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); +#endif error = git_tag_lookup(&tag, repo, &oid); check_error(error, "looking up tag"); @@ -470,7 +487,11 @@ static void tree_parsing(git_repository *repo) /** * Create the oid and lookup the tree object just like the other objects. */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1"); +#endif git_tree_lookup(&tree, repo, &oid); /** @@ -524,7 +545,11 @@ static void blob_parsing(git_repository *repo) printf("\n*Blob Parsing*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08"); +#endif git_blob_lookup(&blob, repo, &oid); /** @@ -566,7 +591,11 @@ static void revwalking(git_repository *repo) printf("\n*Revwalking*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); +#endif /** * To use the revwalker, create a new walker, tell it how you want to sort @@ -679,7 +708,7 @@ static void reference_listing(git_repository *repo) for (i = 0; i < ref_list.count; ++i) { git_reference *ref; - char oid_hex[GIT_OID_HEXSZ+1] = GIT_OID_HEX_ZERO; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = GIT_OID_SHA1_HEXZERO; const char *refname; refname = ref_list.strings[i]; diff --git a/examples/log.c b/examples/log.c index 9060f3f3e..4b0a95dcd 100644 --- a/examples/log.c +++ b/examples/log.c @@ -329,7 +329,7 @@ static void print_time(const git_time *intime, const char *prefix) /** Helper to print a commit object. */ static void print_commit(git_commit *commit, struct log_options *opts) { - char buf[GIT_OID_HEXSZ + 1]; + char buf[GIT_OID_SHA1_HEXSIZE + 1]; int i, count; const git_signature *sig; const char *scan, *eol; diff --git a/examples/ls-remote.c b/examples/ls-remote.c index 03ed887d1..24caae712 100644 --- a/examples/ls-remote.c +++ b/examples/ls-remote.c @@ -34,7 +34,7 @@ static int use_remote(git_repository *repo, char *name) goto cleanup; for (i = 0; i < refs_len; i++) { - char oid[GIT_OID_HEXSZ + 1] = {0}; + char oid[GIT_OID_SHA1_HEXSIZE + 1] = {0}; git_oid_fmt(oid, &refs[i]->oid); printf("%s\t%s\n", oid, refs[i]->name); } diff --git a/examples/rev-list.c b/examples/rev-list.c index d10f16690..cf8ac30c6 100644 --- a/examples/rev-list.c +++ b/examples/rev-list.c @@ -26,7 +26,7 @@ int lg2_rev_list(git_repository *repo, int argc, char **argv) git_revwalk *walk; git_oid oid; git_sort_t sort; - char buf[GIT_OID_HEXSZ+1]; + char buf[GIT_OID_SHA1_HEXSIZE+1]; check_lg2(revwalk_parse_options(&sort, &args), "parsing options", NULL); @@ -36,7 +36,7 @@ int lg2_rev_list(git_repository *repo, int argc, char **argv) while (!git_revwalk_next(&oid, walk)) { git_oid_fmt(buf, &oid); - buf[GIT_OID_HEXSZ] = '\0'; + buf[GIT_OID_SHA1_HEXSIZE] = '\0'; printf("%s\n", buf); } @@ -140,8 +140,14 @@ static int revwalk_parse_revs(git_repository *repo, git_revwalk *walk, struct ar if (push_spec(repo, walk, curr, hide) == 0) continue; +#ifdef GIT_EXPERIMENTAL_SHA256 + if ((error = git_oid_fromstr(&oid, curr, GIT_OID_SHA1))) + return error; +#else if ((error = git_oid_fromstr(&oid, curr))) return error; +#endif + if ((error = push_commit(walk, &oid, hide))) return error; } diff --git a/examples/rev-parse.c b/examples/rev-parse.c index 90258c101..3f68d79b7 100644 --- a/examples/rev-parse.c +++ b/examples/rev-parse.c @@ -65,7 +65,7 @@ static void parse_opts(struct parse_state *ps, int argc, char *argv[]) static int parse_revision(git_repository *repo, struct parse_state *ps) { git_revspec rs; - char str[GIT_OID_HEXSZ + 1]; + char str[GIT_OID_SHA1_HEXSIZE + 1]; check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec); diff --git a/examples/show-index.c b/examples/show-index.c index 7aaa45e65..fb797e04b 100644 --- a/examples/show-index.c +++ b/examples/show-index.c @@ -20,8 +20,8 @@ int lg2_show_index(git_repository *repo, int argc, char **argv) size_t i, ecount; char *dir = "."; size_t dirlen; - char out[GIT_OID_HEXSZ+1]; - out[GIT_OID_HEXSZ] = '\0'; + char out[GIT_OID_SHA1_HEXSIZE+1]; + out[GIT_OID_SHA1_HEXSIZE] = '\0'; if (argc > 2) fatal("usage: showindex [<repo-dir>]", NULL); |