{"thread":{"id":"38797","subject":"[PATCH v2 01/10] Define a structure for object IDs.","startedAt":"2015-03-13T23:39:26Z","lastAt":"2015-03-14T14:16:19Z","messageCount":12,"participants":["brian m. carlson"],"isPatch":true,"patchVersion":2,"patchTotal":10},"messages":[{"id":"257652","messageId":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":null,"subject":"[PATCH v2 00/10] Use a structure for object IDs.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:26Z","receivedAt":"2015-03-13T23:39:26Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is a patch series to convert some of the relevant uses of unsigned\nchar [20] to struct object_id.\n\nThe goal of this series to improve type-checking in the codebase and to\nmake it easier to move to a different hash function if the project\ndecides to do that.\n\nThere should be no functional change from this patch series.\n\nI've tried to adopt most of the suggestions where possible without major\nreworking.\n\nChanges since v1:\n* Call the struct member \"hash\".\n* Convert some additional magic numbers to be based off the constants\n  GIT_SHA1_RAWSZ and GIT_SHA1_HEXSZ.  Introduce variables where this\n  makes sense.\n* Define GIT_SHA1_HEXSZ in terms of GIT_SHA1_RAWSZ.\n* Move the definition of struct object_id to cache.h.  No new #includes\n  are required as a result.\n* Use better names for arguments to oidcmp.\n* Convert one or two structs that were missed last time.\n\nYou can see this series on the object-id branch (may be rebased) at\n\n  https://github.com/bk2204/git.git\n  https://git.crustytoothpaste.net/git/bmc/git.git\n\nBoth repositories are pushed at the same time.\n\nbrian m. carlson (10):\n  Define a structure for object IDs.\n  Define utility functions for object IDs.\n  bisect.c: convert leaf functions to use struct object_id\n  archive.c: convert to use struct object_id\n  zip: use GIT_SHA1_HEXSZ for trailers\n  bulk-checkin.c: convert to use struct object_id\n  diff: convert struct combine_diff_path to object_id\n  commit: convert parts to struct object_id\n  patch-id: convert to use struct object_id\n  apply: convert threeway_stage to object_id\n\n archive-zip.c      |  4 ++--\n archive.c          | 22 ++++++++++-----------\n bisect.c           | 40 +++++++++++++++++++-------------------\n builtin/apply.c    | 14 +++++++-------\n builtin/patch-id.c | 34 ++++++++++++++++-----------------\n bulk-checkin.c     | 12 ++++++------\n cache.h            | 40 ++++++++++++++++++++++++++++++++++----\n combine-diff.c     | 56 +++++++++++++++++++++++++++---------------------------\n commit.c           | 56 +++++++++++++++++++++++++++++-------------------------\n commit.h           |  4 ++--\n diff-lib.c         | 10 +++++-----\n diff.h             |  5 +++--\n hex.c              | 16 +++++++++++++---\n log-tree.c         |  2 +-\n send-pack.c        |  2 +-\n shallow.c          |  8 ++++----\n tree-diff.c        | 10 +++++-----\n upload-pack.c      |  2 +-\n 18 files changed, 192 insertions(+), 145 deletions(-)\n\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257651","messageId":"1426289976-568060-2-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 01/10] Define a structure for object IDs.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:27Z","receivedAt":"2015-03-13T23:39:27Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Many places throughout the code use \"unsigned char [20]\" to store object IDs\n(SHA-1 values).  This leads to lots of hardcoded numbers throughout the\ncodebase.  It also leads to confusion about the purposes of a buffer.\n\nIntroduce a structure for object IDs.  This allows us to obtain the benefits\nof compile-time checking for misuse.  The structure is expected to remain\nthe same size and have the same alignment requirements on all known\nplatforms, compared to the array of unsigned char, although this is not\nrequired for correctness.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 761c570..6582c35 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -43,6 +43,14 @@ int git_deflate_end_gently(git_zstream *);\n int git_deflate(git_zstream *, int flush);\n unsigned long git_deflate_bound(git_zstream *, unsigned long);\n \n+/* The length in bytes and in hex digits of an object name (SHA-1 value). */\n+#define GIT_SHA1_RAWSZ 20\n+#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)\n+\n+struct object_id {\n+\tunsigned char hash[GIT_SHA1_RAWSZ];\n+};\n+\n #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)\n #define DTYPE(de)\t((de)->d_type)\n #else\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257660","messageId":"1426289976-568060-3-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 02/10] Define utility functions for object IDs.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:28Z","receivedAt":"2015-03-13T23:39:28Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"There are several utility functions (hashcmp and friends) that are used\nfor comparing object IDs (SHA-1 values).  Using these functions, which\ntake pointers to unsigned char, with struct object_id requires tiresome\naccess to the sha1 member, which bloats code and violates the desired\nencapsulation.  Provide wrappers around these functions for struct\nobject_id for neater, more maintainable code.  Use the new constants to\navoid the hard-coded 20s and 40s throughout the original functions.\n\nThese functions simply call the underlying pointer-to-unsigned-char\nversions to ensure that any performance improvements will be passed\nthrough to the new functions.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h | 32 ++++++++++++++++++++++++++++----\n hex.c   | 16 +++++++++++++---\n 2 files changed, 41 insertions(+), 7 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 6582c35..95206a3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -718,13 +718,13 @@ extern char *sha1_pack_name(const unsigned char *sha1);\n extern char *sha1_pack_index_name(const unsigned char *sha1);\n \n extern const char *find_unique_abbrev(const unsigned char *sha1, int);\n-extern const unsigned char null_sha1[20];\n+extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];\n \n static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n {\n \tint i;\n \n-\tfor (i = 0; i < 20; i++, sha1++, sha2++) {\n+\tfor (i = 0; i < GIT_SHA1_RAWSZ; i++, sha1++, sha2++) {\n \t\tif (*sha1 != *sha2)\n \t\t\treturn *sha1 - *sha2;\n \t}\n@@ -732,20 +732,42 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n \treturn 0;\n }\n \n+static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)\n+{\n+\treturn hashcmp(oid1->hash, oid2->hash);\n+}\n+\n static inline int is_null_sha1(const unsigned char *sha1)\n {\n \treturn !hashcmp(sha1, null_sha1);\n }\n \n+static inline int is_null_oid(const struct object_id *oid)\n+{\n+\treturn !hashcmp(oid->hash, null_sha1);\n+}\n+\n static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)\n {\n-\tmemcpy(sha_dst, sha_src, 20);\n+\tmemcpy(sha_dst, sha_src, GIT_SHA1_RAWSZ);\n }\n+\n+static inline void oidcpy(struct object_id *dst, const struct object_id *src)\n+{\n+\thashcpy(dst->hash, src->hash);\n+}\n+\n static inline void hashclr(unsigned char *hash)\n {\n-\tmemset(hash, 0, 20);\n+\tmemset(hash, 0, GIT_SHA1_RAWSZ);\n }\n \n+static inline void oidclr(struct object_id *oid)\n+{\n+\thashclr(oid->hash);\n+}\n+\n+\n #define EMPTY_TREE_SHA1_HEX \\\n \t\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"\n #define EMPTY_TREE_SHA1_BIN_LITERAL \\\n@@ -952,8 +974,10 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n  * null-terminated string.\n  */\n extern int get_sha1_hex(const char *hex, unsigned char *sha1);\n+extern int get_oid_hex(const char *hex, struct object_id *sha1);\n \n extern char *sha1_to_hex(const unsigned char *sha1);\t/* static buffer result! */\n+extern char *oid_to_hex(const struct object_id *oid);\t/* same static buffer as sha1_to_hex */\n extern int read_ref_full(const char *refname, int resolve_flags,\n \t\t\t unsigned char *sha1, int *flags);\n extern int read_ref(const char *refname, unsigned char *sha1);\ndiff --git a/hex.c b/hex.c\nindex cfd9d72..899b74a 100644\n--- a/hex.c\n+++ b/hex.c\n@@ -38,7 +38,7 @@ const signed char hexval_table[256] = {\n int get_sha1_hex(const char *hex, unsigned char *sha1)\n {\n \tint i;\n-\tfor (i = 0; i < 20; i++) {\n+\tfor (i = 0; i < GIT_SHA1_RAWSZ; i++) {\n \t\tunsigned int val;\n \t\t/*\n \t\t * hex[1]=='\\0' is caught when val is checked below,\n@@ -56,15 +56,20 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)\n \treturn 0;\n }\n \n+int get_oid_hex(const char *hex, struct object_id *oid)\n+{\n+\treturn get_sha1_hex(hex, oid->hash);\n+}\n+\n char *sha1_to_hex(const unsigned char *sha1)\n {\n \tstatic int bufno;\n-\tstatic char hexbuffer[4][41];\n+\tstatic char hexbuffer[4][GIT_SHA1_HEXSZ + 1];\n \tstatic const char hex[] = \"0123456789abcdef\";\n \tchar *buffer = hexbuffer[3 & ++bufno], *buf = buffer;\n \tint i;\n \n-\tfor (i = 0; i < 20; i++) {\n+\tfor (i = 0; i < GIT_SHA1_RAWSZ; i++) {\n \t\tunsigned int val = *sha1++;\n \t\t*buf++ = hex[val >> 4];\n \t\t*buf++ = hex[val & 0xf];\n@@ -73,3 +78,8 @@ char *sha1_to_hex(const unsigned char *sha1)\n \n \treturn buffer;\n }\n+\n+char *oid_to_hex(const struct object_id *oid)\n+{\n+\treturn sha1_to_hex(oid->hash);\n+}\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257661","messageId":"1426289976-568060-4-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 03/10] bisect.c: convert leaf functions to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:29Z","receivedAt":"2015-03-13T23:39:29Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert some constants to GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bisect.c | 40 ++++++++++++++++++++--------------------\n 1 file changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 8c6d843..10f5e57 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -15,7 +15,7 @@\n static struct sha1_array good_revs;\n static struct sha1_array skipped_revs;\n \n-static unsigned char *current_bad_sha1;\n+static struct object_id *current_bad_oid;\n \n static const char *argv_checkout[] = {\"checkout\", \"-q\", NULL, \"--\", NULL};\n static const char *argv_show_branch[] = {\"show-branch\", NULL, NULL};\n@@ -404,8 +404,8 @@ static int register_ref(const char *refname, const unsigned char *sha1,\n \t\t\tint flags, void *cb_data)\n {\n \tif (!strcmp(refname, \"bad\")) {\n-\t\tcurrent_bad_sha1 = xmalloc(20);\n-\t\thashcpy(current_bad_sha1, sha1);\n+\t\tcurrent_bad_oid = xmalloc(sizeof(*current_bad_oid));\n+\t\thashcpy(current_bad_oid->hash, sha1);\n \t} else if (starts_with(refname, \"good-\")) {\n \t\tsha1_array_append(&good_revs, sha1);\n \t} else if (starts_with(refname, \"skip-\")) {\n@@ -564,7 +564,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)\n \n \tfor (i = 0; cur; cur = cur->next, i++) {\n \t\tif (i == index) {\n-\t\t\tif (hashcmp(cur->item->object.sha1, current_bad_sha1))\n+\t\t\tif (hashcmp(cur->item->object.sha1, current_bad_oid->hash))\n \t\t\t\treturn cur;\n \t\t\tif (previous)\n \t\t\t\treturn previous;\n@@ -607,7 +607,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,\n \n \t/* rev_argv.argv[0] will be ignored by setup_revisions */\n \targv_array_push(&rev_argv, \"bisect_rev_setup\");\n-\targv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1));\n+\targv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));\n \tfor (i = 0; i < good_revs.nr; i++)\n \t\targv_array_pushf(&rev_argv, good_format,\n \t\t\t\t sha1_to_hex(good_revs.sha1[i]));\n@@ -628,7 +628,7 @@ static void bisect_common(struct rev_info *revs)\n }\n \n static void exit_if_skipped_commits(struct commit_list *tried,\n-\t\t\t\t    const unsigned char *bad)\n+\t\t\t\t    const struct object_id *bad)\n {\n \tif (!tried)\n \t\treturn;\n@@ -637,12 +637,12 @@ static void exit_if_skipped_commits(struct commit_list *tried,\n \t       \"The first bad commit could be any of:\\n\");\n \tprint_commit_list(tried, \"%s\\n\", \"%s\\n\");\n \tif (bad)\n-\t\tprintf(\"%s\\n\", sha1_to_hex(bad));\n+\t\tprintf(\"%s\\n\", oid_to_hex(bad));\n \tprintf(\"We cannot bisect more!\\n\");\n \texit(2);\n }\n \n-static int is_expected_rev(const unsigned char *sha1)\n+static int is_expected_rev(const struct object_id *oid)\n {\n \tconst char *filename = git_path(\"BISECT_EXPECTED_REV\");\n \tstruct stat st;\n@@ -658,7 +658,7 @@ static int is_expected_rev(const unsigned char *sha1)\n \t\treturn 0;\n \n \tif (strbuf_getline(&str, fp, '\\n') != EOF)\n-\t\tres = !strcmp(str.buf, sha1_to_hex(sha1));\n+\t\tres = !strcmp(str.buf, oid_to_hex(oid));\n \n \tstrbuf_release(&str);\n \tfclose(fp);\n@@ -719,7 +719,7 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)\n \tstruct commit **rev = xmalloc(len * sizeof(*rev));\n \tint i, n = 0;\n \n-\trev[n++] = get_commit_reference(current_bad_sha1);\n+\trev[n++] = get_commit_reference(current_bad_oid->hash);\n \tfor (i = 0; i < good_revs.nr; i++)\n \t\trev[n++] = get_commit_reference(good_revs.sha1[i]);\n \t*rev_nr = n;\n@@ -729,8 +729,8 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)\n \n static void handle_bad_merge_base(void)\n {\n-\tif (is_expected_rev(current_bad_sha1)) {\n-\t\tchar *bad_hex = sha1_to_hex(current_bad_sha1);\n+\tif (is_expected_rev(current_bad_oid)) {\n+\t\tchar *bad_hex = oid_to_hex(current_bad_oid);\n \t\tchar *good_hex = join_sha1_array_hex(&good_revs, ' ');\n \n \t\tfprintf(stderr, \"The merge base %s is bad.\\n\"\n@@ -750,7 +750,7 @@ static void handle_bad_merge_base(void)\n static void handle_skipped_merge_base(const unsigned char *mb)\n {\n \tchar *mb_hex = sha1_to_hex(mb);\n-\tchar *bad_hex = sha1_to_hex(current_bad_sha1);\n+\tchar *bad_hex = sha1_to_hex(current_bad_oid->hash);\n \tchar *good_hex = join_sha1_array_hex(&good_revs, ' ');\n \n \twarning(\"the merge base between %s and [%s] \"\n@@ -781,7 +781,7 @@ static void check_merge_bases(int no_checkout)\n \n \tfor (; result; result = result->next) {\n \t\tconst unsigned char *mb = result->item->object.sha1;\n-\t\tif (!hashcmp(mb, current_bad_sha1)) {\n+\t\tif (!hashcmp(mb, current_bad_oid->hash)) {\n \t\t\thandle_bad_merge_base();\n \t\t} else if (0 <= sha1_array_lookup(&good_revs, mb)) {\n \t\t\tcontinue;\n@@ -838,7 +838,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n \tstruct stat st;\n \tint fd;\n \n-\tif (!current_bad_sha1)\n+\tif (!current_bad_oid)\n \t\tdie(\"a bad revision is needed\");\n \n \t/* Check if file BISECT_ANCESTORS_OK exists. */\n@@ -903,7 +903,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \tstruct commit_list *tried;\n \tint reaches = 0, all = 0, nr, steps;\n \tconst unsigned char *bisect_rev;\n-\tchar bisect_rev_hex[41];\n+\tchar bisect_rev_hex[GIT_SHA1_HEXSZ + 1];\n \n \tif (read_bisect_refs())\n \t\tdie(\"reading bisect refs failed\");\n@@ -927,7 +927,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \t\texit_if_skipped_commits(tried, NULL);\n \n \t\tprintf(\"%s was both good and bad\\n\",\n-\t\t       sha1_to_hex(current_bad_sha1));\n+\t\t       oid_to_hex(current_bad_oid));\n \t\texit(1);\n \t}\n \n@@ -938,10 +938,10 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \t}\n \n \tbisect_rev = revs.commits->item->object.sha1;\n-\tmemcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), 41);\n+\tmemcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);\n \n-\tif (!hashcmp(bisect_rev, current_bad_sha1)) {\n-\t\texit_if_skipped_commits(tried, current_bad_sha1);\n+\tif (!hashcmp(bisect_rev, current_bad_oid->hash)) {\n+\t\texit_if_skipped_commits(tried, current_bad_oid);\n \t\tprintf(\"%s is the first bad commit\\n\", bisect_rev_hex);\n \t\tshow_diff_tree(prefix, revs.commits->item);\n \t\t/* This means the bisection process succeeded. */\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257659","messageId":"1426289976-568060-5-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 04/10] archive.c: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:30Z","receivedAt":"2015-03-13T23:39:30Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n archive.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 96057ed..d37c41d 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -101,7 +101,7 @@ static void setup_archive_check(struct git_attr_check *check)\n \n struct directory {\n \tstruct directory *up;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint baselen, len;\n \tunsigned mode;\n \tint stage;\n@@ -177,7 +177,7 @@ static void queue_directory(const unsigned char *sha1,\n \td->stage   = stage;\n \tc->bottom  = d;\n \td->len = sprintf(d->path, \"%.*s%s/\", (int)base->len, base->buf, filename);\n-\thashcpy(d->sha1, sha1);\n+\thashcpy(d->oid.hash, sha1);\n }\n \n static int write_directory(struct archiver_context *c)\n@@ -191,7 +191,7 @@ static int write_directory(struct archiver_context *c)\n \td->path[d->len - 1] = '\\0'; /* no trailing slash */\n \tret =\n \t\twrite_directory(c) ||\n-\t\twrite_archive_entry(d->sha1, d->path, d->baselen,\n+\t\twrite_archive_entry(d->oid.hash, d->path, d->baselen,\n \t\t\t\t    d->path + d->baselen, d->mode,\n \t\t\t\t    d->stage, c) != READ_TREE_RECURSIVE;\n \tfree(d);\n@@ -354,7 +354,7 @@ static void parse_treeish_arg(const char **argv,\n \ttime_t archive_time;\n \tstruct tree *tree;\n \tconst struct commit *commit;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \t/* Remotes are only allowed to fetch actual refs */\n \tif (remote && !remote_allow_unreachable) {\n@@ -362,15 +362,15 @@ static void parse_treeish_arg(const char **argv,\n \t\tconst char *colon = strchrnul(name, ':');\n \t\tint refnamelen = colon - name;\n \n-\t\tif (!dwim_ref(name, refnamelen, sha1, &ref))\n+\t\tif (!dwim_ref(name, refnamelen, oid.hash, &ref))\n \t\t\tdie(\"no such ref: %.*s\", refnamelen, name);\n \t\tfree(ref);\n \t}\n \n-\tif (get_sha1(name, sha1))\n+\tif (get_sha1(name, oid.hash))\n \t\tdie(\"Not a valid object name\");\n \n-\tcommit = lookup_commit_reference_gently(sha1, 1);\n+\tcommit = lookup_commit_reference_gently(oid.hash, 1);\n \tif (commit) {\n \t\tcommit_sha1 = commit->object.sha1;\n \t\tarchive_time = commit->date;\n@@ -379,21 +379,21 @@ static void parse_treeish_arg(const char **argv,\n \t\tarchive_time = time(NULL);\n \t}\n \n-\ttree = parse_tree_indirect(sha1);\n+\ttree = parse_tree_indirect(oid.hash);\n \tif (tree == NULL)\n \t\tdie(\"not a tree object\");\n \n \tif (prefix) {\n-\t\tunsigned char tree_sha1[20];\n+\t\tstruct object_id tree_oid;\n \t\tunsigned int mode;\n \t\tint err;\n \n \t\terr = get_tree_entry(tree->object.sha1, prefix,\n-\t\t\t\t     tree_sha1, &mode);\n+\t\t\t\t     tree_oid.hash, &mode);\n \t\tif (err || !S_ISDIR(mode))\n \t\t\tdie(\"current working directory is untracked\");\n \n-\t\ttree = parse_tree_indirect(tree_sha1);\n+\t\ttree = parse_tree_indirect(tree_oid.hash);\n \t}\n \tar_args->tree = tree;\n \tar_args->commit_sha1 = commit_sha1;\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257654","messageId":"1426289976-568060-6-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 05/10] zip: use GIT_SHA1_HEXSZ for trailers","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:31Z","receivedAt":"2015-03-13T23:39:31Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n archive-zip.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/archive-zip.c b/archive-zip.c\nindex 4bde019..b669e50 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -427,12 +427,12 @@ static void write_zip_trailer(const unsigned char *sha1)\n \tcopy_le16(trailer.entries, zip_dir_entries);\n \tcopy_le32(trailer.size, zip_dir_offset);\n \tcopy_le32(trailer.offset, zip_offset);\n-\tcopy_le16(trailer.comment_length, sha1 ? 40 : 0);\n+\tcopy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);\n \n \twrite_or_die(1, zip_dir, zip_dir_offset);\n \twrite_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);\n \tif (sha1)\n-\t\twrite_or_die(1, sha1_to_hex(sha1), 40);\n+\t\twrite_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);\n }\n \n static void dos_time(time_t *time, int *dos_date, int *dos_time)\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257653","messageId":"1426289976-568060-7-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 06/10] bulk-checkin.c: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:32Z","receivedAt":"2015-03-13T23:39:32Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bulk-checkin.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 0c4b8a7..c80e503 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -24,7 +24,7 @@ static struct bulk_checkin_state {\n \n static void finish_bulk_checkin(struct bulk_checkin_state *state)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct strbuf packname = STRBUF_INIT;\n \tint i;\n \n@@ -36,11 +36,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \t\tunlink(state->pack_tmp_name);\n \t\tgoto clear_exit;\n \t} else if (state->nr_written == 1) {\n-\t\tsha1close(state->f, sha1, CSUM_FSYNC);\n+\t\tsha1close(state->f, oid.hash, CSUM_FSYNC);\n \t} else {\n-\t\tint fd = sha1close(state->f, sha1, 0);\n-\t\tfixup_pack_header_footer(fd, sha1, state->pack_tmp_name,\n-\t\t\t\t\t state->nr_written, sha1,\n+\t\tint fd = sha1close(state->f, oid.hash, 0);\n+\t\tfixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name,\n+\t\t\t\t\t state->nr_written, oid.hash,\n \t\t\t\t\t state->offset);\n \t\tclose(fd);\n \t}\n@@ -48,7 +48,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \tstrbuf_addf(&packname, \"%s/pack/pack-\", get_object_directory());\n \tfinish_tmp_packfile(&packname, state->pack_tmp_name,\n \t\t\t    state->written, state->nr_written,\n-\t\t\t    &state->pack_idx_opts, sha1);\n+\t\t\t    &state->pack_idx_opts, oid.hash);\n \tfor (i = 0; i < state->nr_written; i++)\n \t\tfree(state->written[i]);\n \n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257656","messageId":"1426289976-568060-8-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 07/10] diff: convert struct combine_diff_path to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:33Z","receivedAt":"2015-03-13T23:39:33Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Also, convert a constant to GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n combine-diff.c | 56 ++++++++++++++++++++++++++++----------------------------\n diff-lib.c     | 10 +++++-----\n diff.h         |  5 +++--\n tree-diff.c    | 10 +++++-----\n 4 files changed, 41 insertions(+), 40 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 91edce5..8eb7278 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -44,9 +44,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,\n \t\t\tmemset(p->parent, 0,\n \t\t\t       sizeof(p->parent[0]) * num_parent);\n \n-\t\t\thashcpy(p->sha1, q->queue[i]->two->sha1);\n+\t\t\thashcpy(p->oid.hash, q->queue[i]->two->sha1);\n \t\t\tp->mode = q->queue[i]->two->mode;\n-\t\t\thashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);\n+\t\t\thashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);\n \t\t\tp->parent[n].mode = q->queue[i]->one->mode;\n \t\t\tp->parent[n].status = q->queue[i]->status;\n \t\t\t*tail = p;\n@@ -77,7 +77,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,\n \t\t\tcontinue;\n \t\t}\n \n-\t\thashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);\n+\t\thashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);\n \t\tp->parent[n].mode = q->queue[i]->one->mode;\n \t\tp->parent[n].status = q->queue[i]->status;\n \n@@ -284,7 +284,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,\n \treturn base;\n }\n \n-static char *grab_blob(const unsigned char *sha1, unsigned int mode,\n+static char *grab_blob(const struct object_id *oid, unsigned int mode,\n \t\t       unsigned long *size, struct userdiff_driver *textconv,\n \t\t       const char *path)\n {\n@@ -294,20 +294,20 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,\n \tif (S_ISGITLINK(mode)) {\n \t\tblob = xmalloc(100);\n \t\t*size = snprintf(blob, 100,\n-\t\t\t\t \"Subproject commit %s\\n\", sha1_to_hex(sha1));\n-\t} else if (is_null_sha1(sha1)) {\n+\t\t\t\t \"Subproject commit %s\\n\", oid_to_hex(oid));\n+\t} else if (is_null_oid(oid)) {\n \t\t/* deleted blob */\n \t\t*size = 0;\n \t\treturn xcalloc(1, 1);\n \t} else if (textconv) {\n \t\tstruct diff_filespec *df = alloc_filespec(path);\n-\t\tfill_filespec(df, sha1, 1, mode);\n+\t\tfill_filespec(df, oid->hash, 1, mode);\n \t\t*size = fill_textconv(textconv, df, &blob);\n \t\tfree_filespec(df);\n \t} else {\n-\t\tblob = read_sha1_file(sha1, &type, size);\n+\t\tblob = read_sha1_file(oid->hash, &type, size);\n \t\tif (type != OBJ_BLOB)\n-\t\t\tdie(\"object '%s' is not a blob!\", sha1_to_hex(sha1));\n+\t\t\tdie(\"object '%s' is not a blob!\", oid_to_hex(oid));\n \t}\n \treturn blob;\n }\n@@ -389,7 +389,7 @@ static void consume_line(void *state_, char *line, unsigned long len)\n \t}\n }\n \n-static void combine_diff(const unsigned char *parent, unsigned int mode,\n+static void combine_diff(const struct object_id *parent, unsigned int mode,\n \t\t\t mmfile_t *result_file,\n \t\t\t struct sline *sline, unsigned int cnt, int n,\n \t\t\t int num_parent, int result_deleted,\n@@ -897,7 +897,7 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\t\t\t int show_file_header)\n {\n \tstruct diff_options *opt = &rev->diffopt;\n-\tint abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;\n+\tint abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV;\n \tconst char *a_prefix = opt->a_prefix ? opt->a_prefix : \"a/\";\n \tconst char *b_prefix = opt->b_prefix ? opt->b_prefix : \"b/\";\n \tconst char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);\n@@ -914,11 +914,11 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\t\t \"\", elem->path, line_prefix, c_meta, c_reset);\n \tprintf(\"%s%sindex \", line_prefix, c_meta);\n \tfor (i = 0; i < num_parent; i++) {\n-\t\tabb = find_unique_abbrev(elem->parent[i].sha1,\n+\t\tabb = find_unique_abbrev(elem->parent[i].oid.hash,\n \t\t\t\t\t abbrev);\n \t\tprintf(\"%s%s\", i ? \",\" : \"\", abb);\n \t}\n-\tabb = find_unique_abbrev(elem->sha1, abbrev);\n+\tabb = find_unique_abbrev(elem->oid.hash, abbrev);\n \tprintf(\"..%s%s\\n\", abb, c_reset);\n \n \tif (mode_differs) {\n@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \n \t/* Read the result of merge first */\n \tif (!working_tree_file)\n-\t\tresult = grab_blob(elem->sha1, elem->mode, &result_size,\n+\t\tresult = grab_blob(&elem->oid, elem->mode, &result_size,\n \t\t\t\t   textconv, elem->path);\n \telse {\n \t\t/* Used by diff-tree to read from the working tree */\n@@ -1013,12 +1013,12 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tresult = strbuf_detach(&buf, NULL);\n \t\t\telem->mode = canon_mode(st.st_mode);\n \t\t} else if (S_ISDIR(st.st_mode)) {\n-\t\t\tunsigned char sha1[20];\n-\t\t\tif (resolve_gitlink_ref(elem->path, \"HEAD\", sha1) < 0)\n-\t\t\t\tresult = grab_blob(elem->sha1, elem->mode,\n+\t\t\tstruct object_id oid;\n+\t\t\tif (resolve_gitlink_ref(elem->path, \"HEAD\", oid.hash) < 0)\n+\t\t\t\tresult = grab_blob(&elem->oid, elem->mode,\n \t\t\t\t\t\t   &result_size, NULL, NULL);\n \t\t\telse\n-\t\t\t\tresult = grab_blob(sha1, elem->mode,\n+\t\t\t\tresult = grab_blob(&oid, elem->mode,\n \t\t\t\t\t\t   &result_size, NULL, NULL);\n \t\t} else if (textconv) {\n \t\t\tstruct diff_filespec *df = alloc_filespec(elem->path);\n@@ -1090,7 +1090,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\tfor (i = 0; !is_binary && i < num_parent; i++) {\n \t\t\tchar *buf;\n \t\t\tunsigned long size;\n-\t\t\tbuf = grab_blob(elem->parent[i].sha1,\n+\t\t\tbuf = grab_blob(&elem->parent[i].oid,\n \t\t\t\t\telem->parent[i].mode,\n \t\t\t\t\t&size, NULL, NULL);\n \t\t\tif (buffer_is_binary(buf, size))\n@@ -1139,14 +1139,14 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tfor (i = 0; i < num_parent; i++) {\n \t\tint j;\n \t\tfor (j = 0; j < i; j++) {\n-\t\t\tif (!hashcmp(elem->parent[i].sha1,\n-\t\t\t\t     elem->parent[j].sha1)) {\n+\t\t\tif (!oidcmp(&elem->parent[i].oid,\n+\t\t\t\t     &elem->parent[j].oid)) {\n \t\t\t\treuse_combine_diff(sline, cnt, i, j);\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n \t\tif (i <= j)\n-\t\t\tcombine_diff(elem->parent[i].sha1,\n+\t\t\tcombine_diff(&elem->parent[i].oid,\n \t\t\t\t     elem->parent[i].mode,\n \t\t\t\t     &result_file, sline,\n \t\t\t\t     cnt, i, num_parent, result_deleted,\n@@ -1206,9 +1206,9 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re\n \n \t\t/* Show sha1's */\n \t\tfor (i = 0; i < num_parent; i++)\n-\t\t\tprintf(\" %s\", diff_unique_abbrev(p->parent[i].sha1,\n+\t\t\tprintf(\" %s\", diff_unique_abbrev(p->parent[i].oid.hash,\n \t\t\t\t\t\t\t opt->abbrev));\n-\t\tprintf(\" %s \", diff_unique_abbrev(p->sha1, opt->abbrev));\n+\t\tprintf(\" %s \", diff_unique_abbrev(p->oid.hash, opt->abbrev));\n \t}\n \n \tif (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {\n@@ -1271,16 +1271,16 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,\n \tfor (i = 0; i < num_parent; i++) {\n \t\tpair->one[i].path = p->path;\n \t\tpair->one[i].mode = p->parent[i].mode;\n-\t\thashcpy(pair->one[i].sha1, p->parent[i].sha1);\n-\t\tpair->one[i].sha1_valid = !is_null_sha1(p->parent[i].sha1);\n+\t\thashcpy(pair->one[i].sha1, p->parent[i].oid.hash);\n+\t\tpair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);\n \t\tpair->one[i].has_more_entries = 1;\n \t}\n \tpair->one[num_parent - 1].has_more_entries = 0;\n \n \tpair->two->path = p->path;\n \tpair->two->mode = p->mode;\n-\thashcpy(pair->two->sha1, p->sha1);\n-\tpair->two->sha1_valid = !is_null_sha1(p->sha1);\n+\thashcpy(pair->two->sha1, p->oid.hash);\n+\tpair->two->sha1_valid = !is_null_oid(&p->oid);\n \treturn pair;\n }\n \ndiff --git a/diff-lib.c b/diff-lib.c\nindex a85c497..241a843 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -125,7 +125,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\tdpath->next = NULL;\n \t\t\tmemcpy(dpath->path, ce->name, path_len);\n \t\t\tdpath->path[path_len] = '\\0';\n-\t\t\thashclr(dpath->sha1);\n+\t\t\toidclr(&dpath->oid);\n \t\t\tmemset(&(dpath->parent[0]), 0,\n \t\t\t       sizeof(struct combine_diff_parent)*5);\n \n@@ -155,7 +155,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\t\tif (2 <= stage) {\n \t\t\t\t\tint mode = nce->ce_mode;\n \t\t\t\t\tnum_compare_stages++;\n-\t\t\t\t\thashcpy(dpath->parent[stage-2].sha1, nce->sha1);\n+\t\t\t\t\thashcpy(dpath->parent[stage-2].oid.hash, nce->sha1);\n \t\t\t\t\tdpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);\n \t\t\t\t\tdpath->parent[stage-2].status =\n \t\t\t\t\t\tDIFF_STATUS_MODIFIED;\n@@ -339,14 +339,14 @@ static int show_modified(struct rev_info *revs,\n \t\tmemcpy(p->path, new->name, pathlen);\n \t\tp->path[pathlen] = 0;\n \t\tp->mode = mode;\n-\t\thashclr(p->sha1);\n+\t\toidclr(&p->oid);\n \t\tmemset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));\n \t\tp->parent[0].status = DIFF_STATUS_MODIFIED;\n \t\tp->parent[0].mode = new->ce_mode;\n-\t\thashcpy(p->parent[0].sha1, new->sha1);\n+\t\thashcpy(p->parent[0].oid.hash, new->sha1);\n \t\tp->parent[1].status = DIFF_STATUS_MODIFIED;\n \t\tp->parent[1].mode = old->ce_mode;\n-\t\thashcpy(p->parent[1].sha1, old->sha1);\n+\t\thashcpy(p->parent[1].oid.hash, old->sha1);\n \t\tshow_combined_diff(p, 2, revs->dense_combined_merges, revs);\n \t\tfree(p);\n \t\treturn 0;\ndiff --git a/diff.h b/diff.h\nindex b4a624d..f6fdf49 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -6,6 +6,7 @@\n \n #include \"tree-walk.h\"\n #include \"pathspec.h\"\n+#include \"object.h\"\n \n struct rev_info;\n struct diff_options;\n@@ -207,11 +208,11 @@ struct combine_diff_path {\n \tstruct combine_diff_path *next;\n \tchar *path;\n \tunsigned int mode;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct combine_diff_parent {\n \t\tchar status;\n \t\tunsigned int mode;\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t} parent[FLEX_ARRAY];\n };\n #define combine_diff_path_size(n, l) \\\ndiff --git a/tree-diff.c b/tree-diff.c\nindex e7b378c..290a1da 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -64,7 +64,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_\n {\n \tstruct combine_diff_parent *p0 = &p->parent[0];\n \tif (p->mode && p0->mode) {\n-\t\topt->change(opt, p0->mode, p->mode, p0->sha1, p->sha1,\n+\t\topt->change(opt, p0->mode, p->mode, p0->oid.hash, p->oid.hash,\n \t\t\t1, 1, p->path, 0, 0);\n \t}\n \telse {\n@@ -74,11 +74,11 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_\n \n \t\tif (p->mode) {\n \t\t\taddremove = '+';\n-\t\t\tsha1 = p->sha1;\n+\t\t\tsha1 = p->oid.hash;\n \t\t\tmode = p->mode;\n \t\t} else {\n \t\t\taddremove = '-';\n-\t\t\tsha1 = p0->sha1;\n+\t\t\tsha1 = p0->oid.hash;\n \t\t\tmode = p0->mode;\n \t\t}\n \n@@ -151,7 +151,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,\n \tmemcpy(p->path + base->len, path, pathlen);\n \tp->path[len] = 0;\n \tp->mode = mode;\n-\thashcpy(p->sha1, sha1 ? sha1 : null_sha1);\n+\thashcpy(p->oid.hash, sha1 ? sha1 : null_sha1);\n \n \treturn p;\n }\n@@ -238,7 +238,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,\n \t\t\t}\n \n \t\t\tp->parent[i].mode = mode_i;\n-\t\t\thashcpy(p->parent[i].sha1, sha1_i ? sha1_i : null_sha1);\n+\t\t\thashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1);\n \t\t}\n \n \t\tkeep = 1;\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257657","messageId":"1426289976-568060-9-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 08/10] commit: convert parts to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:34Z","receivedAt":"2015-03-13T23:39:34Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert struct commit_graft and necessary local parts of commit.c.\nAlso, convert several constants based on the hex length of an SHA-1 to\nuse GIT_SHA1_HEXSZ, and move several magic constants into variables for\nreadability.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n commit.c      | 56 ++++++++++++++++++++++++++++++--------------------------\n commit.h      |  4 ++--\n log-tree.c    |  2 +-\n send-pack.c   |  2 +-\n shallow.c     |  8 ++++----\n upload-pack.c |  2 +-\n 6 files changed, 39 insertions(+), 35 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a8c7577..2d9de80 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -55,12 +55,12 @@ struct commit *lookup_commit(const unsigned char *sha1)\n \n struct commit *lookup_commit_reference_by_name(const char *name)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct commit *commit;\n \n-\tif (get_sha1_committish(name, sha1))\n+\tif (get_sha1_committish(name, oid.hash))\n \t\treturn NULL;\n-\tcommit = lookup_commit_reference(sha1);\n+\tcommit = lookup_commit_reference(oid.hash);\n \tif (parse_commit(commit))\n \t\treturn NULL;\n \treturn commit;\n@@ -99,7 +99,7 @@ static int commit_graft_alloc, commit_graft_nr;\n static const unsigned char *commit_graft_sha1_access(size_t index, void *table)\n {\n \tstruct commit_graft **commit_graft_table = table;\n-\treturn commit_graft_table[index]->sha1;\n+\treturn commit_graft_table[index]->oid.hash;\n }\n \n static int commit_graft_pos(const unsigned char *sha1)\n@@ -110,7 +110,7 @@ static int commit_graft_pos(const unsigned char *sha1)\n \n int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n {\n-\tint pos = commit_graft_pos(graft->sha1);\n+\tint pos = commit_graft_pos(graft->oid.hash);\n \n \tif (0 <= pos) {\n \t\tif (ignore_dups)\n@@ -138,22 +138,23 @@ struct commit_graft *read_graft_line(char *buf, int len)\n \t/* The format is just \"Commit Parent1 Parent2 ...\\n\" */\n \tint i;\n \tstruct commit_graft *graft = NULL;\n+\tconst int entry_size = GIT_SHA1_HEXSZ + 1;\n \n \twhile (len && isspace(buf[len-1]))\n \t\tbuf[--len] = '\\0';\n \tif (buf[0] == '#' || buf[0] == '\\0')\n \t\treturn NULL;\n-\tif ((len + 1) % 41)\n+\tif ((len + 1) % entry_size)\n \t\tgoto bad_graft_data;\n-\ti = (len + 1) / 41 - 1;\n-\tgraft = xmalloc(sizeof(*graft) + 20 * i);\n+\ti = (len + 1) / entry_size - 1;\n+\tgraft = xmalloc(sizeof(*graft) + GIT_SHA1_RAWSZ * i);\n \tgraft->nr_parent = i;\n-\tif (get_sha1_hex(buf, graft->sha1))\n+\tif (get_oid_hex(buf, &graft->oid))\n \t\tgoto bad_graft_data;\n-\tfor (i = 40; i < len; i += 41) {\n+\tfor (i = GIT_SHA1_HEXSZ; i < len; i += entry_size) {\n \t\tif (buf[i] != ' ')\n \t\t\tgoto bad_graft_data;\n-\t\tif (get_sha1_hex(buf + i + 1, graft->parent[i/41]))\n+\t\tif (get_sha1_hex(buf + i + 1, graft->parent[i/entry_size].hash))\n \t\t\tgoto bad_graft_data;\n \t}\n \treturn graft;\n@@ -302,39 +303,42 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s\n {\n \tconst char *tail = buffer;\n \tconst char *bufptr = buffer;\n-\tunsigned char parent[20];\n+\tstruct object_id parent;\n \tstruct commit_list **pptr;\n \tstruct commit_graft *graft;\n+\tconst int tree_entry_len = GIT_SHA1_HEXSZ + 5;\n+\tconst int parent_entry_len = GIT_SHA1_HEXSZ + 7;\n \n \tif (item->object.parsed)\n \t\treturn 0;\n \titem->object.parsed = 1;\n \ttail += size;\n-\tif (tail <= bufptr + 46 || memcmp(bufptr, \"tree \", 5) || bufptr[45] != '\\n')\n+\tif (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, \"tree \", 5) ||\n+\t\t\tbufptr[tree_entry_len] != '\\n')\n \t\treturn error(\"bogus commit object %s\", sha1_to_hex(item->object.sha1));\n-\tif (get_sha1_hex(bufptr + 5, parent) < 0)\n+\tif (get_sha1_hex(bufptr + 5, parent.hash) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     sha1_to_hex(item->object.sha1));\n-\titem->tree = lookup_tree(parent);\n-\tbufptr += 46; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n+\titem->tree = lookup_tree(parent.hash);\n+\tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \n \tgraft = lookup_commit_graft(item->object.sha1);\n-\twhile (bufptr + 48 < tail && !memcmp(bufptr, \"parent \", 7)) {\n+\twhile (bufptr + parent_entry_len < tail && !memcmp(bufptr, \"parent \", 7)) {\n \t\tstruct commit *new_parent;\n \n-\t\tif (tail <= bufptr + 48 ||\n-\t\t    get_sha1_hex(bufptr + 7, parent) ||\n-\t\t    bufptr[47] != '\\n')\n+\t\tif (tail <= bufptr + parent_entry_len + 1 ||\n+\t\t    get_sha1_hex(bufptr + 7, parent.hash) ||\n+\t\t    bufptr[parent_entry_len] != '\\n')\n \t\t\treturn error(\"bad parents in commit %s\", sha1_to_hex(item->object.sha1));\n-\t\tbufptr += 48;\n+\t\tbufptr += parent_entry_len + 1;\n \t\t/*\n \t\t * The clone is shallow if nr_parent < 0, and we must\n \t\t * not traverse its real parents even when we unhide them.\n \t\t */\n \t\tif (graft && (graft->nr_parent < 0 || grafts_replace_parents))\n \t\t\tcontinue;\n-\t\tnew_parent = lookup_commit(parent);\n+\t\tnew_parent = lookup_commit(parent.hash);\n \t\tif (new_parent)\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\n \t}\n@@ -342,7 +346,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s\n \t\tint i;\n \t\tstruct commit *new_parent;\n \t\tfor (i = 0; i < graft->nr_parent; i++) {\n-\t\t\tnew_parent = lookup_commit(graft->parent[i]);\n+\t\t\tnew_parent = lookup_commit(graft->parent[i].hash);\n \t\t\tif (!new_parent)\n \t\t\t\tcontinue;\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\n@@ -1580,10 +1584,10 @@ struct commit *get_merge_parent(const char *name)\n {\n \tstruct object *obj;\n \tstruct commit *commit;\n-\tunsigned char sha1[20];\n-\tif (get_sha1(name, sha1))\n+\tstruct object_id oid;\n+\tif (get_sha1(name, oid.hash))\n \t\treturn NULL;\n-\tobj = parse_object(sha1);\n+\tobj = parse_object(oid.hash);\n \tcommit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);\n \tif (commit && !commit->util) {\n \t\tstruct merge_remote_desc *desc;\ndiff --git a/commit.h b/commit.h\nindex 9f189cb..ed3a1d5 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -226,9 +226,9 @@ enum rev_sort_order {\n void sort_in_topological_order(struct commit_list **, enum rev_sort_order);\n \n struct commit_graft {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint nr_parent; /* < 0 if shallow commit */\n-\tunsigned char parent[FLEX_ARRAY][20]; /* more */\n+\tstruct object_id parent[FLEX_ARRAY]; /* more */\n };\n typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 7f0890e..51cc695 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -137,7 +137,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in\n \n static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit(graft->sha1);\n+\tstruct commit *commit = lookup_commit(graft->oid.hash);\n \tif (!commit)\n \t\treturn 0;\n \tadd_name_decoration(DECORATION_GRAFTED, \"grafted\", &commit->object);\ndiff --git a/send-pack.c b/send-pack.c\nindex 9d2b0c5..b2fd767 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -182,7 +182,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c\n {\n \tstruct strbuf *sb = cb;\n \tif (graft->nr_parent == -1)\n-\t\tpacket_buf_write(sb, \"shallow %s\\n\", sha1_to_hex(graft->sha1));\n+\t\tpacket_buf_write(sb, \"shallow %s\\n\", oid_to_hex(&graft->oid));\n \treturn 0;\n }\n \ndiff --git a/shallow.c b/shallow.c\nindex d8bf40a..d08d264 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -31,7 +31,7 @@ int register_shallow(const unsigned char *sha1)\n \t\txmalloc(sizeof(struct commit_graft));\n \tstruct commit *commit = lookup_commit(sha1);\n \n-\thashcpy(graft->sha1, sha1);\n+\thashcpy(graft->oid.hash, sha1);\n \tgraft->nr_parent = -1;\n \tif (commit && commit->object.parsed)\n \t\tcommit->parents = NULL;\n@@ -159,11 +159,11 @@ struct write_shallow_data {\n static int write_one_shallow(const struct commit_graft *graft, void *cb_data)\n {\n \tstruct write_shallow_data *data = cb_data;\n-\tconst char *hex = sha1_to_hex(graft->sha1);\n+\tconst char *hex = oid_to_hex(&graft->oid);\n \tif (graft->nr_parent != -1)\n \t\treturn 0;\n \tif (data->flags & SEEN_ONLY) {\n-\t\tstruct commit *c = lookup_commit(graft->sha1);\n+\t\tstruct commit *c = lookup_commit(graft->oid.hash);\n \t\tif (!c || !(c->object.flags & SEEN)) {\n \t\t\tif (data->flags & VERBOSE)\n \t\t\t\tprintf(\"Removing %s from .git/shallow\\n\",\n@@ -282,7 +282,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c\n {\n \tint fd = *(int *)cb;\n \tif (graft->nr_parent == -1)\n-\t\tpacket_write(fd, \"shallow %s\\n\", sha1_to_hex(graft->sha1));\n+\t\tpacket_write(fd, \"shallow %s\\n\", oid_to_hex(&graft->oid));\n \treturn 0;\n }\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex b531a32..0566ce0 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -74,7 +74,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)\n {\n \tFILE *fp = cb_data;\n \tif (graft->nr_parent == -1)\n-\t\tfprintf(fp, \"--shallow %s\\n\", sha1_to_hex(graft->sha1));\n+\t\tfprintf(fp, \"--shallow %s\\n\", oid_to_hex(&graft->oid));\n \treturn 0;\n }\n \n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257655","messageId":"1426289976-568060-10-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 09/10] patch-id: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:35Z","receivedAt":"2015-03-13T23:39:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert some magic numbers to the new GIT_SHA1 constants.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/patch-id.c | 34 +++++++++++++++++-----------------\n 1 file changed, 17 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/patch-id.c b/builtin/patch-id.c\nindex 77db873..ba34dac 100644\n--- a/builtin/patch-id.c\n+++ b/builtin/patch-id.c\n@@ -1,14 +1,14 @@\n #include \"builtin.h\"\n \n-static void flush_current_id(int patchlen, unsigned char *id, unsigned char *result)\n+static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)\n {\n \tchar name[50];\n \n \tif (!patchlen)\n \t\treturn;\n \n-\tmemcpy(name, sha1_to_hex(id), 41);\n-\tprintf(\"%s %s\\n\", sha1_to_hex(result), name);\n+\tmemcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);\n+\tprintf(\"%s %s\\n\", oid_to_hex(result), name);\n }\n \n static int remove_space(char *line)\n@@ -53,23 +53,23 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)\n \treturn 1;\n }\n \n-static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)\n+static void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)\n {\n-\tunsigned char hash[20];\n+\tunsigned char hash[GIT_SHA1_RAWSZ];\n \tunsigned short carry = 0;\n \tint i;\n \n \tgit_SHA1_Final(hash, ctx);\n \tgit_SHA1_Init(ctx);\n \t/* 20-byte sum, with carry */\n-\tfor (i = 0; i < 20; ++i) {\n-\t\tcarry += result[i] + hash[i];\n-\t\tresult[i] = carry;\n+\tfor (i = 0; i < GIT_SHA1_RAWSZ; ++i) {\n+\t\tcarry += result->hash[i] + hash[i];\n+\t\tresult->hash[i] = carry;\n \t\tcarry >>= 8;\n \t}\n }\n \n-static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,\n+static int get_one_patchid(struct object_id *next_oid, struct object_id *result,\n \t\t\t   struct strbuf *line_buf, int stable)\n {\n \tint patchlen = 0, found_next = 0;\n@@ -77,7 +77,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,\n \tgit_SHA_CTX ctx;\n \n \tgit_SHA1_Init(&ctx);\n-\thashclr(result);\n+\toidclr(result);\n \n \twhile (strbuf_getwholeline(line_buf, stdin, '\\n') != EOF) {\n \t\tchar *line = line_buf->buf;\n@@ -93,7 +93,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,\n \t\telse if (!memcmp(line, \"\\\\ \", 2) && 12 < strlen(line))\n \t\t\tcontinue;\n \n-\t\tif (!get_sha1_hex(p, next_sha1)) {\n+\t\tif (!get_oid_hex(p, next_oid)) {\n \t\t\tfound_next = 1;\n \t\t\tbreak;\n \t\t}\n@@ -143,7 +143,7 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,\n \t}\n \n \tif (!found_next)\n-\t\thashclr(next_sha1);\n+\t\toidclr(next_oid);\n \n \tflush_one_hunk(result, &ctx);\n \n@@ -152,15 +152,15 @@ static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,\n \n static void generate_id_list(int stable)\n {\n-\tunsigned char sha1[20], n[20], result[20];\n+\tstruct object_id oid, n, result;\n \tint patchlen;\n \tstruct strbuf line_buf = STRBUF_INIT;\n \n-\thashclr(sha1);\n+\toidclr(&oid);\n \twhile (!feof(stdin)) {\n-\t\tpatchlen = get_one_patchid(n, result, &line_buf, stable);\n-\t\tflush_current_id(patchlen, sha1, result);\n-\t\thashcpy(sha1, n);\n+\t\tpatchlen = get_one_patchid(&n, &result, &line_buf, stable);\n+\t\tflush_current_id(patchlen, &oid, &result);\n+\t\toidcpy(&oid, &n);\n \t}\n \tstrbuf_release(&line_buf);\n }\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257658","messageId":"1426289976-568060-11-git-send-email-sandals@crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 10/10] apply: convert threeway_stage to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-13T23:39:36Z","receivedAt":"2015-03-13T23:39:36Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/apply.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 65b97ee..c2c8f39 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -208,7 +208,7 @@ struct patch {\n \tstruct patch *next;\n \n \t/* three-way fallback result */\n-\tunsigned char threeway_stage[3][20];\n+\tstruct object_id threeway_stage[3];\n };\n \n static void free_fragment_list(struct fragment *list)\n@@ -3424,11 +3424,11 @@ static int try_threeway(struct image *image, struct patch *patch,\n \tif (status) {\n \t\tpatch->conflicted_threeway = 1;\n \t\tif (patch->is_new)\n-\t\t\thashclr(patch->threeway_stage[0]);\n+\t\t\toidclr(&patch->threeway_stage[0]);\n \t\telse\n-\t\t\thashcpy(patch->threeway_stage[0], pre_sha1);\n-\t\thashcpy(patch->threeway_stage[1], our_sha1);\n-\t\thashcpy(patch->threeway_stage[2], post_sha1);\n+\t\t\thashcpy(patch->threeway_stage[0].hash, pre_sha1);\n+\t\thashcpy(patch->threeway_stage[1].hash, our_sha1);\n+\t\thashcpy(patch->threeway_stage[2].hash, post_sha1);\n \t\tfprintf(stderr, \"Applied patch to '%s' with conflicts.\\n\", patch->new_name);\n \t} else {\n \t\tfprintf(stderr, \"Applied patch to '%s' cleanly.\\n\", patch->new_name);\n@@ -4184,14 +4184,14 @@ static void add_conflicted_stages_file(struct patch *patch)\n \n \tremove_file_from_cache(patch->new_name);\n \tfor (stage = 1; stage < 4; stage++) {\n-\t\tif (is_null_sha1(patch->threeway_stage[stage - 1]))\n+\t\tif (is_null_oid(&patch->threeway_stage[stage - 1]))\n \t\t\tcontinue;\n \t\tce = xcalloc(1, ce_size);\n \t\tmemcpy(ce->name, patch->new_name, namelen);\n \t\tce->ce_mode = create_ce_mode(mode);\n \t\tce->ce_flags = create_ce_flags(stage);\n \t\tce->ce_namelen = namelen;\n-\t\thashcpy(ce->sha1, patch->threeway_stage[stage - 1]);\n+\t\thashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash);\n \t\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)\n \t\t\tdie(_(\"unable to add cache entry for %s\"), patch->new_name);\n \t}\n-- \n2.2.1.209.g41e5f3a\n"},{"id":"257677","messageId":"20150314141619.GI46326@vauxhall.crustytoothpaste.net","threadId":"38797","inReplyTo":"1426289976-568060-1-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/10] Use a structure for object IDs.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-03-14T14:16:19Z","receivedAt":"2015-03-14T14:16:19Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Fri, Mar 13, 2015 at 11:39:26PM +0000, brian m. carlson wrote:\n>\n>Changes since v1:\n\nI just realized that I sent this out as v2 instead of v3.  It really is\nv3.  My apologies for the error.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}