{"thread":{"id":"39573","subject":"[PATCH 1/8] refs: convert some internal functions to use object_id","startedAt":"2015-06-09T16:28:28Z","lastAt":"2015-06-13T15:28:59Z","messageCount":23,"participants":["brian m. carlson","Duy Nguyen","Junio C Hamano","Michael Haggerty"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"263377","messageId":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":null,"subject":"[PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:28Z","receivedAt":"2015-06-09T16:28:28Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is another series of conversions to struct object_id.\n\nThis series converts more of the refs code and struct object to use\nstruct object_id.  It introduces two additional helper functions.  One\nis has_object_file, which is the equivalent of has_sha1_file.  The name\nwas chosen to be slightly more logical than has_oid_file, although it\ncan be changed if desired.\n\nThe second helper function is parse_oid_hex.  It works much like\nget_oid_hex, but it takes an optional length argument and returns the\nnumber of bytes parsed on success (40) and 0 on error.  It's designed to\nbe more useful in conditionals and to enable us to avoid having to write\nGIT_SHA1_HEXSZ in favor of simply using the return value.\n\nThe final piece in this series is the conversion of struct object to use\nstruct object_id.  This is a necessarily large patch because of the\nlarge number of places this code is used.\n\nbrian m. carlson (8):\n  refs: convert some internal functions to use object_id\n  sha1_file: introduce has_object_file helper.\n  Convert struct ref to use object_id.\n  Add a utility function to make parsing hex values easier.\n  add_sought_entry_mem: convert to struct object_id\n  parse_fetch: convert to use struct object_id\n  ref_newer: convert to use struct object_id\n  Convert struct object to object_id\n\n archive.c                |   6 +--\n bisect.c                 |  10 ++---\n branch.c                 |   2 +-\n builtin/blame.c          |  46 ++++++++++----------\n builtin/branch.c         |   2 +-\n builtin/checkout.c       |  24 +++++------\n builtin/clone.c          |  18 ++++----\n builtin/commit-tree.c    |   4 +-\n builtin/commit.c         |   8 ++--\n builtin/describe.c       |  20 ++++-----\n builtin/diff-tree.c      |  12 +++---\n builtin/diff.c           |  12 +++---\n builtin/fast-export.c    |  34 +++++++--------\n builtin/fetch-pack.c     |  14 ++++---\n builtin/fetch.c          |  54 ++++++++++++------------\n builtin/fmt-merge-msg.c  |   6 +--\n builtin/for-each-ref.c   |  12 +++---\n builtin/fsck.c           |  34 +++++++--------\n builtin/grep.c           |   6 +--\n builtin/index-pack.c     |  10 ++---\n builtin/log.c            |  24 +++++------\n builtin/ls-remote.c      |   2 +-\n builtin/merge-base.c     |   8 ++--\n builtin/merge-tree.c     |   6 +--\n builtin/merge.c          |  60 +++++++++++++--------------\n builtin/name-rev.c       |  12 +++---\n builtin/notes.c          |   2 +-\n builtin/pack-objects.c   |  16 +++----\n builtin/receive-pack.c   |   2 +-\n builtin/reflog.c         |   4 +-\n builtin/remote.c         |  12 +++---\n builtin/replace.c        |   2 +-\n builtin/reset.c          |   6 +--\n builtin/rev-list.c       |  18 ++++----\n builtin/rev-parse.c      |   4 +-\n builtin/shortlog.c       |   2 +-\n builtin/show-branch.c    |   8 ++--\n builtin/tag.c            |   4 +-\n builtin/unpack-objects.c |  10 ++---\n bundle.c                 |  10 ++---\n cache-tree.c             |   2 +-\n cache.h                  |  12 ++++++\n combine-diff.c           |   4 +-\n commit.c                 |  32 +++++++-------\n connect.c                |   2 +-\n decorate.c               |   2 +-\n diff-lib.c               |   2 +-\n fetch-pack.c             |  24 +++++------\n fsck.c                   |  10 ++---\n hex.c                    |   7 ++++\n http-backend.c           |   2 +-\n http-push.c              |  88 +++++++++++++++++++--------------------\n http.c                   |   2 +-\n line-log.c               |   6 +--\n list-objects.c           |   4 +-\n log-tree.c               |  32 +++++++-------\n merge-blobs.c            |   4 +-\n merge-recursive.c        |  22 +++++-----\n merge.c                  |   2 +-\n notes-merge.c            |  24 +++++------\n object.c                 |   8 ++--\n object.h                 |   2 +-\n pack-bitmap-write.c      |  16 +++----\n pack-bitmap.c            |  34 +++++++--------\n patch-ids.c              |   6 +--\n pretty.c                 |  18 ++++----\n refs.c                   | 106 +++++++++++++++++++++++------------------------\n remote-curl.c            |  21 +++++-----\n remote.c                 |  68 +++++++++++++++---------------\n remote.h                 |   8 ++--\n revision.c               |  48 ++++++++++-----------\n send-pack.c              |  16 +++----\n sequencer.c              |  38 ++++++++---------\n server-info.c            |   2 +-\n sha1_file.c              |   5 +++\n sha1_name.c              |  20 ++++-----\n shallow.c                |   6 +--\n submodule.c              |   8 ++--\n tag.c                    |  10 ++---\n test-match-trees.c       |   2 +-\n transport-helper.c       |  18 ++++----\n transport.c              |  32 +++++++-------\n transport.h              |   8 ++--\n tree.c                   |  10 ++---\n upload-pack.c            |  26 ++++++------\n walker.c                 |  18 ++++----\n wt-status.c              |   2 +-\n 87 files changed, 706 insertions(+), 679 deletions(-)\n\n-- \n2.4.0\n"},{"id":"263369","messageId":"1433867316-663554-2-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 1/8] refs: convert some internal functions to use object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:29Z","receivedAt":"2015-06-09T16:28:29Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert several internal functions in refs.c to use struct object_id,\nand use the GIT_SHA1_HEXSZ constants in parse_ref_line.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c | 104 ++++++++++++++++++++++++++++++++---------------------------------\n 1 file changed, 52 insertions(+), 52 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex a742d79..b391a0f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1158,7 +1158,7 @@ static const char PACKED_REFS_HEADER[] =\n  * Return a pointer to the refname within the line (null-terminated),\n  * or NULL if there was a problem.\n  */\n-static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1)\n+static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)\n {\n \tconst char *ref;\n \n@@ -1170,15 +1170,15 @@ static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1)\n \t *  +1 (space in between hex and name)\n \t *  +1 (newline at the end of the line)\n \t */\n-\tif (line->len <= 42)\n+\tif (line->len <= GIT_SHA1_HEXSZ + 2)\n \t\treturn NULL;\n \n-\tif (get_sha1_hex(line->buf, sha1) < 0)\n+\tif (get_oid_hex(line->buf, oid) < 0)\n \t\treturn NULL;\n-\tif (!isspace(line->buf[40]))\n+\tif (!isspace(line->buf[GIT_SHA1_HEXSZ]))\n \t\treturn NULL;\n \n-\tref = line->buf + 41;\n+\tref = line->buf + GIT_SHA1_HEXSZ + 1;\n \tif (isspace(*ref))\n \t\treturn NULL;\n \n@@ -1223,7 +1223,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)\n \tenum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;\n \n \twhile (strbuf_getwholeline(&line, f, '\\n') != EOF) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tconst char *refname;\n \t\tconst char *traits;\n \n@@ -1236,17 +1236,17 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)\n \t\t\tcontinue;\n \t\t}\n \n-\t\trefname = parse_ref_line(&line, sha1);\n+\t\trefname = parse_ref_line(&line, &oid);\n \t\tif (refname) {\n \t\t\tint flag = REF_ISPACKED;\n \n \t\t\tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {\n \t\t\t\tif (!refname_is_safe(refname))\n \t\t\t\t\tdie(\"packed refname is dangerous: %s\", refname);\n-\t\t\t\thashclr(sha1);\n+\t\t\t\toidclr(&oid);\n \t\t\t\tflag |= REF_BAD_NAME | REF_ISBROKEN;\n \t\t\t}\n-\t\t\tlast = create_ref_entry(refname, sha1, flag, 0);\n+\t\t\tlast = create_ref_entry(refname, oid.hash, flag, 0);\n \t\t\tif (peeled == PEELED_FULLY ||\n \t\t\t    (peeled == PEELED_TAGS && starts_with(refname, \"refs/tags/\")))\n \t\t\t\tlast->flag |= REF_KNOWS_PEELED;\n@@ -1257,8 +1257,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)\n \t\t    line.buf[0] == '^' &&\n \t\t    line.len == PEELED_LINE_LENGTH &&\n \t\t    line.buf[PEELED_LINE_LENGTH - 1] == '\\n' &&\n-\t\t    !get_sha1_hex(line.buf + 1, sha1)) {\n-\t\t\thashcpy(last->u.value.peeled.hash, sha1);\n+\t\t    !get_oid_hex(line.buf + 1, &oid)) {\n+\t\t\toidcpy(&last->u.value.peeled, &oid);\n \t\t\t/*\n \t\t\t * Regardless of what the file header said,\n \t\t\t * we definitely know the value of *this*\n@@ -1352,7 +1352,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)\n \tstrbuf_add(&refname, dirname, dirnamelen);\n \n \twhile ((de = readdir(d)) != NULL) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct stat st;\n \t\tint flag;\n \t\tconst char *refdir;\n@@ -1374,27 +1374,27 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)\n \t\t\t\t\t\t\t  refname.len, 1));\n \t\t} else {\n \t\t\tif (*refs->name) {\n-\t\t\t\thashclr(sha1);\n+\t\t\t\toidclr(&oid);\n \t\t\t\tflag = 0;\n-\t\t\t\tif (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {\n-\t\t\t\t\thashclr(sha1);\n+\t\t\t\tif (resolve_gitlink_ref(refs->name, refname.buf, oid.hash) < 0) {\n+\t\t\t\t\toidclr(&oid);\n \t\t\t\t\tflag |= REF_ISBROKEN;\n \t\t\t\t}\n \t\t\t} else if (read_ref_full(refname.buf,\n \t\t\t\t\t\t RESOLVE_REF_READING,\n-\t\t\t\t\t\t sha1, &flag)) {\n-\t\t\t\thashclr(sha1);\n+\t\t\t\t\t\t oid.hash, &flag)) {\n+\t\t\t\toidclr(&oid);\n \t\t\t\tflag |= REF_ISBROKEN;\n \t\t\t}\n \t\t\tif (check_refname_format(refname.buf,\n \t\t\t\t\t\t REFNAME_ALLOW_ONELEVEL)) {\n \t\t\t\tif (!refname_is_safe(refname.buf))\n \t\t\t\t\tdie(\"loose refname is dangerous: %s\", refname.buf);\n-\t\t\t\thashclr(sha1);\n+\t\t\t\toidclr(&oid);\n \t\t\t\tflag |= REF_BAD_NAME | REF_ISBROKEN;\n \t\t\t}\n \t\t\tadd_entry_to_dir(dir,\n-\t\t\t\t\t create_ref_entry(refname.buf, sha1, flag, 0));\n+\t\t\t\t\t create_ref_entry(refname.buf, oid.hash, flag, 0));\n \t\t}\n \t\tstrbuf_setlen(&refname, dirnamelen);\n \t}\n@@ -1752,8 +1752,8 @@ int read_ref(const char *refname, unsigned char *sha1)\n \n int ref_exists(const char *refname)\n {\n-\tunsigned char sha1[20];\n-\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);\n+\tstruct object_id oid;\n+\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, oid.hash, NULL);\n }\n \n static int filter_refs(const char *refname, const struct object_id *oid,\n@@ -1857,7 +1857,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)\n int peel_ref(const char *refname, unsigned char *sha1)\n {\n \tint flag;\n-\tunsigned char base[20];\n+\tstruct object_id base;\n \n \tif (current_ref && (current_ref->name == refname\n \t\t\t    || !strcmp(current_ref->name, refname))) {\n@@ -1867,7 +1867,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n \t\treturn 0;\n \t}\n \n-\tif (read_ref_full(refname, RESOLVE_REF_READING, base, &flag))\n+\tif (read_ref_full(refname, RESOLVE_REF_READING, base.hash, &flag))\n \t\treturn -1;\n \n \t/*\n@@ -1888,7 +1888,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n \t\t}\n \t}\n \n-\treturn peel_object(base, sha1);\n+\treturn peel_object(base.hash, sha1);\n }\n \n struct warn_if_dangling_data {\n@@ -2292,11 +2292,11 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)\n \t*ref = NULL;\n \tfor (p = ref_rev_parse_rules; *p; p++) {\n \t\tchar fullref[PATH_MAX];\n-\t\tunsigned char sha1_from_ref[20];\n+\t\tstruct object_id oid_from_ref;\n \t\tunsigned char *this_result;\n \t\tint flag;\n \n-\t\tthis_result = refs_found ? sha1_from_ref : sha1;\n+\t\tthis_result = refs_found ? oid_from_ref.hash : sha1;\n \t\tmksnpath(fullref, sizeof(fullref), *p, len, str);\n \t\tr = resolve_ref_unsafe(fullref, RESOLVE_REF_READING,\n \t\t\t\t       this_result, &flag);\n@@ -2323,13 +2323,13 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)\n \n \t*log = NULL;\n \tfor (p = ref_rev_parse_rules; *p; p++) {\n-\t\tunsigned char hash[20];\n+\t\tstruct object_id oid;\n \t\tchar path[PATH_MAX];\n \t\tconst char *ref, *it;\n \n \t\tmksnpath(path, sizeof(path), *p, len, str);\n \t\tref = resolve_ref_unsafe(path, RESOLVE_REF_READING,\n-\t\t\t\t\t hash, NULL);\n+\t\t\t\t\t oid.hash, NULL);\n \t\tif (!ref)\n \t\t\tcontinue;\n \t\tif (reflog_exists(path))\n@@ -2340,7 +2340,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)\n \t\t\tcontinue;\n \t\tif (!logs_found++) {\n \t\t\t*log = xstrdup(it);\n-\t\t\thashcpy(sha1, hash);\n+\t\t\thashcpy(sha1, oid.hash);\n \t\t}\n \t\tif (!warn_ambiguous_refs)\n \t\t\tbreak;\n@@ -2479,12 +2479,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n  * Write an entry to the packed-refs file for the specified refname.\n  * If peeled is non-NULL, write it as the entry's peeled value.\n  */\n-static void write_packed_entry(FILE *fh, char *refname, unsigned char *sha1,\n-\t\t\t       unsigned char *peeled)\n+static void write_packed_entry(FILE *fh, char *refname, struct object_id *oid,\n+\t\t\t       struct object_id *peeled)\n {\n-\tfprintf_or_die(fh, \"%s %s\\n\", sha1_to_hex(sha1), refname);\n+\tfprintf_or_die(fh, \"%s %s\\n\", oid_to_hex(oid), refname);\n \tif (peeled)\n-\t\tfprintf_or_die(fh, \"^%s\\n\", sha1_to_hex(peeled));\n+\t\tfprintf_or_die(fh, \"^%s\\n\", oid_to_hex(peeled));\n }\n \n /*\n@@ -2497,9 +2497,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)\n \tif (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)\n \t\terror(\"internal error: %s is not a valid packed reference!\",\n \t\t      entry->name);\n-\twrite_packed_entry(cb_data, entry->name, entry->u.value.oid.hash,\n+\twrite_packed_entry(cb_data, entry->name, &entry->u.value.oid,\n \t\t\t   peel_status == PEEL_PEELED ?\n-\t\t\t   entry->u.value.peeled.hash : NULL);\n+\t\t\t   &entry->u.value.peeled : NULL);\n \treturn 0;\n }\n \n@@ -2889,7 +2889,7 @@ static int commit_ref_update(struct ref_lock *lock,\n \n int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)\n {\n-\tunsigned char sha1[20], orig_sha1[20];\n+\tstruct object_id oid, orig_oid;\n \tint flag = 0, logmoved = 0;\n \tstruct ref_lock *lock;\n \tstruct stat loginfo;\n@@ -2901,7 +2901,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \t\treturn error(\"reflog for %s is a symlink\", oldrefname);\n \n \tsymref = resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING,\n-\t\t\t\t    orig_sha1, &flag);\n+\t\t\t\t    orig_oid.hash, &flag);\n \tif (flag & REF_ISSYMREF)\n \t\treturn error(\"refname %s is a symbolic ref, renaming it is not supported\",\n \t\t\toldrefname);\n@@ -2915,13 +2915,13 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \t\treturn error(\"unable to move logfile logs/%s to \"TMP_RENAMED_LOG\": %s\",\n \t\t\toldrefname, strerror(errno));\n \n-\tif (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {\n+\tif (delete_ref(oldrefname, orig_oid.hash, REF_NODEREF)) {\n \t\terror(\"unable to delete old %s\", oldrefname);\n \t\tgoto rollback;\n \t}\n \n-\tif (!read_ref_full(newrefname, RESOLVE_REF_READING, sha1, NULL) &&\n-\t    delete_ref(newrefname, sha1, REF_NODEREF)) {\n+\tif (!read_ref_full(newrefname, RESOLVE_REF_READING, oid.hash, NULL) &&\n+\t    delete_ref(newrefname, oid.hash, REF_NODEREF)) {\n \t\tif (errno==EISDIR) {\n \t\t\tif (remove_empty_directories(git_path(\"%s\", newrefname))) {\n \t\t\t\terror(\"Directory not empty: %s\", newrefname);\n@@ -2944,10 +2944,10 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \t\tstrbuf_release(&err);\n \t\tgoto rollback;\n \t}\n-\thashcpy(lock->old_oid.hash, orig_sha1);\n+\toidcpy(&lock->old_oid, &orig_oid);\n \n-\tif (write_ref_to_lockfile(lock, orig_sha1) ||\n-\t    commit_ref_update(lock, orig_sha1, logmsg)) {\n+\tif (write_ref_to_lockfile(lock, orig_oid.hash) ||\n+\t    commit_ref_update(lock, orig_oid.hash, logmsg)) {\n \t\terror(\"unable to write current sha1 into %s\", newrefname);\n \t\tgoto rollback;\n \t}\n@@ -2964,8 +2964,8 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \n \tflag = log_all_ref_updates;\n \tlog_all_ref_updates = 0;\n-\tif (write_ref_to_lockfile(lock, orig_sha1) ||\n-\t    commit_ref_update(lock, orig_sha1, NULL))\n+\tif (write_ref_to_lockfile(lock, orig_oid.hash) ||\n+\t    commit_ref_update(lock, orig_oid.hash, NULL))\n \t\terror(\"unable to write current sha1 into %s\", oldrefname);\n \tlog_all_ref_updates = flag;\n \n@@ -3218,11 +3218,11 @@ static int commit_ref_update(struct ref_lock *lock,\n \t\t * check with HEAD only which should cover 99% of all usage\n \t\t * scenarios (even 100% of the default ones).\n \t\t */\n-\t\tunsigned char head_sha1[20];\n+\t\tstruct object_id head_oid;\n \t\tint head_flag;\n \t\tconst char *head_ref;\n \t\thead_ref = resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING,\n-\t\t\t\t\t      head_sha1, &head_flag);\n+\t\t\t\t\t      head_oid.hash, &head_flag);\n \t\tif (head_ref && (head_flag & REF_ISSYMREF) &&\n \t\t    !strcmp(head_ref, lock->ref_name))\n \t\t\tlog_ref_write(\"HEAD\", lock->old_oid.hash, sha1, logmsg);\n@@ -3243,10 +3243,10 @@ int create_symref(const char *ref_target, const char *refs_heads_master,\n \tchar ref[1000];\n \tint fd, len, written;\n \tchar *git_HEAD = git_pathdup(\"%s\", ref_target);\n-\tunsigned char old_sha1[20], new_sha1[20];\n+\tstruct object_id old_oid, new_oid;\n \n-\tif (logmsg && read_ref(ref_target, old_sha1))\n-\t\thashclr(old_sha1);\n+\tif (logmsg && read_ref(ref_target, old_oid.hash))\n+\t\toidclr(&old_oid);\n \n \tif (safe_create_leading_directories(git_HEAD) < 0)\n \t\treturn error(\"unable to create directory for %s\", git_HEAD);\n@@ -3292,8 +3292,8 @@ int create_symref(const char *ref_target, const char *refs_heads_master,\n #ifndef NO_SYMLINK_HEAD\n \tdone:\n #endif\n-\tif (logmsg && !read_ref(refs_heads_master, new_sha1))\n-\t\tlog_ref_write(ref_target, old_sha1, new_sha1, logmsg);\n+\tif (logmsg && !read_ref(refs_heads_master, new_oid.hash))\n+\t\tlog_ref_write(ref_target, old_oid.hash, new_oid.hash, logmsg);\n \n \tfree(git_HEAD);\n \treturn 0;\n-- \n2.4.0\n"},{"id":"263370","messageId":"1433867316-663554-3-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 2/8] sha1_file: introduce has_object_file helper.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:30Z","receivedAt":"2015-06-09T16:28:30Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Add has_object_file, which is a wrapper around has_sha1_file, but for\nstruct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h     | 3 +++\n sha1_file.c | 5 +++++\n 2 files changed, 8 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 571c98f..fa1f067 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -946,6 +946,9 @@ extern int has_sha1_pack(const unsigned char *sha1);\n  */\n extern int has_sha1_file(const unsigned char *sha1);\n \n+/* Same as the above, except for struct object_id. */\n+extern int has_object_file(const struct object_id *oid);\n+\n /*\n  * Return true iff an alternate object database has a loose object\n  * with the specified name.  This function does not respect replace\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 7e38148..09f7f03 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3173,6 +3173,11 @@ int has_sha1_file(const unsigned char *sha1)\n \treturn find_pack_entry(sha1, &e);\n }\n \n+int has_object_file(const struct object_id *oid)\n+{\n+\treturn has_sha1_file(oid->hash);\n+}\n+\n static void check_tree(const void *buf, size_t size)\n {\n \tstruct tree_desc desc;\n-- \n2.4.0\n"},{"id":"263373","messageId":"1433867316-663554-4-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 3/8] Convert struct ref to use object_id.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:31Z","receivedAt":"2015-06-09T16:28:31Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Use struct object_id in three fields in struct ref and convert all the\nnecessary places that use it.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/clone.c        | 16 +++++++-------\n builtin/fetch-pack.c   |  4 ++--\n builtin/fetch.c        | 50 +++++++++++++++++++++----------------------\n builtin/ls-remote.c    |  2 +-\n builtin/receive-pack.c |  2 +-\n builtin/remote.c       | 12 +++++------\n connect.c              |  2 +-\n fetch-pack.c           | 18 ++++++++--------\n http-push.c            | 46 +++++++++++++++++++--------------------\n http.c                 |  2 +-\n remote-curl.c          | 10 ++++-----\n remote.c               | 58 +++++++++++++++++++++++++-------------------------\n remote.h               |  6 +++---\n send-pack.c            | 16 +++++++-------\n transport-helper.c     | 18 ++++++++--------\n transport.c            | 32 ++++++++++++++--------------\n transport.h            |  8 +++----\n walker.c               |  2 +-\n 18 files changed, 152 insertions(+), 152 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex b878252..c909574 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -505,7 +505,7 @@ static void write_remote_refs(const struct ref *local_refs)\n \tfor (r = local_refs; r; r = r->next) {\n \t\tif (!r->peer_ref)\n \t\t\tcontinue;\n-\t\tadd_packed_ref(r->peer_ref->name, r->old_sha1);\n+\t\tadd_packed_ref(r->peer_ref->name, r->old_oid.hash);\n \t}\n \n \tif (commit_packed_refs())\n@@ -520,9 +520,9 @@ static void write_followtags(const struct ref *refs, const char *msg)\n \t\t\tcontinue;\n \t\tif (ends_with(ref->name, \"^{}\"))\n \t\t\tcontinue;\n-\t\tif (!has_sha1_file(ref->old_sha1))\n+\t\tif (!has_object_file(&ref->old_oid))\n \t\t\tcontinue;\n-\t\tupdate_ref(msg, ref->name, ref->old_sha1,\n+\t\tupdate_ref(msg, ref->name, ref->old_oid.hash,\n \t\t\t   NULL, 0, UPDATE_REFS_DIE_ON_ERR);\n \t}\n }\n@@ -542,7 +542,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])\n \tif (!ref)\n \t\treturn -1;\n \n-\thashcpy(sha1, ref->old_sha1);\n+\thashcpy(sha1, ref->old_oid.hash);\n \t*rm = ref->next;\n \treturn 0;\n }\n@@ -591,12 +591,12 @@ static void update_head(const struct ref *our, const struct ref *remote,\n \t\t/* Local default branch link */\n \t\tcreate_symref(\"HEAD\", our->name, NULL);\n \t\tif (!option_bare) {\n-\t\t\tupdate_ref(msg, \"HEAD\", our->old_sha1, NULL, 0,\n+\t\t\tupdate_ref(msg, \"HEAD\", our->old_oid.hash, NULL, 0,\n \t\t\t\t   UPDATE_REFS_DIE_ON_ERR);\n \t\t\tinstall_branch_config(0, head, option_origin, our->name);\n \t\t}\n \t} else if (our) {\n-\t\tstruct commit *c = lookup_commit_reference(our->old_sha1);\n+\t\tstruct commit *c = lookup_commit_reference(our->old_oid.hash);\n \t\t/* --branch specifies a non-branch (i.e. tags), detach HEAD */\n \t\tupdate_ref(msg, \"HEAD\", c->object.sha1,\n \t\t\t   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);\n@@ -606,7 +606,7 @@ static void update_head(const struct ref *our, const struct ref *remote,\n \t\t * HEAD points to a branch but we don't know which one.\n \t\t * Detach HEAD in all these cases.\n \t\t */\n-\t\tupdate_ref(msg, \"HEAD\", remote->old_sha1,\n+\t\tupdate_ref(msg, \"HEAD\", remote->old_oid.hash,\n \t\t\t   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);\n \t}\n }\n@@ -957,7 +957,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t * remote HEAD check.\n \t\t */\n \t\tfor (ref = refs; ref; ref = ref->next)\n-\t\t\tif (is_null_sha1(ref->old_sha1)) {\n+\t\t\tif (is_null_oid(&ref->old_oid)) {\n \t\t\t\tcomplete_refs_before_fetch = 0;\n \t\t\t\tbreak;\n \t\t\t}\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 4a6b340..19215b3 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -17,7 +17,7 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,\n \tunsigned char sha1[20];\n \n \tif (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {\n-\t\thashcpy(ref->old_sha1, sha1);\n+\t\thashcpy(ref->old_oid.hash, sha1);\n \t\tname += 41;\n \t\tnamelen -= 41;\n \t}\n@@ -210,7 +210,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \n \twhile (ref) {\n \t\tprintf(\"%s %s\\n\",\n-\t\t       sha1_to_hex(ref->old_sha1), ref->name);\n+\t\t       oid_to_hex(&ref->old_oid), ref->name);\n \t\tref = ref->next;\n \t}\n \ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 8d5b2db..af42cde 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -195,7 +195,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)\n {\n \tstruct ref *rm = *head;\n \twhile (rm) {\n-\t\tif (!hashcmp(rm->old_sha1, sha1))\n+\t\tif (!hashcmp(rm->old_oid.hash, sha1))\n \t\t\treturn 1;\n \t\trm = rm->next;\n \t}\n@@ -223,8 +223,8 @@ static void find_non_local_tags(struct transport *transport,\n \t\t * as one to ignore by setting util to NULL.\n \t\t */\n \t\tif (ends_with(ref->name, \"^{}\")) {\n-\t\t\tif (item && !has_sha1_file(ref->old_sha1) &&\n-\t\t\t    !will_fetch(head, ref->old_sha1) &&\n+\t\t\tif (item && !has_object_file(&ref->old_oid) &&\n+\t\t\t    !will_fetch(head, ref->old_oid.hash) &&\n \t\t\t    !has_sha1_file(item->util) &&\n \t\t\t    !will_fetch(head, item->util))\n \t\t\t\titem->util = NULL;\n@@ -250,7 +250,7 @@ static void find_non_local_tags(struct transport *transport,\n \t\t\tcontinue;\n \n \t\titem = string_list_insert(&remote_refs, ref->name);\n-\t\titem->util = (void *)ref->old_sha1;\n+\t\titem->util = (void *)&ref->old_oid;\n \t}\n \tstring_list_clear(&existing_refs, 1);\n \n@@ -272,7 +272,7 @@ static void find_non_local_tags(struct transport *transport,\n \t\t{\n \t\t\tstruct ref *rm = alloc_ref(item->string);\n \t\t\trm->peer_ref = alloc_ref(item->string);\n-\t\t\thashcpy(rm->old_sha1, item->util);\n+\t\t\toidcpy(&rm->old_oid, item->util);\n \t\t\t**tail = rm;\n \t\t\t*tail = &rm->next;\n \t\t}\n@@ -418,8 +418,8 @@ static int s_update_ref(const char *action,\n \ttransaction = ref_transaction_begin(&err);\n \tif (!transaction ||\n \t    ref_transaction_update(transaction, ref->name,\n-\t\t\t\t   ref->new_sha1,\n-\t\t\t\t   check_old ? ref->old_sha1 : NULL,\n+\t\t\t\t   ref->new_oid.hash,\n+\t\t\t\t   check_old ? ref->old_oid.hash : NULL,\n \t\t\t\t   0, msg, &err))\n \t\tgoto fail;\n \n@@ -452,11 +452,11 @@ static int update_local_ref(struct ref *ref,\n \tstruct branch *current_branch = branch_get(NULL);\n \tconst char *pretty_ref = prettify_refname(ref->name);\n \n-\ttype = sha1_object_info(ref->new_sha1, NULL);\n+\ttype = sha1_object_info(ref->new_oid.hash, NULL);\n \tif (type < 0)\n-\t\tdie(_(\"object %s not found\"), sha1_to_hex(ref->new_sha1));\n+\t\tdie(_(\"object %s not found\"), oid_to_hex(&ref->new_oid));\n \n-\tif (!hashcmp(ref->old_sha1, ref->new_sha1)) {\n+\tif (!oidcmp(&ref->old_oid, &ref->new_oid)) {\n \t\tif (verbosity > 0)\n \t\t\tstrbuf_addf(display, \"= %-*s %-*s -> %s\",\n \t\t\t\t    TRANSPORT_SUMMARY(_(\"[up to date]\")),\n@@ -467,7 +467,7 @@ static int update_local_ref(struct ref *ref,\n \tif (current_branch &&\n \t    !strcmp(ref->name, current_branch->name) &&\n \t    !(update_head_ok || is_bare_repository()) &&\n-\t    !is_null_sha1(ref->old_sha1)) {\n+\t    !is_null_oid(&ref->old_oid)) {\n \t\t/*\n \t\t * If this is the head, and it's not okay to update\n \t\t * the head, and the old value of the head isn't empty...\n@@ -479,7 +479,7 @@ static int update_local_ref(struct ref *ref,\n \t\treturn 1;\n \t}\n \n-\tif (!is_null_sha1(ref->old_sha1) &&\n+\tif (!is_null_oid(&ref->old_oid) &&\n \t    starts_with(ref->name, \"refs/tags/\")) {\n \t\tint r;\n \t\tr = s_update_ref(\"updating tag\", ref, 0);\n@@ -491,8 +491,8 @@ static int update_local_ref(struct ref *ref,\n \t\treturn r;\n \t}\n \n-\tcurrent = lookup_commit_reference_gently(ref->old_sha1, 1);\n-\tupdated = lookup_commit_reference_gently(ref->new_sha1, 1);\n+\tcurrent = lookup_commit_reference_gently(ref->old_oid.hash, 1);\n+\tupdated = lookup_commit_reference_gently(ref->new_oid.hash, 1);\n \tif (!current || !updated) {\n \t\tconst char *msg;\n \t\tconst char *what;\n@@ -516,7 +516,7 @@ static int update_local_ref(struct ref *ref,\n \n \t\tif ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&\n \t\t    (recurse_submodules != RECURSE_SUBMODULES_ON))\n-\t\t\tcheck_for_new_submodule_commits(ref->new_sha1);\n+\t\t\tcheck_for_new_submodule_commits(ref->new_oid.hash);\n \t\tr = s_update_ref(msg, ref, 0);\n \t\tstrbuf_addf(display, \"%c %-*s %-*s -> %s%s\",\n \t\t\t    r ? '!' : '*',\n@@ -531,10 +531,10 @@ static int update_local_ref(struct ref *ref,\n \t\tint r;\n \t\tstrcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));\n \t\tstrcat(quickref, \"..\");\n-\t\tstrcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));\n+\t\tstrcat(quickref, find_unique_abbrev(ref->new_oid.hash, DEFAULT_ABBREV));\n \t\tif ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&\n \t\t    (recurse_submodules != RECURSE_SUBMODULES_ON))\n-\t\t\tcheck_for_new_submodule_commits(ref->new_sha1);\n+\t\t\tcheck_for_new_submodule_commits(ref->new_oid.hash);\n \t\tr = s_update_ref(\"fast-forward\", ref, 1);\n \t\tstrbuf_addf(display, \"%c %-*s %-*s -> %s%s\",\n \t\t\t    r ? '!' : ' ',\n@@ -547,10 +547,10 @@ static int update_local_ref(struct ref *ref,\n \t\tint r;\n \t\tstrcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));\n \t\tstrcat(quickref, \"...\");\n-\t\tstrcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));\n+\t\tstrcat(quickref, find_unique_abbrev(ref->new_oid.hash, DEFAULT_ABBREV));\n \t\tif ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&\n \t\t    (recurse_submodules != RECURSE_SUBMODULES_ON))\n-\t\t\tcheck_for_new_submodule_commits(ref->new_sha1);\n+\t\t\tcheck_for_new_submodule_commits(ref->new_oid.hash);\n \t\tr = s_update_ref(\"forced-update\", ref, 1);\n \t\tstrbuf_addf(display, \"%c %-*s %-*s -> %s  (%s)\",\n \t\t\t    r ? '!' : '+',\n@@ -577,7 +577,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])\n \tif (!ref)\n \t\treturn -1; /* end of the list */\n \t*rm = ref->next;\n-\thashcpy(sha1, ref->old_sha1);\n+\thashcpy(sha1, ref->old_oid.hash);\n \treturn 0;\n }\n \n@@ -628,7 +628,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\t\tcontinue;\n \t\t\t}\n \n-\t\t\tcommit = lookup_commit_reference_gently(rm->old_sha1, 1);\n+\t\t\tcommit = lookup_commit_reference_gently(rm->old_oid.hash, 1);\n \t\t\tif (!commit)\n \t\t\t\trm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;\n \n@@ -638,8 +638,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\tif (rm->peer_ref) {\n \t\t\t\tref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);\n \t\t\t\tstrcpy(ref->name, rm->peer_ref->name);\n-\t\t\t\thashcpy(ref->old_sha1, rm->peer_ref->old_sha1);\n-\t\t\t\thashcpy(ref->new_sha1, rm->old_sha1);\n+\t\t\t\toidcpy(&ref->old_oid, &rm->peer_ref->old_oid);\n+\t\t\t\toidcpy(&ref->new_oid, &rm->old_oid);\n \t\t\t\tref->force = rm->peer_ref->force;\n \t\t\t}\n \n@@ -684,7 +684,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \t\t\t\t/* fall-through */\n \t\t\tcase FETCH_HEAD_MERGE:\n \t\t\t\tfprintf(fp, \"%s\\t%s\\t%s\",\n-\t\t\t\t\tsha1_to_hex(rm->old_sha1),\n+\t\t\t\t\toid_to_hex(&rm->old_oid),\n \t\t\t\t\tmerge_status_marker,\n \t\t\t\t\tnote.buf);\n \t\t\t\tfor (i = 0; i < url_len; ++i)\n@@ -917,7 +917,7 @@ static int do_fetch(struct transport *transport,\n \t\t\t\t\t\t   rm->peer_ref->name);\n \t\t\tif (peer_item) {\n \t\t\t\tstruct object_id *old_oid = peer_item->util;\n-\t\t\t\thashcpy(rm->peer_ref->old_sha1, old_oid->hash);\n+\t\t\t\toidcpy(&rm->peer_ref->old_oid, old_oid);\n \t\t\t}\n \t\t}\n \t}\ndiff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\nindex 4554dbc..db35e58 100644\n--- a/builtin/ls-remote.c\n+++ b/builtin/ls-remote.c\n@@ -129,7 +129,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n \t\t\tcontinue;\n \t\tif (!tail_match(pattern, ref->name))\n \t\t\tcontinue;\n-\t\tprintf(\"%s\t%s\\n\", sha1_to_hex(ref->old_sha1), ref->name);\n+\t\tprintf(\"%s\t%s\\n\", oid_to_hex(&ref->old_oid), ref->name);\n \t\tstatus = 0; /* we found something */\n \t}\n \treturn status;\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 94d0571..5941c78 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -222,7 +222,7 @@ static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)\n static void collect_one_alternate_ref(const struct ref *ref, void *data)\n {\n \tstruct sha1_array *sa = data;\n-\tsha1_array_append(sa, ref->old_sha1);\n+\tsha1_array_append(sa, ref->old_oid.hash);\n }\n \n static void write_head_info(void)\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex f4a6ec9..fa4d04c 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -395,7 +395,7 @@ static int get_push_ref_states(const struct ref *remote_refs,\n \n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\thashcpy(ref->new_sha1, ref->peer_ref->new_sha1);\n+\t\toidcpy(&ref->new_oid, &ref->peer_ref->new_oid);\n \n \t\titem = string_list_append(&states->push,\n \t\t\t\t\t  abbrev_branch(ref->peer_ref->name));\n@@ -404,14 +404,14 @@ static int get_push_ref_states(const struct ref *remote_refs,\n \t\tinfo->forced = ref->force;\n \t\tinfo->dest = xstrdup(abbrev_branch(ref->name));\n \n-\t\tif (is_null_sha1(ref->new_sha1)) {\n+\t\tif (is_null_oid(&ref->new_oid)) {\n \t\t\tinfo->status = PUSH_STATUS_DELETE;\n-\t\t} else if (!hashcmp(ref->old_sha1, ref->new_sha1))\n+\t\t} else if (!oidcmp(&ref->old_oid, &ref->new_oid))\n \t\t\tinfo->status = PUSH_STATUS_UPTODATE;\n-\t\telse if (is_null_sha1(ref->old_sha1))\n+\t\telse if (is_null_oid(&ref->old_oid))\n \t\t\tinfo->status = PUSH_STATUS_CREATE;\n-\t\telse if (has_sha1_file(ref->old_sha1) &&\n-\t\t\t ref_newer(ref->new_sha1, ref->old_sha1))\n+\t\telse if (has_object_file(&ref->old_oid) &&\n+\t\t\t ref_newer(ref->new_oid.hash, ref->old_oid.hash))\n \t\t\tinfo->status = PUSH_STATUS_FASTFORWARD;\n \t\telse\n \t\t\tinfo->status = PUSH_STATUS_OUTOFDATE;\ndiff --git a/connect.c b/connect.c\nindex c0144d8..f8b10eb 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -165,7 +165,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,\n \t\tif (!check_ref(name, flags))\n \t\t\tcontinue;\n \t\tref = alloc_ref(buffer + 41);\n-\t\thashcpy(ref->old_sha1, old_sha1);\n+\t\thashcpy(ref->old_oid.hash, old_sha1);\n \t\t*list = ref;\n \t\tlist = &ref->next;\n \t\tgot_at_least_one_head = 1;\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex a912935..c02ea87 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -238,7 +238,7 @@ static void send_request(struct fetch_pack_args *args,\n \n static void insert_one_alternate_ref(const struct ref *ref, void *unused)\n {\n-\trev_list_insert_ref(NULL, ref->old_sha1);\n+\trev_list_insert_ref(NULL, ref->old_oid.hash);\n }\n \n #define INITIAL_FLUSH 16\n@@ -280,7 +280,7 @@ static int find_common(struct fetch_pack_args *args,\n \n \tfetching = 0;\n \tfor ( ; refs ; refs = refs->next) {\n-\t\tunsigned char *remote = refs->old_sha1;\n+\t\tunsigned char *remote = refs->old_oid.hash;\n \t\tconst char *remote_hex;\n \t\tstruct object *o;\n \n@@ -570,7 +570,7 @@ static void filter_refs(struct fetch_pack_args *args,\n \t\t\t\tcontinue;\n \t\t\tif (get_sha1_hex(ref->name, sha1) ||\n \t\t\t    ref->name[40] != '\\0' ||\n-\t\t\t    hashcmp(sha1, ref->old_sha1))\n+\t\t\t    hashcmp(sha1, ref->old_oid.hash))\n \t\t\t\tcontinue;\n \n \t\t\tref->matched = 1;\n@@ -583,7 +583,7 @@ static void filter_refs(struct fetch_pack_args *args,\n \n static void mark_alternate_complete(const struct ref *ref, void *unused)\n {\n-\tmark_complete(ref->old_sha1);\n+\tmark_complete(ref->old_oid.hash);\n }\n \n static int everything_local(struct fetch_pack_args *args,\n@@ -599,10 +599,10 @@ static int everything_local(struct fetch_pack_args *args,\n \tfor (ref = *refs; ref; ref = ref->next) {\n \t\tstruct object *o;\n \n-\t\tif (!has_sha1_file(ref->old_sha1))\n+\t\tif (!has_object_file(&ref->old_oid))\n \t\t\tcontinue;\n \n-\t\to = parse_object(ref->old_sha1);\n+\t\to = parse_object(ref->old_oid.hash);\n \t\tif (!o)\n \t\t\tcontinue;\n \n@@ -630,7 +630,7 @@ static int everything_local(struct fetch_pack_args *args,\n \t * Don't mark them common yet; the server has to be told so first.\n \t */\n \tfor (ref = *refs; ref; ref = ref->next) {\n-\t\tstruct object *o = deref_tag(lookup_object(ref->old_sha1),\n+\t\tstruct object *o = deref_tag(lookup_object(ref->old_oid.hash),\n \t\t\t\t\t     NULL, 0);\n \n \t\tif (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))\n@@ -646,7 +646,7 @@ static int everything_local(struct fetch_pack_args *args,\n \tfilter_refs(args, refs, sought, nr_sought);\n \n \tfor (retval = 1, ref = *refs; ref ; ref = ref->next) {\n-\t\tconst unsigned char *remote = ref->old_sha1;\n+\t\tconst unsigned char *remote = ref->old_oid.hash;\n \t\tstruct object *o;\n \n \t\to = lookup_object(remote);\n@@ -987,7 +987,7 @@ static void update_shallow(struct fetch_pack_args *args,\n \tif (!si->nr_ours && !si->nr_theirs)\n \t\treturn;\n \tfor (i = 0; i < nr_sought; i++)\n-\t\tsha1_array_append(&ref, sought[i]->old_sha1);\n+\t\tsha1_array_append(&ref, sought[i]->old_oid.hash);\n \tsi->ref = &ref;\n \n \tif (args->update_shallow) {\ndiff --git a/http-push.c b/http-push.c\nindex c98dad2..d054fdb 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1437,11 +1437,11 @@ static void one_remote_ref(const char *refname)\n \t * Fetch a copy of the object if it doesn't exist locally - it\n \t * may be required for updating server info later.\n \t */\n-\tif (repo->can_update_info_refs && !has_sha1_file(ref->old_sha1)) {\n-\t\tobj = lookup_unknown_object(ref->old_sha1);\n+\tif (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {\n+\t\tobj = lookup_unknown_object(ref->old_oid.hash);\n \t\tif (obj) {\n \t\t\tfprintf(stderr,\t\"  fetch %s for %s\\n\",\n-\t\t\t\tsha1_to_hex(ref->old_sha1), refname);\n+\t\t\t\toid_to_hex(&ref->old_oid), refname);\n \t\t\tadd_fetch_request(obj);\n \t\t}\n \t}\n@@ -1474,11 +1474,11 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)\n \t\treturn;\n \t}\n \n-\to = parse_object(ref->old_sha1);\n+\to = parse_object(ref->old_oid.hash);\n \tif (!o) {\n \t\tfprintf(stderr,\n \t\t\t\"Unable to parse object %s for remote ref %s\\n\",\n-\t\t\tsha1_to_hex(ref->old_sha1), ls->dentry_name);\n+\t\t\toid_to_hex(&ref->old_oid), ls->dentry_name);\n \t\taborted = 1;\n \t\tfree(ref);\n \t\treturn;\n@@ -1487,7 +1487,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)\n \tlen = strlen(ls->dentry_name) + 42;\n \tref_info = xcalloc(len + 1, 1);\n \tsprintf(ref_info, \"%s\t%s\\n\",\n-\t\tsha1_to_hex(ref->old_sha1), ls->dentry_name);\n+\t\toid_to_hex(&ref->old_oid), ls->dentry_name);\n \tfwrite_buffer(ref_info, 1, len, buf);\n \tfree(ref_info);\n \n@@ -1591,7 +1591,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)\n static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)\n {\n \tstruct commit *head = lookup_commit_or_die(head_sha1, \"HEAD\");\n-\tstruct commit *branch = lookup_commit_or_die(remote->old_sha1, remote->name);\n+\tstruct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name);\n \n \treturn in_merge_bases(branch, head);\n }\n@@ -1654,11 +1654,11 @@ static int delete_remote_branch(const char *pattern, int force)\n \t\t\treturn error(\"Remote HEAD resolves to object %s\\nwhich does not exist locally, perhaps you need to fetch?\", sha1_to_hex(head_sha1));\n \n \t\t/* Remote branch must resolve to a known object */\n-\t\tif (is_null_sha1(remote_ref->old_sha1))\n+\t\tif (is_null_oid(&remote_ref->old_oid))\n \t\t\treturn error(\"Unable to resolve remote branch %s\",\n \t\t\t\t     remote_ref->name);\n-\t\tif (!has_sha1_file(remote_ref->old_sha1))\n-\t\t\treturn error(\"Remote branch %s resolves to object %s\\nwhich does not exist locally, perhaps you need to fetch?\", remote_ref->name, sha1_to_hex(remote_ref->old_sha1));\n+\t\tif (!has_object_file(&remote_ref->old_oid))\n+\t\t\treturn error(\"Remote branch %s resolves to object %s\\nwhich does not exist locally, perhaps you need to fetch?\", remote_ref->name, oid_to_hex(&remote_ref->old_oid));\n \n \t\t/* Remote branch must be an ancestor of remote HEAD */\n \t\tif (!verify_merge_base(head_sha1, remote_ref)) {\n@@ -1874,7 +1874,7 @@ int main(int argc, char **argv)\n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n \n-\t\tif (is_null_sha1(ref->peer_ref->new_sha1)) {\n+\t\tif (is_null_oid(&ref->peer_ref->new_oid)) {\n \t\t\tif (delete_remote_branch(ref->name, 1) == -1) {\n \t\t\t\terror(\"Could not remove %s\", ref->name);\n \t\t\t\tif (helper_status)\n@@ -1887,7 +1887,7 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {\n+\t\tif (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {\n \t\t\tif (push_verbosely)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n \t\t\tif (helper_status)\n@@ -1896,11 +1896,11 @@ int main(int argc, char **argv)\n \t\t}\n \n \t\tif (!force_all &&\n-\t\t    !is_null_sha1(ref->old_sha1) &&\n+\t\t    !is_null_oid(&ref->old_oid) &&\n \t\t    !ref->force) {\n-\t\t\tif (!has_sha1_file(ref->old_sha1) ||\n-\t\t\t    !ref_newer(ref->peer_ref->new_sha1,\n-\t\t\t\t       ref->old_sha1)) {\n+\t\t\tif (!has_object_file(&ref->old_oid) ||\n+\t\t\t    !ref_newer(ref->peer_ref->new_oid.hash,\n+\t\t\t\t       ref->old_oid.hash)) {\n \t\t\t\t/*\n \t\t\t\t * We do not have the remote ref, or\n \t\t\t\t * we know that the remote ref is not\n@@ -1921,10 +1921,10 @@ int main(int argc, char **argv)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t}\n-\t\thashcpy(ref->new_sha1, ref->peer_ref->new_sha1);\n+\t\toidcpy(&ref->new_oid, &ref->peer_ref->new_oid);\n \t\tnew_refs++;\n-\t\tstrcpy(old_hex, sha1_to_hex(ref->old_sha1));\n-\t\tnew_hex = sha1_to_hex(ref->new_sha1);\n+\t\tstrcpy(old_hex, oid_to_hex(&ref->old_oid));\n+\t\tnew_hex = oid_to_hex(&ref->new_oid);\n \n \t\tfprintf(stderr, \"updating '%s'\", ref->name);\n \t\tif (strcmp(ref->name, ref->peer_ref->name))\n@@ -1949,14 +1949,14 @@ int main(int argc, char **argv)\n \n \t\t/* Set up revision info for this refspec */\n \t\tcommit_argc = 3;\n-\t\tnew_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));\n+\t\tnew_sha1_hex = xstrdup(oid_to_hex(&ref->new_oid));\n \t\told_sha1_hex = NULL;\n \t\tcommit_argv[1] = \"--objects\";\n \t\tcommit_argv[2] = new_sha1_hex;\n-\t\tif (!push_all && !is_null_sha1(ref->old_sha1)) {\n+\t\tif (!push_all && !is_null_oid(&ref->old_oid)) {\n \t\t\told_sha1_hex = xmalloc(42);\n \t\t\tsprintf(old_sha1_hex, \"^%s\",\n-\t\t\t\tsha1_to_hex(ref->old_sha1));\n+\t\t\t\toid_to_hex(&ref->old_oid));\n \t\t\tcommit_argv[3] = old_sha1_hex;\n \t\t\tcommit_argc++;\n \t\t}\n@@ -1988,7 +1988,7 @@ int main(int argc, char **argv)\n \t\trun_request_queue();\n \n \t\t/* Update the remote branch if all went well */\n-\t\tif (aborted || !update_remote(ref->new_sha1, ref_lock))\n+\t\tif (aborted || !update_remote(ref->new_oid.hash, ref_lock))\n \t\t\trc = 1;\n \n \t\tif (!rc)\ndiff --git a/http.c b/http.c\nindex f0c5bbc..96b7863 100644\n--- a/http.c\n+++ b/http.c\n@@ -1338,7 +1338,7 @@ int http_fetch_ref(const char *base, struct ref *ref)\n \tif (http_get_strbuf(url, &buffer, &options) == HTTP_OK) {\n \t\tstrbuf_rtrim(&buffer);\n \t\tif (buffer.len == 40)\n-\t\t\tret = get_sha1_hex(buffer.buf, ref->old_sha1);\n+\t\t\tret = get_oid_hex(buffer.buf, &ref->old_oid);\n \t\telse if (starts_with(buffer.buf, \"ref: \")) {\n \t\t\tref->symref = xstrdup(buffer.buf + 5);\n \t\t\tret = 0;\ndiff --git a/remote-curl.c b/remote-curl.c\nindex af7b678..80cb4c7 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -168,7 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)\n \t\t\t\t      strlen(ref_name) + 1);\n \t\t\tmemset(ref, 0, sizeof(struct ref));\n \t\t\tstrcpy(ref->name, ref_name);\n-\t\t\tget_sha1_hex(start, ref->old_sha1);\n+\t\t\tget_oid_hex(start, &ref->old_oid);\n \t\t\tif (!refs)\n \t\t\t\trefs = ref;\n \t\t\tif (last_ref)\n@@ -347,7 +347,7 @@ static void output_refs(struct ref *refs)\n \t\tif (posn->symref)\n \t\t\tprintf(\"@%s %s\\n\", posn->symref, posn->name);\n \t\telse\n-\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(posn->old_sha1), posn->name);\n+\t\t\tprintf(\"%s %s\\n\", oid_to_hex(&posn->old_oid), posn->name);\n \t}\n \tprintf(\"\\n\");\n \tfflush(stdout);\n@@ -701,7 +701,7 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n \tif (options.depth)\n \t\tdie(\"dumb http transport does not support --depth\");\n \tfor (i = 0; i < nr_heads; i++)\n-\t\ttargets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));\n+\t\ttargets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));\n \n \twalker = get_http_walker(url.buf);\n \twalker->get_all = 1;\n@@ -762,7 +762,7 @@ static int fetch_git(struct discovery *heads,\n \t\tif (!*ref->name)\n \t\t\tdie(\"cannot fetch by sha1 over smart http\");\n \t\tpacket_buf_write(&preamble, \"%s %s\\n\",\n-\t\t\t\t sha1_to_hex(ref->old_sha1), ref->name);\n+\t\t\t\t oid_to_hex(&ref->old_oid), ref->name);\n \t}\n \tpacket_buf_flush(&preamble);\n \n@@ -814,7 +814,7 @@ static void parse_fetch(struct strbuf *buf)\n \t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n \n \t\t\tref = alloc_ref(name);\n-\t\t\thashcpy(ref->old_sha1, old_sha1);\n+\t\t\thashcpy(ref->old_oid.hash, old_sha1);\n \n \t\t\t*list = ref;\n \t\t\tlist = &ref->next;\ndiff --git a/remote.c b/remote.c\nindex 26504b7..706d2fb 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1111,7 +1111,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)\n static struct ref *alloc_delete_ref(void)\n {\n \tstruct ref *ref = alloc_ref(\"(delete)\");\n-\thashclr(ref->new_sha1);\n+\toidclr(&ref->new_oid);\n \treturn ref;\n }\n \n@@ -1131,7 +1131,7 @@ static int try_explicit_object_name(const char *name,\n \n \tif (match) {\n \t\t*match = alloc_ref(name);\n-\t\thashcpy((*match)->new_sha1, sha1);\n+\t\thashcpy((*match)->new_oid.hash, sha1);\n \t}\n \treturn 0;\n }\n@@ -1226,7 +1226,7 @@ static int match_explicit(struct ref *src, struct ref *dst,\n \tcase 0:\n \t\tif (starts_with(dst_value, \"refs/\"))\n \t\t\tmatched_dst = make_linked_ref(dst_value, dst_tail);\n-\t\telse if (is_null_sha1(matched_src->new_sha1))\n+\t\telse if (is_null_oid(&matched_src->new_oid))\n \t\t\terror(\"unable to delete '%s': remote ref does not exist\",\n \t\t\t      dst_value);\n \t\telse if ((dst_guess = guess_ref(dst_value, matched_src)))\n@@ -1357,10 +1357,10 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \tmemset(&sent_tips, 0, sizeof(sent_tips));\n \tfor (ref = *dst; ref; ref = ref->next) {\n \t\tif (ref->peer_ref &&\n-\t\t    !is_null_sha1(ref->peer_ref->new_sha1))\n-\t\t\tadd_to_tips(&sent_tips, ref->peer_ref->new_sha1);\n+\t\t    !is_null_oid(&ref->peer_ref->new_oid))\n+\t\t\tadd_to_tips(&sent_tips, ref->peer_ref->new_oid.hash);\n \t\telse\n-\t\t\tadd_to_tips(&sent_tips, ref->old_sha1);\n+\t\t\tadd_to_tips(&sent_tips, ref->old_oid.hash);\n \t\tif (starts_with(ref->name, \"refs/tags/\"))\n \t\t\tstring_list_append(&dst_tag, ref->name);\n \t}\n@@ -1374,7 +1374,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \t\t\tcontinue; /* not a tag */\n \t\tif (string_list_has_string(&dst_tag, ref->name))\n \t\t\tcontinue; /* they already have it */\n-\t\tif (sha1_object_info(ref->new_sha1, NULL) != OBJ_TAG)\n+\t\tif (sha1_object_info(ref->new_oid.hash, NULL) != OBJ_TAG)\n \t\t\tcontinue; /* be conservative */\n \t\titem = string_list_append(&src_tag, ref->name);\n \t\titem->util = ref;\n@@ -1394,9 +1394,9 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \t\t\tstruct ref *dst_ref;\n \t\t\tstruct commit *commit;\n \n-\t\t\tif (is_null_sha1(ref->new_sha1))\n+\t\t\tif (is_null_oid(&ref->new_oid))\n \t\t\t\tcontinue;\n-\t\t\tcommit = lookup_commit_reference_gently(ref->new_sha1, 1);\n+\t\t\tcommit = lookup_commit_reference_gently(ref->new_oid.hash, 1);\n \t\t\tif (!commit)\n \t\t\t\t/* not pushing a commit, which is not an error */\n \t\t\t\tcontinue;\n@@ -1410,7 +1410,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \n \t\t\t/* Add it in */\n \t\t\tdst_ref = make_linked_ref(ref->name, dst_tail);\n-\t\t\thashcpy(dst_ref->new_sha1, ref->new_sha1);\n+\t\t\toidcpy(&dst_ref->new_oid, &ref->new_oid);\n \t\t\tdst_ref->peer_ref = copy_ref(ref);\n \t\t}\n \t}\n@@ -1517,7 +1517,7 @@ int match_push_refs(struct ref *src, struct ref **dst,\n \n \t\t\t/* Create a new one and link it */\n \t\t\tdst_peer = make_linked_ref(dst_name, &dst_tail);\n-\t\t\thashcpy(dst_peer->new_sha1, ref->new_sha1);\n+\t\t\toidcpy(&dst_peer->new_oid, &ref->new_oid);\n \t\t\tstring_list_insert(&dst_ref_index,\n \t\t\t\tdst_peer->name)->util = dst_peer;\n \t\t}\n@@ -1569,13 +1569,13 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\tint reject_reason = 0;\n \n \t\tif (ref->peer_ref)\n-\t\t\thashcpy(ref->new_sha1, ref->peer_ref->new_sha1);\n+\t\t\toidcpy(&ref->new_oid, &ref->peer_ref->new_oid);\n \t\telse if (!send_mirror)\n \t\t\tcontinue;\n \n-\t\tref->deletion = is_null_sha1(ref->new_sha1);\n+\t\tref->deletion = is_null_oid(&ref->new_oid);\n \t\tif (!ref->deletion &&\n-\t\t\t!hashcmp(ref->old_sha1, ref->new_sha1)) {\n+\t\t\t!oidcmp(&ref->old_oid, &ref->new_oid)) {\n \t\t\tref->status = REF_STATUS_UPTODATE;\n \t\t\tcontinue;\n \t\t}\n@@ -1594,7 +1594,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t */\n \t\tif (ref->expect_old_sha1) {\n \t\t\tif (ref->expect_old_no_trackback ||\n-\t\t\t    hashcmp(ref->old_sha1, ref->old_sha1_expect))\n+\t\t\t    oidcmp(&ref->old_oid, &ref->old_oid_expect))\n \t\t\t\treject_reason = REF_STATUS_REJECT_STALE;\n \t\t}\n \n@@ -1618,15 +1618,15 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t *     passing the --force argument\n \t\t */\n \n-\t\telse if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {\n+\t\telse if (!ref->deletion && !is_null_oid(&ref->old_oid)) {\n \t\t\tif (starts_with(ref->name, \"refs/tags/\"))\n \t\t\t\treject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;\n-\t\t\telse if (!has_sha1_file(ref->old_sha1))\n+\t\t\telse if (!has_object_file(&ref->old_oid))\n \t\t\t\treject_reason = REF_STATUS_REJECT_FETCH_FIRST;\n-\t\t\telse if (!lookup_commit_reference_gently(ref->old_sha1, 1) ||\n-\t\t\t\t !lookup_commit_reference_gently(ref->new_sha1, 1))\n+\t\t\telse if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) ||\n+\t\t\t\t !lookup_commit_reference_gently(ref->new_oid.hash, 1))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NEEDS_FORCE;\n-\t\t\telse if (!ref_newer(ref->new_sha1, ref->old_sha1))\n+\t\t\telse if (!ref_newer(ref->new_oid.hash, ref->old_oid.hash))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NONFASTFORWARD;\n \t\t}\n \n@@ -1925,7 +1925,7 @@ int get_fetch_map(const struct ref *remote_refs,\n \n \t\tif (refspec->exact_sha1) {\n \t\t\tref_map = alloc_ref(name);\n-\t\t\tget_sha1_hex(name, ref_map->old_sha1);\n+\t\t\tget_oid_hex(name, &ref_map->old_oid);\n \t\t} else {\n \t\t\tref_map = get_remote_ref(remote_refs, name);\n \t\t}\n@@ -1966,7 +1966,7 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)\n \t\treturn 0;\n \tfor (; list; list = list->next)\n \t\tif (!strcmp(ref->symref, list->name)) {\n-\t\t\thashcpy(ref->old_sha1, list->old_sha1);\n+\t\t\toidcpy(&ref->old_oid, &list->old_oid);\n \t\t\treturn 0;\n \t\t}\n \treturn 1;\n@@ -2181,7 +2181,7 @@ static int one_local_ref(const char *refname, const struct object_id *oid,\n \n \tlen = strlen(refname) + 1;\n \tref = xcalloc(1, sizeof(*ref) + len);\n-\thashcpy(ref->new_sha1, oid->hash);\n+\thashcpy(ref->new_oid.hash, oid->hash);\n \tmemcpy(ref->name, refname, len);\n \t**local_tail = ref;\n \t*local_tail = &ref->next;\n@@ -2218,7 +2218,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \t/* If refs/heads/master could be right, it is. */\n \tif (!all) {\n \t\tr = find_ref_by_name(refs, \"refs/heads/master\");\n-\t\tif (r && !hashcmp(r->old_sha1, head->old_sha1))\n+\t\tif (r && !oidcmp(&r->old_oid, &head->old_oid))\n \t\t\treturn copy_ref(r);\n \t}\n \n@@ -2226,7 +2226,7 @@ struct ref *guess_remote_head(const struct ref *head,\n \tfor (r = refs; r; r = r->next) {\n \t\tif (r != head &&\n \t\t    starts_with(r->name, \"refs/heads/\") &&\n-\t\t    !hashcmp(r->old_sha1, head->old_sha1)) {\n+\t\t    !oidcmp(&r->old_oid, &head->old_oid)) {\n \t\t\t*tail = copy_ref(r);\n \t\t\ttail = &((*tail)->next);\n \t\t\tif (!all)\n@@ -2274,7 +2274,7 @@ static int get_stale_heads_cb(const char *refname, const struct object_id *oid,\n \n \tif (stale) {\n \t\tstruct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);\n-\t\thashcpy(ref->new_sha1, oid->hash);\n+\t\toidcpy(&ref->new_oid, oid);\n \t}\n \n clean_exit:\n@@ -2394,8 +2394,8 @@ static void apply_cas(struct push_cas_option *cas,\n \t\t\tcontinue;\n \t\tref->expect_old_sha1 = 1;\n \t\tif (!entry->use_tracking)\n-\t\t\thashcpy(ref->old_sha1_expect, cas->entry[i].expect);\n-\t\telse if (remote_tracking(remote, ref->name, ref->old_sha1_expect))\n+\t\t\thashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);\n+\t\telse if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))\n \t\t\tref->expect_old_no_trackback = 1;\n \t\treturn;\n \t}\n@@ -2405,7 +2405,7 @@ static void apply_cas(struct push_cas_option *cas,\n \t\treturn;\n \n \tref->expect_old_sha1 = 1;\n-\tif (remote_tracking(remote, ref->name, ref->old_sha1_expect))\n+\tif (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))\n \t\tref->expect_old_no_trackback = 1;\n }\n \ndiff --git a/remote.h b/remote.h\nindex 312b7ca..163ea5e 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -79,9 +79,9 @@ extern const struct refspec *tag_refspec;\n \n struct ref {\n \tstruct ref *next;\n-\tunsigned char old_sha1[20];\n-\tunsigned char new_sha1[20];\n-\tunsigned char old_sha1_expect[20]; /* used by expect-old */\n+\tstruct object_id old_oid;\n+\tstruct object_id new_oid;\n+\tstruct object_id old_oid_expect; /* used by expect-old */\n \tchar *symref;\n \tunsigned int\n \t\tforce:1,\ndiff --git a/send-pack.c b/send-pack.c\nindex 2a64fec..ae3a104 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -79,11 +79,11 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru\n \t\t\tbreak;\n \n \twhile (refs) {\n-\t\tif (!is_null_sha1(refs->old_sha1) &&\n-\t\t    !feed_object(refs->old_sha1, po.in, 1))\n+\t\tif (!is_null_oid(&refs->old_oid) &&\n+\t\t    !feed_object(refs->old_oid.hash, po.in, 1))\n \t\t\tbreak;\n-\t\tif (!is_null_sha1(refs->new_sha1) &&\n-\t\t    !feed_object(refs->new_sha1, po.in, 0))\n+\t\tif (!is_null_oid(&refs->new_oid) &&\n+\t\t    !feed_object(refs->new_oid.hash, po.in, 0))\n \t\t\tbreak;\n \t\trefs = refs->next;\n \t}\n@@ -261,8 +261,8 @@ static int generate_push_cert(struct strbuf *req_buf,\n \t\t\tcontinue;\n \t\tupdate_seen = 1;\n \t\tstrbuf_addf(&cert, \"%s %s %s\\n\",\n-\t\t\t    sha1_to_hex(ref->old_sha1),\n-\t\t\t    sha1_to_hex(ref->new_sha1),\n+\t\t\t    oid_to_hex(&ref->old_oid),\n+\t\t\t    oid_to_hex(&ref->new_oid),\n \t\t\t    ref->name);\n \t}\n \tif (!update_seen)\n@@ -458,8 +458,8 @@ int send_pack(struct send_pack_args *args,\n \t\tif (check_to_send_update(ref, args) < 0)\n \t\t\tcontinue;\n \n-\t\told_hex = sha1_to_hex(ref->old_sha1);\n-\t\tnew_hex = sha1_to_hex(ref->new_sha1);\n+\t\told_hex = oid_to_hex(&ref->old_oid);\n+\t\tnew_hex = oid_to_hex(&ref->new_oid);\n \t\tif (!cmds_sent) {\n \t\t\tpacket_buf_write(&req_buf,\n \t\t\t\t\t \"%s %s %s%c%s\",\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 5d99a6b..4ca3e80 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -347,7 +347,7 @@ static int fetch_with_fetch(struct transport *transport,\n \t\t\tcontinue;\n \n \t\tstrbuf_addf(&buf, \"fetch %s %s\\n\",\n-\t\t\t    sha1_to_hex(posn->old_sha1),\n+\t\t\t    oid_to_hex(&posn->old_oid),\n \t\t\t    posn->symref ? posn->symref : posn->name);\n \t}\n \n@@ -490,7 +490,7 @@ static int fetch_with_import(struct transport *transport,\n \t\telse\n \t\t\tprivate = xstrdup(name);\n \t\tif (private) {\n-\t\t\tread_ref(private, posn->old_sha1);\n+\t\t\tread_ref(private, posn->old_oid.hash);\n \t\t\tfree(private);\n \t\t}\n \t}\n@@ -756,7 +756,7 @@ static int push_update_refs_status(struct helper_data *data,\n \t\tprivate = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);\n \t\tif (!private)\n \t\t\tcontinue;\n-\t\tupdate_ref(\"update by helper\", private, ref->new_sha1, NULL, 0, 0);\n+\t\tupdate_ref(\"update by helper\", private, ref->new_oid.hash, NULL, 0, 0);\n \t\tfree(private);\n \t}\n \tstrbuf_release(&buf);\n@@ -803,7 +803,7 @@ static int push_refs_with_push(struct transport *transport,\n \t\t\tif (ref->peer_ref)\n \t\t\t\tstrbuf_addstr(&buf, ref->peer_ref->name);\n \t\t\telse\n-\t\t\t\tstrbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));\n+\t\t\t\tstrbuf_addstr(&buf, oid_to_hex(&ref->new_oid));\n \t\t}\n \t\tstrbuf_addch(&buf, ':');\n \t\tstrbuf_addstr(&buf, ref->name);\n@@ -812,14 +812,14 @@ static int push_refs_with_push(struct transport *transport,\n \t\t/*\n \t\t * The \"--force-with-lease\" options without explicit\n \t\t * values to expect have already been expanded into\n-\t\t * the ref->old_sha1_expect[] field; we can ignore\n+\t\t * the ref->old_oid_expect[] field; we can ignore\n \t\t * transport->smart_options->cas altogether and instead\n \t\t * can enumerate them from the refs.\n \t\t */\n \t\tif (ref->expect_old_sha1) {\n \t\t\tstruct strbuf cas = STRBUF_INIT;\n \t\t\tstrbuf_addf(&cas, \"%s:%s\",\n-\t\t\t\t    ref->name, sha1_to_hex(ref->old_sha1_expect));\n+\t\t\t\t    ref->name, oid_to_hex(&ref->old_oid_expect));\n \t\t\tstring_list_append(&cas_options, strbuf_detach(&cas, NULL));\n \t\t}\n \t}\n@@ -883,7 +883,7 @@ static int push_refs_with_export(struct transport *transport,\n \t\tif (private && !get_sha1(private, sha1)) {\n \t\t\tstrbuf_addf(&buf, \"^%s\", private);\n \t\t\tstring_list_append(&revlist_args, strbuf_detach(&buf, NULL));\n-\t\t\thashcpy(ref->old_sha1, sha1);\n+\t\t\thashcpy(ref->old_oid.hash, sha1);\n \t\t}\n \t\tfree(private);\n \n@@ -1015,11 +1015,11 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)\n \t\tif (buf.buf[0] == '@')\n \t\t\t(*tail)->symref = xstrdup(buf.buf + 1);\n \t\telse if (buf.buf[0] != '?')\n-\t\t\tget_sha1_hex(buf.buf, (*tail)->old_sha1);\n+\t\t\tget_oid_hex(buf.buf, &(*tail)->old_oid);\n \t\tif (eon) {\n \t\t\tif (has_attribute(eon + 1, \"unchanged\")) {\n \t\t\t\t(*tail)->status |= REF_STATUS_UPTODATE;\n-\t\t\t\tread_ref((*tail)->name, (*tail)->old_sha1);\n+\t\t\t\tread_ref((*tail)->name, (*tail)->old_oid.hash);\n \t\t\t}\n \t\t}\n \t\ttail = &((*tail)->next);\ndiff --git a/transport.c b/transport.c\nindex 40692f8..e880d94 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -79,7 +79,7 @@ static int read_loose_refs(struct strbuf *path, int name_offset,\n \t\t\t\tcontinue;\n \t\t\tnext = alloc_ref(path->buf + name_offset);\n \t\t\tif (read_in_full(fd, buffer, 40) != 40 ||\n-\t\t\t\t\tget_sha1_hex(buffer, next->old_sha1)) {\n+\t\t\t\t\tget_oid_hex(buffer, &next->old_oid)) {\n \t\t\t\tclose(fd);\n \t\t\t\tfree(next);\n \t\t\t\tcontinue;\n@@ -131,7 +131,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)\n \t\tif (!(*list)->next || cmp < 0) {\n \t\t\tstruct ref *next = alloc_ref(buffer + 41);\n \t\t\tbuffer[40] = '\\0';\n-\t\t\tif (get_sha1_hex(buffer, next->old_sha1)) {\n+\t\t\tif (get_oid_hex(buffer, &next->old_oid)) {\n \t\t\t\twarning (\"invalid SHA-1: %s\", buffer);\n \t\t\t\tfree(next);\n \t\t\t\tcontinue;\n@@ -162,7 +162,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,\n \t\t\tcontinue;\n \t\tif (!ref->peer_ref)\n \t\t\tcontinue;\n-\t\tif (is_null_sha1(ref->new_sha1))\n+\t\tif (is_null_oid(&ref->new_oid))\n \t\t\tcontinue;\n \n \t\t/* Follow symbolic refs (mainly for HEAD). */\n@@ -412,7 +412,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus\n \tfor (i = 0; i < data->header.references.nr; i++) {\n \t\tstruct ref_list_entry *e = data->header.references.list + i;\n \t\tstruct ref *ref = alloc_ref(e->name);\n-\t\thashcpy(ref->old_sha1, e->sha1);\n+\t\thashcpy(ref->old_oid.hash, e->sha1);\n \t\tref->next = result;\n \t\tresult = ref;\n \t}\n@@ -611,7 +611,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v\n \t\t\tdelete_ref(rs.dst, NULL, 0);\n \t\t} else\n \t\t\tupdate_ref(\"update by push\", rs.dst,\n-\t\t\t\t\tref->new_sha1, NULL, 0, 0);\n+\t\t\t\t\tref->new_oid.hash, NULL, 0, 0);\n \t\tfree(rs.dst);\n \t}\n }\n@@ -651,7 +651,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n {\n \tif (ref->deletion)\n \t\tprint_ref_status('-', \"[deleted]\", ref, NULL, NULL, porcelain);\n-\telse if (is_null_sha1(ref->old_sha1))\n+\telse if (is_null_oid(&ref->old_oid))\n \t\tprint_ref_status('*',\n \t\t\t(starts_with(ref->name, \"refs/tags/\") ? \"[new tag]\" :\n \t\t\t\"[new branch]\"),\n@@ -661,7 +661,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n \t\tchar type;\n \t\tconst char *msg;\n \n-\t\tstrcpy(quickref, status_abbrev(ref->old_sha1));\n+\t\tstrcpy(quickref, status_abbrev(ref->old_oid.hash));\n \t\tif (ref->forced_update) {\n \t\t\tstrcat(quickref, \"...\");\n \t\t\ttype = '+';\n@@ -671,7 +671,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n \t\t\ttype = ' ';\n \t\t\tmsg = NULL;\n \t\t}\n-\t\tstrcat(quickref, status_abbrev(ref->new_sha1));\n+\t\tstrcat(quickref, status_abbrev(ref->new_oid.hash));\n \n \t\tprint_ref_status(type, quickref, ref, ref->peer_ref, msg, porcelain);\n \t}\n@@ -1092,8 +1092,8 @@ static int run_pre_push_hook(struct transport *transport,\n \n \t\tstrbuf_reset(&buf);\n \t\tstrbuf_addf( &buf, \"%s %s %s %s\\n\",\n-\t\t\t r->peer_ref->name, sha1_to_hex(r->new_sha1),\n-\t\t\t r->name, sha1_to_hex(r->old_sha1));\n+\t\t\t r->peer_ref->name, oid_to_hex(&r->new_oid),\n+\t\t\t r->name, oid_to_hex(&r->old_oid));\n \n \t\tif (write_in_full(proc.in, buf.buf, buf.len) != buf.len) {\n \t\t\tret = -1;\n@@ -1173,8 +1173,8 @@ int transport_push(struct transport *transport,\n \t\tif ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {\n \t\t\tstruct ref *ref = remote_refs;\n \t\t\tfor (; ref; ref = ref->next)\n-\t\t\t\tif (!is_null_sha1(ref->new_sha1) &&\n-\t\t\t\t    !push_unpushed_submodules(ref->new_sha1,\n+\t\t\t\tif (!is_null_oid(&ref->new_oid) &&\n+\t\t\t\t    !push_unpushed_submodules(ref->new_oid.hash,\n \t\t\t\t\t    transport->remote->name))\n \t\t\t\t    die (\"Failed to push all needed submodules!\");\n \t\t}\n@@ -1185,8 +1185,8 @@ int transport_push(struct transport *transport,\n \t\t\tstruct string_list needs_pushing = STRING_LIST_INIT_DUP;\n \n \t\t\tfor (; ref; ref = ref->next)\n-\t\t\t\tif (!is_null_sha1(ref->new_sha1) &&\n-\t\t\t\t    find_unpushed_submodules(ref->new_sha1,\n+\t\t\t\tif (!is_null_oid(&ref->new_oid) &&\n+\t\t\t\t    find_unpushed_submodules(ref->new_oid.hash,\n \t\t\t\t\t    transport->remote->name, &needs_pushing))\n \t\t\t\t\tdie_with_unpushed_submodules(&needs_pushing);\n \t\t}\n@@ -1239,8 +1239,8 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)\n \tfor (rm = refs; rm; rm = rm->next) {\n \t\tnr_refs++;\n \t\tif (rm->peer_ref &&\n-\t\t    !is_null_sha1(rm->old_sha1) &&\n-\t\t    !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))\n+\t\t    !is_null_oid(&rm->old_oid) &&\n+\t\t    !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))\n \t\t\tcontinue;\n \t\tALLOC_GROW(heads, nr_heads + 1, nr_alloc);\n \t\theads[nr_heads++] = rm;\ndiff --git a/transport.h b/transport.h\nindex 18d2cf8..4a4aaac 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -75,15 +75,15 @@ struct transport {\n \t/**\n \t * Push the objects and refs. Send the necessary objects, and\n \t * then, for any refs where peer_ref is set and\n-\t * peer_ref->new_sha1 is different from old_sha1, tell the\n-\t * remote side to update each ref in the list from old_sha1 to\n-\t * peer_ref->new_sha1.\n+\t * peer_ref->new_oid is different from old_oid, tell the\n+\t * remote side to update each ref in the list from old_oid to\n+\t * peer_ref->new_oid.\n \t *\n \t * Where possible, set the status for each ref appropriately.\n \t *\n \t * The transport must modify new_sha1 in the ref to the new\n \t * value if the remote accepted the change. Note that this\n-\t * could be a different value from peer_ref->new_sha1 if the\n+\t * could be a different value from peer_ref->new_oid if the\n \t * process involved generating new commits.\n \t **/\n \tint (*push_refs)(struct transport *transport, struct ref *refs, int flags);\ndiff --git a/walker.c b/walker.c\nindex 44a936c..14f71c0 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -191,7 +191,7 @@ static int interpret_target(struct walker *walker, char *target, unsigned char *\n \tif (!check_refname_format(target, 0)) {\n \t\tstruct ref *ref = alloc_ref(target);\n \t\tif (!walker->fetch_ref(walker, ref)) {\n-\t\t\thashcpy(sha1, ref->old_sha1);\n+\t\t\thashcpy(sha1, ref->old_oid.hash);\n \t\t\tfree(ref);\n \t\t\treturn 0;\n \t\t}\n-- \n2.4.0\n"},{"id":"263371","messageId":"1433867316-663554-5-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 4/8] Add a utility function to make parsing hex values easier.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:32Z","receivedAt":"2015-06-09T16:28:32Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"get_oid_hex is already available for parsing hex object IDs into struct\nobject_id, but parsing code still must hard-code the number of bytes\nread.  Introduce parse_oid_hex, which accepts an optional length, and\nalso returns the number of bytes parsed on success, or 0 on failure.\nThis makes it easier for code not to assume fixed values when parsing,\nand to move to larger hash functions in the future.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h | 9 +++++++++\n hex.c   | 7 +++++++\n 2 files changed, 16 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex fa1f067..f3b829f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1012,6 +1012,15 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\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+/*\n+ * Like get_oid_hex, but accepts an optional length argument, which may be -1\n+ * if the string is terminated by a non-hex character.  As with get_oid_hex,\n+ * reading stops if a NUL is encountered.  Returns the number of characters\n+ * read (40) on success and 0 on failure.  This is designed to be easier to\n+ * use for parsing data than get_oid_hex.\n+ */\n+extern int parse_oid_hex(const char *hex, int len, struct object_id *oid);\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,\ndiff --git a/hex.c b/hex.c\nindex 899b74a..ba196d7 100644\n--- a/hex.c\n+++ b/hex.c\n@@ -61,6 +61,13 @@ int get_oid_hex(const char *hex, struct object_id *oid)\n \treturn get_sha1_hex(hex, oid->hash);\n }\n \n+int parse_oid_hex(const char *hex, int len, struct object_id *oid)\n+{\n+\tif (len != -1 && len < GIT_SHA1_HEXSZ)\n+\t\treturn 0;\n+\treturn get_sha1_hex(hex, oid->hash) ? GIT_SHA1_HEXSZ : 0;\n+}\n+\n char *sha1_to_hex(const unsigned char *sha1)\n {\n \tstatic int bufno;\n-- \n2.4.0\n"},{"id":"263375","messageId":"1433867316-663554-6-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 5/8] add_sought_entry_mem: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:33Z","receivedAt":"2015-06-09T16:28:33Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert this function to use struct object_id.  Use parse_oid_hex to\navoid having to hard-code the number of bytes to be parsed.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/fetch-pack.c | 12 +++++++-----\n 1 file changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 19215b3..f3b89a9 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,\n \t\t\t\t const char *name, int namelen)\n {\n \tstruct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n+\tint hexlen;\n \n-\tif (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {\n-\t\thashcpy(ref->old_oid.hash, sha1);\n-\t\tname += 41;\n-\t\tnamelen -= 41;\n+\tif ((hexlen = parse_oid_hex(name, namelen, &oid)) && namelen > hexlen + 1 &&\n+\t\tname[hexlen] == ' ') {\n+\t\toidcpy(&ref->old_oid, &oid);\n+\t\tname += hexlen + 1;\n+\t\tnamelen -= hexlen + 1;\n \t}\n \n \tmemcpy(ref->name, name, namelen);\n-- \n2.4.0\n"},{"id":"263376","messageId":"1433867316-663554-7-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 6/8] parse_fetch: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:34Z","receivedAt":"2015-06-09T16:28:34Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the parse_fetch function to use struct object_id.  Switch from\nget_sha1_hex to parse_oid_hex to avoid hard-coding constants.  Remove\nthe strlen check as parse_oid_hex will fail safely on receiving a\ntoo-short NUL-terminated string.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n remote-curl.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 80cb4c7..46206a0 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -802,19 +802,20 @@ static void parse_fetch(struct strbuf *buf)\n \t\tif (skip_prefix(buf->buf, \"fetch \", &p)) {\n \t\t\tconst char *name;\n \t\t\tstruct ref *ref;\n-\t\t\tunsigned char old_sha1[20];\n+\t\t\tstruct object_id old_oid;\n+\t\t\tint hexlen;\n \n-\t\t\tif (strlen(p) < 40 || get_sha1_hex(p, old_sha1))\n+\t\t\tif (!(hexlen = parse_oid_hex(p, -1, &old_oid)))\n \t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n-\t\t\tif (p[40] == ' ')\n-\t\t\t\tname = p + 41;\n-\t\t\telse if (!p[40])\n+\t\t\tif (p[hexlen] == ' ')\n+\t\t\t\tname = p + hexlen + 1;\n+\t\t\telse if (!p[hexlen])\n \t\t\t\tname = \"\";\n \t\t\telse\n \t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n \n \t\t\tref = alloc_ref(name);\n-\t\t\thashcpy(ref->old_oid.hash, old_sha1);\n+\t\t\toidcpy(&ref->old_oid, &old_oid);\n \n \t\t\t*list = ref;\n \t\t\tlist = &ref->next;\n-- \n2.4.0\n"},{"id":"263372","messageId":"1433867316-663554-8-git-send-email-sandals@crustytoothpaste.net","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 7/8] ref_newer: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-09T16:28:35Z","receivedAt":"2015-06-09T16:28:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert ref_newer and its caller to use struct object_id instead of\nunsigned char *.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/remote.c | 2 +-\n http-push.c      | 4 ++--\n remote.c         | 8 ++++----\n remote.h         | 2 +-\n 4 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex fa4d04c..0efc388 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -411,7 +411,7 @@ static int get_push_ref_states(const struct ref *remote_refs,\n \t\telse if (is_null_oid(&ref->old_oid))\n \t\t\tinfo->status = PUSH_STATUS_CREATE;\n \t\telse if (has_object_file(&ref->old_oid) &&\n-\t\t\t ref_newer(ref->new_oid.hash, ref->old_oid.hash))\n+\t\t\t ref_newer(&ref->new_oid, &ref->old_oid))\n \t\t\tinfo->status = PUSH_STATUS_FASTFORWARD;\n \t\telse\n \t\t\tinfo->status = PUSH_STATUS_OUTOFDATE;\ndiff --git a/http-push.c b/http-push.c\nindex d054fdb..0e688a7 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1899,8 +1899,8 @@ int main(int argc, char **argv)\n \t\t    !is_null_oid(&ref->old_oid) &&\n \t\t    !ref->force) {\n \t\t\tif (!has_object_file(&ref->old_oid) ||\n-\t\t\t    !ref_newer(ref->peer_ref->new_oid.hash,\n-\t\t\t\t       ref->old_oid.hash)) {\n+\t\t\t    !ref_newer(&ref->peer_ref->new_oid,\n+\t\t\t\t       &ref->old_oid)) {\n \t\t\t\t/*\n \t\t\t\t * We do not have the remote ref, or\n \t\t\t\t * we know that the remote ref is not\ndiff --git a/remote.c b/remote.c\nindex 706d2fb..675cb23 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1626,7 +1626,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,\n \t\t\telse if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) ||\n \t\t\t\t !lookup_commit_reference_gently(ref->new_oid.hash, 1))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NEEDS_FORCE;\n-\t\t\telse if (!ref_newer(ref->new_oid.hash, ref->old_oid.hash))\n+\t\t\telse if (!ref_newer(&ref->new_oid, &ref->old_oid))\n \t\t\t\treject_reason = REF_STATUS_REJECT_NONFASTFORWARD;\n \t\t}\n \n@@ -1982,7 +1982,7 @@ static void unmark_and_free(struct commit_list *list, unsigned int mark)\n \t}\n }\n \n-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)\n+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)\n {\n \tstruct object *o;\n \tstruct commit *old, *new;\n@@ -1993,12 +1993,12 @@ int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)\n \t * Both new and old must be commit-ish and new is descendant of\n \t * old.  Otherwise we require --force.\n \t */\n-\to = deref_tag(parse_object(old_sha1), NULL, 0);\n+\to = deref_tag(parse_object(old_oid->hash), NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \told = (struct commit *) o;\n \n-\to = deref_tag(parse_object(new_sha1), NULL, 0);\n+\to = deref_tag(parse_object(new_oid->hash), NULL, 0);\n \tif (!o || o->type != OBJ_COMMIT)\n \t\treturn 0;\n \tnew = (struct commit *) o;\ndiff --git a/remote.h b/remote.h\nindex 163ea5e..4a039ba 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -150,7 +150,7 @@ extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,\n \t\t\t\t     struct sha1_array *shallow);\n \n int resolve_remote_symref(struct ref *ref, struct ref *list);\n-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);\n+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);\n \n /*\n  * Remove and free all but the first of any entries in the input list\n-- \n2.4.0\n"},{"id":"263457","messageId":"CACsJy8DHJ415euwo3gMTtuQx+5RopzBg+mssZ8TVstGJcdWSqg@mail.gmail.com","threadId":"39573","inReplyTo":"1433867316-663554-3-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH 2/8] sha1_file: introduce has_object_file helper.","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-06-10T09:59:58Z","receivedAt":"2015-06-10T09:59:58Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Jun 9, 2015 at 11:28 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> diff --git a/sha1_file.c b/sha1_file.c\n> index 7e38148..09f7f03 100644\n> --- a/sha1_file.c\n> +++ b/sha1_file.c\n> @@ -3173,6 +3173,11 @@ int has_sha1_file(const unsigned char *sha1)\n>         return find_pack_entry(sha1, &e);\n>  }\n>\n> +int has_object_file(const struct object_id *oid)\n> +{\n> +       return has_sha1_file(oid->hash);\n> +}\n> +\n\nThis version could be \"static inline\" and placed in cache.h. Though it\nmay be premature optimization. On top of my head I can't recall any\nplace where has_sha1_file() is used so many times for this extra call\nto become significant overhead.\n-- \nDuy\n"},{"id":"263464","messageId":"20150610135555.GD664685@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"CACsJy8DHJ415euwo3gMTtuQx+5RopzBg+mssZ8TVstGJcdWSqg@mail.gmail.com","subject":"Re: [PATCH 2/8] sha1_file: introduce has_object_file helper.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-10T13:55:55Z","receivedAt":"2015-06-10T13:55:55Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Jun 10, 2015 at 04:59:58PM +0700, Duy Nguyen wrote:\n> On Tue, Jun 9, 2015 at 11:28 PM, brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > diff --git a/sha1_file.c b/sha1_file.c\n> > index 7e38148..09f7f03 100644\n> > --- a/sha1_file.c\n> > +++ b/sha1_file.c\n> > @@ -3173,6 +3173,11 @@ int has_sha1_file(const unsigned char *sha1)\n> >         return find_pack_entry(sha1, &e);\n> >  }\n> >\n> > +int has_object_file(const struct object_id *oid)\n> > +{\n> > +       return has_sha1_file(oid->hash);\n> > +}\n> > +\n> \n> This version could be \"static inline\" and placed in cache.h. Though it\n> may be premature optimization. On top of my head I can't recall any\n> place where has_sha1_file() is used so many times for this extra call\n> to become significant overhead.\n\nI planned on merging the two into has_object_file when has_sha1_file has\nno more callers, so it's more of an incidental artifact that one calls\nthe other rather than a long-term goal.  In the branch I'm working on\nnow, I'm down to 27 callers, so it may be rather soon that it goes away.\n\nOf course, if the consensus is that the performance increase is worth it\nin the mean time, I can certainly just move it back when they merge.\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"},{"id":"263541","messageId":"xmqq381zi3ev.fsf@gitster.dls.corp.google.com","threadId":"39573","inReplyTo":"1433867316-663554-1-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-10T22:50:32Z","receivedAt":"2015-06-10T22:50:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> The final piece in this series is the conversion of struct object to use\n> struct object_id.  This is a necessarily large patch because of the\n> large number of places this code is used.\n>\n> brian m. carlson (8):\n>   refs: convert some internal functions to use object_id\n>   sha1_file: introduce has_object_file helper.\n>   Convert struct ref to use object_id.\n>   Add a utility function to make parsing hex values easier.\n>   add_sought_entry_mem: convert to struct object_id\n>   parse_fetch: convert to use struct object_id\n>   ref_newer: convert to use struct object_id\n>   Convert struct object to object_id\n\nIt seems that the last one didn't make it...\n"},{"id":"263545","messageId":"20150610235114.GA786544@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"xmqq381zi3ev.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-10T23:51:14Z","receivedAt":"2015-06-10T23:51:14Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> >   Convert struct object to object_id\n> \n> It seems that the last one didn't make it...\n\nIt appears the mail was too large for vger.  Unfortunately for\nbisectability reasons, it is necessarily large.  I'll resubmit the patch\nwith less context.\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"},{"id":"263546","messageId":"20150611000251.GB786544@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"20150610235114.GA786544@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-11T00:02:52Z","receivedAt":"2015-06-11T00:02:52Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:\n> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:\n> > \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> > >   Convert struct object to object_id\n> > \n> > It seems that the last one didn't make it...\n> \n> It appears the mail was too large for vger.  Unfortunately for\n> bisectability reasons, it is necessarily large.  I'll resubmit the patch\n> with less context.\n\nUnfortunately, the only patch I can generate that falls under to 100 KB\nlimit is with -U0, which isn't very useful.  How do you want to proceed?\nThe branch is available at [0], or I can send the -U0 patch, or I can\nsplit it into unbisectable pieces.\n\n[0] https://github.com/bk2204/git.git object-id-part2\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"},{"id":"263547","messageId":"xmqqpp53gkmq.fsf@gitster.dls.corp.google.com","threadId":"39573","inReplyTo":"20150611000251.GB786544@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-11T00:21:33Z","receivedAt":"2015-06-11T00:21:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:\n>> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:\n>> > \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n>> > >   Convert struct object to object_id\n>> > \n>> > It seems that the last one didn't make it...\n>> \n>> It appears the mail was too large for vger.  Unfortunately for\n>> bisectability reasons, it is necessarily large.  I'll resubmit the patch\n>> with less context.\n>\n> Unfortunately, the only patch I can generate that falls under to 100 KB\n> limit is with -U0, which isn't very useful.  How do you want to proceed?\n> The branch is available at [0], or I can send the -U0 patch, or I can\n> split it into unbisectable pieces.\n>\n> [0] https://github.com/bk2204/git.git object-id-part2\n\nNo approach other than just letting reviewers fetch from there and\ntaking a look is reasonable, I would think.\n\nDid you create this manually, or is it a mechanical scripted rewrite\nfollowed by manual clean-up?  If the latter, it may help people by\nposting the mechanical recipe _and_ a patch that shows the manual\nclean-up.  That is something we can reasonably review and discuss.\n"},{"id":"263551","messageId":"20150611033107.GA789892@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"xmqqpp53gkmq.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-11T03:31:08Z","receivedAt":"2015-06-11T03:31:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Jun 10, 2015 at 05:21:33PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> > [0] https://github.com/bk2204/git.git object-id-part2\n> \n> No approach other than just letting reviewers fetch from there and\n> taking a look is reasonable, I would think.\n> \n> Did you create this manually, or is it a mechanical scripted rewrite\n> followed by manual clean-up?  If the latter, it may help people by\n> posting the mechanical recipe _and_ a patch that shows the manual\n> clean-up.  That is something we can reasonably review and discuss.\n\nIt's mostly manual, but some pieces (the is_null_sha1 and sha1_to_hex\nconversions) were scripted using the embedded Ruby interpreter in Vim.\nThe script I used to do that is below.\n\n  def refactor(s)\n    methods = %w(is_null_sha1 sha1_to_hex).map do |m|\n      [m, m.sub('sha1', 'oid')]\n    end.to_h\n    s.sub(/\\A(.*)(is_null_sha1|sha1_to_hex)\\(([^)]+)(\\.|->)sha1\\)(.*)\\z/) do\n      [$1, methods[$2], \"(&#{$3}#{$4}oid)\", $5].join('')\n    end\n  end\n  \n  def replace_line(method)\n    func = Object.method(method)\n    VIM::Buffer.current.line = func.call(VIM::Buffer.current.line)\n  end\n\nIt was invoked as replace_line(:refactor), so it basically modified each\nrelevant line by passing it through refactor.\n\nSorry for choosing a language that's less familiar to the list: if I had\nknown you'd want to see it, I would have used Perl.\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"},{"id":"263597","messageId":"5579AC1D.6000606@alum.mit.edu","threadId":"39573","inReplyTo":"1433867316-663554-4-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH 3/8] Convert struct ref to use object_id.","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2015-06-11T15:41:17Z","receivedAt":"2015-06-11T15:41:17Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"I visually inspected patches 1 and 2 without finding any problems.\n\nRegarding this patch, I saw a few functions where you could convert\nlocal variables to \"struct object_id\" and then change function calls\nlike hashcpy() to oidcpy(). See below. I'm not sure if it makes sense to\ndo that in this same patch.\n\nFor that matter, it seems to me that it should be possible to change\n*all* local\n\n    unsigned char $variable[20];\n\nto\n\n    struct object_id $variable;\n\nwithout having to change any external interfaces. I wonder whether it\nwould be advisable to make that change early in this transition? It\nwould have the advantage that during later refactorings, where, e.g., a\nfunction needs a \"struct object_id *\" parameter, you would often already\nhave one handy.\n\nMichael\n\nOn 06/09/2015 06:28 PM, brian m. carlson wrote:\n> Use struct object_id in three fields in struct ref and convert all the\n> necessary places that use it.\n> \n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  builtin/clone.c        | 16 +++++++-------\n>  builtin/fetch-pack.c   |  4 ++--\n>  builtin/fetch.c        | 50 +++++++++++++++++++++----------------------\n>  builtin/ls-remote.c    |  2 +-\n>  builtin/receive-pack.c |  2 +-\n>  builtin/remote.c       | 12 +++++------\n>  connect.c              |  2 +-\n>  fetch-pack.c           | 18 ++++++++--------\n>  http-push.c            | 46 +++++++++++++++++++--------------------\n>  http.c                 |  2 +-\n>  remote-curl.c          | 10 ++++-----\n>  remote.c               | 58 +++++++++++++++++++++++++-------------------------\n>  remote.h               |  6 +++---\n>  send-pack.c            | 16 +++++++-------\n>  transport-helper.c     | 18 ++++++++--------\n>  transport.c            | 32 ++++++++++++++--------------\n>  transport.h            |  8 +++----\n>  walker.c               |  2 +-\n>  18 files changed, 152 insertions(+), 152 deletions(-)\n> \n> [...]\n> diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\n> index 4a6b340..19215b3 100644\n> --- a/builtin/fetch-pack.c\n> +++ b/builtin/fetch-pack.c\n> @@ -17,7 +17,7 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,\n>  \tunsigned char sha1[20];\n>  \n>  \tif (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {\n> -\t\thashcpy(ref->old_sha1, sha1);\n> +\t\thashcpy(ref->old_oid.hash, sha1);\n>  \t\tname += 41;\n>  \t\tnamelen -= 41;\n>  \t}\n\nVariable \"sha1\" in this function could become \"struct object_id\".\n\n> [...]\n> diff --git a/connect.c b/connect.c\n> index c0144d8..f8b10eb 100644\n> --- a/connect.c\n> +++ b/connect.c\n> @@ -165,7 +165,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,\n>  \t\tif (!check_ref(name, flags))\n>  \t\t\tcontinue;\n>  \t\tref = alloc_ref(buffer + 41);\n> -\t\thashcpy(ref->old_sha1, old_sha1);\n> +\t\thashcpy(ref->old_oid.hash, old_sha1);\n>  \t\t*list = ref;\n>  \t\tlist = &ref->next;\n>  \t\tgot_at_least_one_head = 1;\n\nold_sha1 in this function could become \"struct object_id\". Also, this\nfunction has a few \"20\" and \"41\" and \"42\" hard-coded literals.\n\n> [...]\n> diff --git a/remote-curl.c b/remote-curl.c\n> index af7b678..80cb4c7 100644\n> --- a/remote-curl.c\n> +++ b/remote-curl.c\n> [...]\n> @@ -814,7 +814,7 @@ static void parse_fetch(struct strbuf *buf)\n>  \t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n>  \n>  \t\t\tref = alloc_ref(name);\n> -\t\t\thashcpy(ref->old_sha1, old_sha1);\n> +\t\t\thashcpy(ref->old_oid.hash, old_sha1);\n>  \n>  \t\t\t*list = ref;\n>  \t\t\tlist = &ref->next;\n\nold_sha1 in this code block could be converted to \"struct object_id\".\n\n> diff --git a/remote.c b/remote.c\n> index 26504b7..706d2fb 100644\n> --- a/remote.c\n> +++ b/remote.c\n> [...]\n> @@ -1131,7 +1131,7 @@ static int try_explicit_object_name(const char *name,\n>  \n>  \tif (match) {\n>  \t\t*match = alloc_ref(name);\n> -\t\thashcpy((*match)->new_sha1, sha1);\n> +\t\thashcpy((*match)->new_oid.hash, sha1);\n>  \t}\n>  \treturn 0;\n>  }\n\nThe \"sha1\" variable in this function could become a \"struct object_id\".\n\n> [...]\n> @@ -2181,7 +2181,7 @@ static int one_local_ref(const char *refname, const struct object_id *oid,\n>  \n>  \tlen = strlen(refname) + 1;\n>  \tref = xcalloc(1, sizeof(*ref) + len);\n> -\thashcpy(ref->new_sha1, oid->hash);\n> +\thashcpy(ref->new_oid.hash, oid->hash);\n\nThis could become oidcopy().\n\n>  \tmemcpy(ref->name, refname, len);\n>  \t**local_tail = ref;\n>  \t*local_tail = &ref->next;\n> [...]\n> diff --git a/transport-helper.c b/transport-helper.c\n> index 5d99a6b..4ca3e80 100644\n> --- a/transport-helper.c\n> +++ b/transport-helper.c\n> [...]\n> @@ -883,7 +883,7 @@ static int push_refs_with_export(struct transport *transport,\n>  \t\tif (private && !get_sha1(private, sha1)) {\n>  \t\t\tstrbuf_addf(&buf, \"^%s\", private);\n>  \t\t\tstring_list_append(&revlist_args, strbuf_detach(&buf, NULL));\n> -\t\t\thashcpy(ref->old_sha1, sha1);\n> +\t\t\thashcpy(ref->old_oid.hash, sha1);\n>  \t\t}\n>  \t\tfree(private);\n>  \n\nsha1 in this function could become \"struct object_id\".\n\n> [...]\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"263601","messageId":"5579B2B3.8030805@alum.mit.edu","threadId":"39573","inReplyTo":"1433867316-663554-5-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH 4/8] Add a utility function to make parsing hex values easier.","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2015-06-11T16:09:23Z","receivedAt":"2015-06-11T16:09:23Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 06/09/2015 06:28 PM, brian m. carlson wrote:\n> get_oid_hex is already available for parsing hex object IDs into struct\n> object_id, but parsing code still must hard-code the number of bytes\n> read.  Introduce parse_oid_hex, which accepts an optional length, and\n> also returns the number of bytes parsed on success, or 0 on failure.\n> This makes it easier for code not to assume fixed values when parsing,\n> and to move to larger hash functions in the future.\n\nI have an open mind, but I have the feeling that this will not be a very\nhandy interface:\n\n* It will usually require a new int variable to catch the return value.\n\n* We don't put assignments within conditional expressions. So often this\nwill require one line of code to call the function and a second one to\ntest the return value.\n\nFor example, consider how awkward it will be to rewrite code that now\nlooks like\n\n    if (hex && !get_sha1_hex(hex, sha1) && hex[40] == '\\n')\n\n\nYou might instead consider the style of interface used by skip_prefix(),\nwhich I've really come to like:\n\nint parse_oid_hex(const char *hex, struct object_id *oid,\n                  const char **out)\n{\n\tif (get_sha1_hex(hex, oid->hash))\n\t\treturn -1; /* failure */\n\n\tif (out)\n\t\t*out = hex + GIT_SHA1_HEXSZ;\n\treturn 0;\n}\n\nThis function could of course take a \"len\" parameter too. Note that it\nuses our usual convention that success is denoted by returning 0.\n\nWith this definition, the above code could be rewritten to (if the old\nvalue of hex is not needed again)\n\n    if (hex && !parse_oid_hex(hex, &oid, &hex) && *hex == '\\n')\n\n> ---\n>  cache.h | 9 +++++++++\n>  hex.c   | 7 +++++++\n>  2 files changed, 16 insertions(+)\n> \n> diff --git a/cache.h b/cache.h\n> index fa1f067..f3b829f 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1012,6 +1012,15 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\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> +/*\n> + * Like get_oid_hex, but accepts an optional length argument, which may be -1\n> + * if the string is terminated by a non-hex character.  As with get_oid_hex,\n> + * reading stops if a NUL is encountered.  Returns the number of characters\n> + * read (40) on success and 0 on failure.  This is designed to be easier to\n> + * use for parsing data than get_oid_hex.\n> + */\n> +extern int parse_oid_hex(const char *hex, int len, struct object_id *oid);\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> diff --git a/hex.c b/hex.c\n> index 899b74a..ba196d7 100644\n> --- a/hex.c\n> +++ b/hex.c\n> @@ -61,6 +61,13 @@ int get_oid_hex(const char *hex, struct object_id *oid)\n>  \treturn get_sha1_hex(hex, oid->hash);\n>  }\n>  \n> +int parse_oid_hex(const char *hex, int len, struct object_id *oid)\n> +{\n> +\tif (len != -1 && len < GIT_SHA1_HEXSZ)\n> +\t\treturn 0;\n> +\treturn get_sha1_hex(hex, oid->hash) ? GIT_SHA1_HEXSZ : 0;\n> +}\n> +\n\nIsn't this return-statement logic backwards? get_sha1_hex() returns 0 on\nsuccess, which you would want to convert to 40. This function would want\nto return 0 on *error*.\n\nWhich is another disadvantage of this style. All the code that called\nget_sha1_hex() had to treat 0 as success. With your function they would\nhave to be inverted to treat 0 as failure. I think this would cause\nconfusion.\n\n> [...]\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"263636","messageId":"xmqq4mmef22j.fsf@gitster.dls.corp.google.com","threadId":"39573","inReplyTo":"xmqqpp53gkmq.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-11T20:00:04Z","receivedAt":"2015-06-11T20:00:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n>\n>> On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:\n>>> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:\n>>> > \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n>>> > >   Convert struct object to object_id\n>>> > \n>>> > It seems that the last one didn't make it...\n>>> \n>>> It appears the mail was too large for vger.  Unfortunately for\n>>> bisectability reasons, it is necessarily large.  I'll resubmit the patch\n>>> with less context.\n>>\n>> Unfortunately, the only patch I can generate that falls under to 100 KB\n>> limit is with -U0, which isn't very useful.  How do you want to proceed?\n>> The branch is available at [0], or I can send the -U0 patch, or I can\n>> split it into unbisectable pieces.\n>>\n>> [0] https://github.com/bk2204/git.git object-id-part2\n>\n> No approach other than just letting reviewers fetch from there and\n> taking a look is reasonable, I would think.\n\nFetched that branch, built and found out that it does not pass the\ntests, at least these (there may be others I do not usually run that\nare broken by this series; I dunno), so I'll discard what I fetched\nfor now X-<.\n\nTest Summary Report\n-------------------\nt5540-http-push-webdav.sh  (Wstat: 256 Tests: 19 Failed: 12)\n  Failed tests:  4-10, 12-15, 17\n  Non-zero exit status: 1\nt5539-fetch-http-shallow.sh (Wstat: 256 Tests: 3 Failed: 2)\n  Failed tests:  2-3\n  Non-zero exit status: 1\nt5541-http-push-smart.sh   (Wstat: 256 Tests: 34 Failed: 27)\n  Failed tests:  3-17, 22-29, 31-34\n  Non-zero exit status: 1\nt5551-http-fetch-smart.sh  (Wstat: 256 Tests: 26 Failed: 17)\n  Failed tests:  4-14, 16, 19-20, 22, 24-25\n  Non-zero exit status: 1\nt5550-http-fetch-dumb.sh   (Wstat: 256 Tests: 29 Failed: 12)\n  Failed tests:  3, 7-16, 19\n  Non-zero exit status: 1\n"},{"id":"263695","messageId":"20150612203054.GA29305@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"xmqq4mmef22j.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-12T20:30:54Z","receivedAt":"2015-06-12T20:30:54Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Thu, Jun 11, 2015 at 01:00:04PM -0700, Junio C Hamano wrote:\n> Fetched that branch, built and found out that it does not pass the\n> tests, at least these (there may be others I do not usually run that\n> are broken by this series; I dunno), so I'll discard what I fetched\n> for now X-<.\n> \n> Test Summary Report\n> -------------------\n> t5540-http-push-webdav.sh  (Wstat: 256 Tests: 19 Failed: 12)\n>   Failed tests:  4-10, 12-15, 17\n>   Non-zero exit status: 1\n> t5539-fetch-http-shallow.sh (Wstat: 256 Tests: 3 Failed: 2)\n>   Failed tests:  2-3\n>   Non-zero exit status: 1\n> t5541-http-push-smart.sh   (Wstat: 256 Tests: 34 Failed: 27)\n>   Failed tests:  3-17, 22-29, 31-34\n>   Non-zero exit status: 1\n> t5551-http-fetch-smart.sh  (Wstat: 256 Tests: 26 Failed: 17)\n>   Failed tests:  4-14, 16, 19-20, 22, 24-25\n>   Non-zero exit status: 1\n> t5550-http-fetch-dumb.sh   (Wstat: 256 Tests: 29 Failed: 12)\n>   Failed tests:  3, 7-16, 19\n>   Non-zero exit status: 1\n\nWhile I did run the tests between each commit, I hadn't noticed they\nwere failing because I don't have Apache installed on my laptop, so they\nwere silently skipped.  I'll resubmit with that fixed.\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"},{"id":"263710","messageId":"xmqqvbesbmm6.fsf@gitster.dls.corp.google.com","threadId":"39573","inReplyTo":"20150612203054.GA29305@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T22:14:25Z","receivedAt":"2015-06-12T22:14:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> While I did run the tests between each commit, I hadn't noticed they\n> were failing because I don't have Apache installed on my laptop, so they\n> were silently skipped.  I'll resubmit with that fixed.\n\nIt is somewhat strange that _only_ http part had failures like this,\nand is unnerving, too, given that a few people seem to have given at\nleast a cursory read over the patches and didn't spot anything\nobviously wrong.\n\nWas that because there was a single manual botch, or was that merely\nthat other parts of the system do not have sufficient test coverage?\n"},{"id":"263714","messageId":"20150612222713.GD29305@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"xmqqvbesbmm6.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-12T22:27:13Z","receivedAt":"2015-06-12T22:27:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Fri, Jun 12, 2015 at 03:14:25PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > While I did run the tests between each commit, I hadn't noticed they\n> > were failing because I don't have Apache installed on my laptop, so they\n> > were silently skipped.  I'll resubmit with that fixed.\n> \n> It is somewhat strange that _only_ http part had failures like this,\n> and is unnerving, too, given that a few people seem to have given at\n> least a cursory read over the patches and didn't spot anything\n> obviously wrong.\n> \n> Was that because there was a single manual botch, or was that merely\n> that other parts of the system do not have sufficient test coverage?\n\nIt appears that I broke the change in \"parse_fetch: convert to use\nstruct object_id\" which modifies remote-curl.c, so I think it's a single\nmanual botch.  I'm going to rework that patch anyway since Michael said\nthat he didn't like the idea of parse_oid_hex as it stands, so it will\nend up being mostly moot.\n\nI mostly introduced it in an effort to avoid having to use\nGIT_SHA1_HEXSZ repeatedly throughout small blocks of code, but since we\ndon't use assignments in conditionals, it doesn't seem useful as it\ncurrently stands.\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"},{"id":"263720","messageId":"557BEDA9.30809@alum.mit.edu","threadId":"39573","inReplyTo":"20150612222713.GD29305@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2015-06-13T08:45:29Z","receivedAt":"2015-06-13T08:45:29Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nOn 06/13/2015 12:27 AM, brian m. carlson wrote:\n> On Fri, Jun 12, 2015 at 03:14:25PM -0700, Junio C Hamano wrote:\n>> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n>> \n>>> While I did run the tests between each commit, I hadn't noticed\n>>> they were failing because I don't have Apache installed on my\n>>> laptop, so they were silently skipped.  I'll resubmit with that\n>>> fixed.\n>> \n>> It is somewhat strange that _only_ http part had failures like\n>> this, and is unnerving, too, given that a few people seem to have\n>> given at least a cursory read over the patches and didn't spot\n>> anything obviously wrong.\n>> \n>> Was that because there was a single manual botch, or was that\n>> merely that other parts of the system do not have sufficient test\n>> coverage?\n> \n> It appears that I broke the change in \"parse_fetch: convert to use \n> struct object_id\" which modifies remote-curl.c, so I think it's a\n> single manual botch.  I'm going to rework that patch anyway since\n> Michael said that he didn't like the idea of parse_oid_hex as it\n> stands, so it will end up being mostly moot.\n\nIn the same email where I made those design suggestions, I also I\npointed out a bug in the implementation of parse_oid_hex(). Maybe that\nis the reason for the test failures.\n\nMichael\n\n- -- \nMichael Haggerty\nmhagger@alum.mit.edu\n\n\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v2\n\niEYEARECAAYFAlV77aYACgkQwg9mrRwfmAnCyQCeIp9aSOTtQ1ABpiSybcFQFP87\nfNwAoLNhQtyFQ2/fqQIvzl1gGEEOlWxa\n=gI7/\n-----END PGP SIGNATURE-----\n"},{"id":"263735","messageId":"20150613152859.GE29305@vauxhall.crustytoothpaste.net","threadId":"39573","inReplyTo":"557BEDA9.30809@alum.mit.edu","subject":"Re: [PATCH 0/8] object_id part 2","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-06-13T15:28:59Z","receivedAt":"2015-06-13T15:28:59Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sat, Jun 13, 2015 at 10:45:29AM +0200, Michael Haggerty wrote:\n> In the same email where I made those design suggestions, I also I\n> pointed out a bug in the implementation of parse_oid_hex(). Maybe that\n> is the reason for the test failures.\n\nIt probably is, although I either botched a conversion in the branch I'm\nworking on as well, or the area for that code is lacking tests, since I\ndon't think the tests are failing there.  In the latter case, I'll send\na testsuite patch as part of my next series.\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"}]}