All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/10] object_id part 2
@ 2015-06-13 22:16 brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 01/10] refs: convert some internal functions to use object_id brian m. carlson
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

This is another series of conversions to struct object_id.

This series converts more of the refs code and struct object to use
struct object_id.  It introduces an additional helper function,
has_object_file, which is the equivalent of has_sha1_file.  The name was
chosen to be slightly more logical than has_oid_file, although it can be
changed if desired.

The next-to-last patch in this series is the conversion of struct object
to use struct object_id.  This is a necessarily large patch because of
the large number of places this code is used.  That patch will most
likely be too large to make it through to the list, so this series is
available in the object-id-part2 branch from:

https://github.com/bk2204/git.git
https://git.crustytoothpaste.net/git/bmc/git.git

Changes from v1:
* Rebase on newer master.
* Drop parse_oid_hex.  It ended up not being very useful (only 4 uses
  over 47 patches) and a better version, like the one Michael Haggerty
  suggested, can be introduced later if it's beneficial.
* Fix the code that caused the httpd unit tests to fail.  This series
  passes the testsuite on each commit, including the httpd tests.
* Convert the remaining places touched by the first patch to use
  object_id.  These were split out into their own patches to keep
  patches to a reasonable size.  Some of these were in the original
  series, and some were not.
* Convert remote.c as well.  As part of the previous item, I went
  through remote.c and converted the places touched by the first patch,
  and realized that it was trivial to convert the rest of the file.
  This patch is at the end as we can get slightly better conversion by
  doing it after the conversion of struct object, meaning we can avoid
  making another pass later.  I blame Michael for the inspiration to do
  this. :-)

brian m. carlson (10):
  refs: convert some internal functions to use object_id
  sha1_file: introduce has_object_file helper.
  Convert struct ref to use object_id.
  add_sought_entry_mem: convert to struct object_id
  parse_fetch: convert to use struct object_id
  get_remote_heads: convert to struct object_id
  push_refs_with_export: convert to struct object_id
  ref_newer: convert to use struct object_id
  Convert struct object to object_id
  remote: convert functions to struct object_id

 archive.c                |   6 +--
 bisect.c                 |  10 ++--
 branch.c                 |   2 +-
 builtin/blame.c          |  46 +++++++++---------
 builtin/branch.c         |   2 +-
 builtin/checkout.c       |  24 +++++-----
 builtin/clone.c          |  18 +++----
 builtin/commit-tree.c    |   4 +-
 builtin/commit.c         |   8 ++--
 builtin/describe.c       |  20 ++++----
 builtin/diff-tree.c      |  12 ++---
 builtin/diff.c           |  12 ++---
 builtin/fast-export.c    |  34 +++++++-------
 builtin/fetch-pack.c     |  14 +++---
 builtin/fetch.c          |  54 ++++++++++-----------
 builtin/fmt-merge-msg.c  |   6 +--
 builtin/for-each-ref.c   |  12 ++---
 builtin/fsck.c           |  34 +++++++-------
 builtin/grep.c           |   6 +--
 builtin/index-pack.c     |  10 ++--
 builtin/log.c            |  24 +++++-----
 builtin/ls-remote.c      |   2 +-
 builtin/merge-base.c     |   8 ++--
 builtin/merge-tree.c     |   6 +--
 builtin/merge.c          |  60 ++++++++++++------------
 builtin/name-rev.c       |  12 ++---
 builtin/notes.c          |   2 +-
 builtin/pack-objects.c   |  16 +++----
 builtin/receive-pack.c   |   2 +-
 builtin/reflog.c         |   4 +-
 builtin/remote.c         |  12 ++---
 builtin/replace.c        |   2 +-
 builtin/reset.c          |   6 +--
 builtin/rev-list.c       |  18 +++----
 builtin/rev-parse.c      |   4 +-
 builtin/shortlog.c       |   2 +-
 builtin/show-branch.c    |   8 ++--
 builtin/tag.c            |   4 +-
 builtin/unpack-objects.c |  10 ++--
 bundle.c                 |  10 ++--
 cache-tree.c             |   2 +-
 cache.h                  |   3 ++
 combine-diff.c           |   4 +-
 commit.c                 |  32 ++++++-------
 connect.c                |  22 +++++----
 decorate.c               |   2 +-
 diff-lib.c               |   2 +-
 fetch-pack.c             |  24 +++++-----
 fsck.c                   |  10 ++--
 http-backend.c           |   2 +-
 http-push.c              |  88 +++++++++++++++++-----------------
 http.c                   |   2 +-
 line-log.c               |   6 +--
 list-objects.c           |   4 +-
 log-tree.c               |  32 ++++++-------
 merge-blobs.c            |   4 +-
 merge-recursive.c        |  22 ++++-----
 merge.c                  |   2 +-
 notes-merge.c            |  24 +++++-----
 object.c                 |   8 ++--
 object.h                 |   2 +-
 pack-bitmap-write.c      |  16 +++----
 pack-bitmap.c            |  34 +++++++-------
 patch-ids.c              |   6 +--
 pretty.c                 |  18 +++----
 refs.c                   | 106 ++++++++++++++++++++---------------------
 remote-curl.c            |  20 ++++----
 remote.c                 | 120 +++++++++++++++++++++++------------------------
 remote.h                 |   8 ++--
 revision.c               |  48 +++++++++----------
 send-pack.c              |  16 +++----
 sequencer.c              |  38 +++++++--------
 server-info.c            |   2 +-
 sha1_file.c              |   5 ++
 sha1_name.c              |  20 ++++----
 shallow.c                |   6 +--
 submodule.c              |   8 ++--
 tag.c                    |  10 ++--
 test-match-trees.c       |   2 +-
 transport-helper.c       |  24 +++++-----
 transport.c              |  32 ++++++-------
 transport.h              |   8 ++--
 tree.c                   |  10 ++--
 upload-pack.c            |  26 +++++-----
 walker.c                 |  18 +++----
 wt-status.c              |   2 +-
 86 files changed, 729 insertions(+), 717 deletions(-)

-- 
2.4.0

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 01/10] refs: convert some internal functions to use object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 02/10] sha1_file: introduce has_object_file helper brian m. carlson
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Convert several internal functions in refs.c to use struct object_id,
and use the GIT_SHA1_HEXSZ constants in parse_ref_line.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 refs.c | 104 ++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 52 insertions(+), 52 deletions(-)

diff --git a/refs.c b/refs.c
index 26d1ac1..2087012 100644
--- a/refs.c
+++ b/refs.c
@@ -1158,7 +1158,7 @@ static const char PACKED_REFS_HEADER[] =
  * Return a pointer to the refname within the line (null-terminated),
  * or NULL if there was a problem.
  */
-static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1)
+static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
 {
 	const char *ref;
 
@@ -1170,15 +1170,15 @@ static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1)
 	 *  +1 (space in between hex and name)
 	 *  +1 (newline at the end of the line)
 	 */
-	if (line->len <= 42)
+	if (line->len <= GIT_SHA1_HEXSZ + 2)
 		return NULL;
 
-	if (get_sha1_hex(line->buf, sha1) < 0)
+	if (get_oid_hex(line->buf, oid) < 0)
 		return NULL;
-	if (!isspace(line->buf[40]))
+	if (!isspace(line->buf[GIT_SHA1_HEXSZ]))
 		return NULL;
 
-	ref = line->buf + 41;
+	ref = line->buf + GIT_SHA1_HEXSZ + 1;
 	if (isspace(*ref))
 		return NULL;
 
@@ -1223,7 +1223,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
 	enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
 
 	while (strbuf_getwholeline(&line, f, '\n') != EOF) {
-		unsigned char sha1[20];
+		struct object_id oid;
 		const char *refname;
 		const char *traits;
 
@@ -1236,17 +1236,17 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
 			continue;
 		}
 
-		refname = parse_ref_line(&line, sha1);
+		refname = parse_ref_line(&line, &oid);
 		if (refname) {
 			int flag = REF_ISPACKED;
 
 			if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
 				if (!refname_is_safe(refname))
 					die("packed refname is dangerous: %s", refname);
-				hashclr(sha1);
+				oidclr(&oid);
 				flag |= REF_BAD_NAME | REF_ISBROKEN;
 			}
-			last = create_ref_entry(refname, sha1, flag, 0);
+			last = create_ref_entry(refname, oid.hash, flag, 0);
 			if (peeled == PEELED_FULLY ||
 			    (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
 				last->flag |= REF_KNOWS_PEELED;
@@ -1257,8 +1257,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
 		    line.buf[0] == '^' &&
 		    line.len == PEELED_LINE_LENGTH &&
 		    line.buf[PEELED_LINE_LENGTH - 1] == '\n' &&
-		    !get_sha1_hex(line.buf + 1, sha1)) {
-			hashcpy(last->u.value.peeled.hash, sha1);
+		    !get_oid_hex(line.buf + 1, &oid)) {
+			oidcpy(&last->u.value.peeled, &oid);
 			/*
 			 * Regardless of what the file header said,
 			 * we definitely know the value of *this*
@@ -1352,7 +1352,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
 	strbuf_add(&refname, dirname, dirnamelen);
 
 	while ((de = readdir(d)) != NULL) {
-		unsigned char sha1[20];
+		struct object_id oid;
 		struct stat st;
 		int flag;
 		const char *refdir;
@@ -1374,27 +1374,27 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
 							  refname.len, 1));
 		} else {
 			if (*refs->name) {
-				hashclr(sha1);
+				oidclr(&oid);
 				flag = 0;
-				if (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {
-					hashclr(sha1);
+				if (resolve_gitlink_ref(refs->name, refname.buf, oid.hash) < 0) {
+					oidclr(&oid);
 					flag |= REF_ISBROKEN;
 				}
 			} else if (read_ref_full(refname.buf,
 						 RESOLVE_REF_READING,
-						 sha1, &flag)) {
-				hashclr(sha1);
+						 oid.hash, &flag)) {
+				oidclr(&oid);
 				flag |= REF_ISBROKEN;
 			}
 			if (check_refname_format(refname.buf,
 						 REFNAME_ALLOW_ONELEVEL)) {
 				if (!refname_is_safe(refname.buf))
 					die("loose refname is dangerous: %s", refname.buf);
-				hashclr(sha1);
+				oidclr(&oid);
 				flag |= REF_BAD_NAME | REF_ISBROKEN;
 			}
 			add_entry_to_dir(dir,
-					 create_ref_entry(refname.buf, sha1, flag, 0));
+					 create_ref_entry(refname.buf, oid.hash, flag, 0));
 		}
 		strbuf_setlen(&refname, dirnamelen);
 	}
@@ -1752,8 +1752,8 @@ int read_ref(const char *refname, unsigned char *sha1)
 
 int ref_exists(const char *refname)
 {
-	unsigned char sha1[20];
-	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
+	struct object_id oid;
+	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, oid.hash, NULL);
 }
 
 static int filter_refs(const char *refname, const struct object_id *oid,
@@ -1857,7 +1857,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)
 int peel_ref(const char *refname, unsigned char *sha1)
 {
 	int flag;
-	unsigned char base[20];
+	struct object_id base;
 
 	if (current_ref && (current_ref->name == refname
 			    || !strcmp(current_ref->name, refname))) {
@@ -1867,7 +1867,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
 		return 0;
 	}
 
-	if (read_ref_full(refname, RESOLVE_REF_READING, base, &flag))
+	if (read_ref_full(refname, RESOLVE_REF_READING, base.hash, &flag))
 		return -1;
 
 	/*
@@ -1888,7 +1888,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
 		}
 	}
 
-	return peel_object(base, sha1);
+	return peel_object(base.hash, sha1);
 }
 
 struct warn_if_dangling_data {
@@ -2300,11 +2300,11 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
 	*ref = NULL;
 	for (p = ref_rev_parse_rules; *p; p++) {
 		char fullref[PATH_MAX];
-		unsigned char sha1_from_ref[20];
+		struct object_id oid_from_ref;
 		unsigned char *this_result;
 		int flag;
 
-		this_result = refs_found ? sha1_from_ref : sha1;
+		this_result = refs_found ? oid_from_ref.hash : sha1;
 		mksnpath(fullref, sizeof(fullref), *p, len, str);
 		r = resolve_ref_unsafe(fullref, RESOLVE_REF_READING,
 				       this_result, &flag);
@@ -2331,13 +2331,13 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 
 	*log = NULL;
 	for (p = ref_rev_parse_rules; *p; p++) {
-		unsigned char hash[20];
+		struct object_id oid;
 		char path[PATH_MAX];
 		const char *ref, *it;
 
 		mksnpath(path, sizeof(path), *p, len, str);
 		ref = resolve_ref_unsafe(path, RESOLVE_REF_READING,
-					 hash, NULL);
+					 oid.hash, NULL);
 		if (!ref)
 			continue;
 		if (reflog_exists(path))
@@ -2348,7 +2348,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 			continue;
 		if (!logs_found++) {
 			*log = xstrdup(it);
-			hashcpy(sha1, hash);
+			hashcpy(sha1, oid.hash);
 		}
 		if (!warn_ambiguous_refs)
 			break;
@@ -2491,12 +2491,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
  * Write an entry to the packed-refs file for the specified refname.
  * If peeled is non-NULL, write it as the entry's peeled value.
  */
-static void write_packed_entry(FILE *fh, char *refname, unsigned char *sha1,
-			       unsigned char *peeled)
+static void write_packed_entry(FILE *fh, char *refname, struct object_id *oid,
+			       struct object_id *peeled)
 {
-	fprintf_or_die(fh, "%s %s\n", sha1_to_hex(sha1), refname);
+	fprintf_or_die(fh, "%s %s\n", oid_to_hex(oid), refname);
 	if (peeled)
-		fprintf_or_die(fh, "^%s\n", sha1_to_hex(peeled));
+		fprintf_or_die(fh, "^%s\n", oid_to_hex(peeled));
 }
 
 /*
@@ -2509,9 +2509,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
 	if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)
 		error("internal error: %s is not a valid packed reference!",
 		      entry->name);
-	write_packed_entry(cb_data, entry->name, entry->u.value.oid.hash,
+	write_packed_entry(cb_data, entry->name, &entry->u.value.oid,
 			   peel_status == PEEL_PEELED ?
-			   entry->u.value.peeled.hash : NULL);
+			   &entry->u.value.peeled : NULL);
 	return 0;
 }
 
@@ -2901,7 +2901,7 @@ static int commit_ref_update(struct ref_lock *lock,
 
 int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
 {
-	unsigned char sha1[20], orig_sha1[20];
+	struct object_id oid, orig_oid;
 	int flag = 0, logmoved = 0;
 	struct ref_lock *lock;
 	struct stat loginfo;
@@ -2913,7 +2913,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 		return error("reflog for %s is a symlink", oldrefname);
 
 	symref = resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING,
-				    orig_sha1, &flag);
+				    orig_oid.hash, &flag);
 	if (flag & REF_ISSYMREF)
 		return error("refname %s is a symbolic ref, renaming it is not supported",
 			oldrefname);
@@ -2927,13 +2927,13 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 		return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
 			oldrefname, strerror(errno));
 
-	if (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {
+	if (delete_ref(oldrefname, orig_oid.hash, REF_NODEREF)) {
 		error("unable to delete old %s", oldrefname);
 		goto rollback;
 	}
 
-	if (!read_ref_full(newrefname, RESOLVE_REF_READING, sha1, NULL) &&
-	    delete_ref(newrefname, sha1, REF_NODEREF)) {
+	if (!read_ref_full(newrefname, RESOLVE_REF_READING, oid.hash, NULL) &&
+	    delete_ref(newrefname, oid.hash, REF_NODEREF)) {
 		if (errno==EISDIR) {
 			if (remove_empty_directories(git_path("%s", newrefname))) {
 				error("Directory not empty: %s", newrefname);
@@ -2956,10 +2956,10 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 		strbuf_release(&err);
 		goto rollback;
 	}
-	hashcpy(lock->old_oid.hash, orig_sha1);
+	oidcpy(&lock->old_oid, &orig_oid);
 
-	if (write_ref_to_lockfile(lock, orig_sha1) ||
-	    commit_ref_update(lock, orig_sha1, logmsg)) {
+	if (write_ref_to_lockfile(lock, orig_oid.hash) ||
+	    commit_ref_update(lock, orig_oid.hash, logmsg)) {
 		error("unable to write current sha1 into %s", newrefname);
 		goto rollback;
 	}
@@ -2976,8 +2976,8 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 
 	flag = log_all_ref_updates;
 	log_all_ref_updates = 0;
-	if (write_ref_to_lockfile(lock, orig_sha1) ||
-	    commit_ref_update(lock, orig_sha1, NULL))
+	if (write_ref_to_lockfile(lock, orig_oid.hash) ||
+	    commit_ref_update(lock, orig_oid.hash, NULL))
 		error("unable to write current sha1 into %s", oldrefname);
 	log_all_ref_updates = flag;
 
@@ -3230,11 +3230,11 @@ static int commit_ref_update(struct ref_lock *lock,
 		 * check with HEAD only which should cover 99% of all usage
 		 * scenarios (even 100% of the default ones).
 		 */
-		unsigned char head_sha1[20];
+		struct object_id head_oid;
 		int head_flag;
 		const char *head_ref;
 		head_ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
-					      head_sha1, &head_flag);
+					      head_oid.hash, &head_flag);
 		if (head_ref && (head_flag & REF_ISSYMREF) &&
 		    !strcmp(head_ref, lock->ref_name))
 			log_ref_write("HEAD", lock->old_oid.hash, sha1, logmsg);
@@ -3255,10 +3255,10 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
 	char ref[1000];
 	int fd, len, written;
 	char *git_HEAD = git_pathdup("%s", ref_target);
-	unsigned char old_sha1[20], new_sha1[20];
+	struct object_id old_oid, new_oid;
 
-	if (logmsg && read_ref(ref_target, old_sha1))
-		hashclr(old_sha1);
+	if (logmsg && read_ref(ref_target, old_oid.hash))
+		oidclr(&old_oid);
 
 	if (safe_create_leading_directories(git_HEAD) < 0)
 		return error("unable to create directory for %s", git_HEAD);
@@ -3304,8 +3304,8 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
 #ifndef NO_SYMLINK_HEAD
 	done:
 #endif
-	if (logmsg && !read_ref(refs_heads_master, new_sha1))
-		log_ref_write(ref_target, old_sha1, new_sha1, logmsg);
+	if (logmsg && !read_ref(refs_heads_master, new_oid.hash))
+		log_ref_write(ref_target, old_oid.hash, new_oid.hash, logmsg);
 
 	free(git_HEAD);
 	return 0;
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 02/10] sha1_file: introduce has_object_file helper.
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 01/10] refs: convert some internal functions to use object_id brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 03/10] Convert struct ref to use object_id brian m. carlson
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Add has_object_file, which is a wrapper around has_sha1_file, but for
struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 cache.h     | 3 +++
 sha1_file.c | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/cache.h b/cache.h
index 571c98f..fa1f067 100644
--- a/cache.h
+++ b/cache.h
@@ -946,6 +946,9 @@ extern int has_sha1_pack(const unsigned char *sha1);
  */
 extern int has_sha1_file(const unsigned char *sha1);
 
+/* Same as the above, except for struct object_id. */
+extern int has_object_file(const struct object_id *oid);
+
 /*
  * Return true iff an alternate object database has a loose object
  * with the specified name.  This function does not respect replace
diff --git a/sha1_file.c b/sha1_file.c
index 5038475..2bad0cd 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3180,6 +3180,11 @@ int has_sha1_file(const unsigned char *sha1)
 	return find_pack_entry(sha1, &e);
 }
 
+int has_object_file(const struct object_id *oid)
+{
+	return has_sha1_file(oid->hash);
+}
+
 static void check_tree(const void *buf, size_t size)
 {
 	struct tree_desc desc;
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 03/10] Convert struct ref to use object_id.
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 01/10] refs: convert some internal functions to use object_id brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 02/10] sha1_file: introduce has_object_file helper brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-15 22:13   ` Junio C Hamano
  2015-06-13 22:16 ` [PATCH v2 04/10] add_sought_entry_mem: convert to struct object_id brian m. carlson
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Use struct object_id in three fields in struct ref and convert all the
necessary places that use it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/clone.c        | 16 +++++++-------
 builtin/fetch-pack.c   |  4 ++--
 builtin/fetch.c        | 50 +++++++++++++++++++++----------------------
 builtin/ls-remote.c    |  2 +-
 builtin/receive-pack.c |  2 +-
 builtin/remote.c       | 12 +++++------
 connect.c              |  2 +-
 fetch-pack.c           | 18 ++++++++--------
 http-push.c            | 46 +++++++++++++++++++--------------------
 http.c                 |  2 +-
 remote-curl.c          | 10 ++++-----
 remote.c               | 58 +++++++++++++++++++++++++-------------------------
 remote.h               |  6 +++---
 send-pack.c            | 16 +++++++-------
 transport-helper.c     | 18 ++++++++--------
 transport.c            | 32 ++++++++++++++--------------
 transport.h            |  8 +++----
 walker.c               |  2 +-
 18 files changed, 152 insertions(+), 152 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 00535d0..d164712 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -496,7 +496,7 @@ static void write_remote_refs(const struct ref *local_refs)
 	for (r = local_refs; r; r = r->next) {
 		if (!r->peer_ref)
 			continue;
-		add_packed_ref(r->peer_ref->name, r->old_sha1);
+		add_packed_ref(r->peer_ref->name, r->old_oid.hash);
 	}
 
 	if (commit_packed_refs())
@@ -511,9 +511,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
 			continue;
 		if (ends_with(ref->name, "^{}"))
 			continue;
-		if (!has_sha1_file(ref->old_sha1))
+		if (!has_object_file(&ref->old_oid))
 			continue;
-		update_ref(msg, ref->name, ref->old_sha1,
+		update_ref(msg, ref->name, ref->old_oid.hash,
 			   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 	}
 }
@@ -533,7 +533,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
 	if (!ref)
 		return -1;
 
-	hashcpy(sha1, ref->old_sha1);
+	hashcpy(sha1, ref->old_oid.hash);
 	*rm = ref->next;
 	return 0;
 }
@@ -582,12 +582,12 @@ static void update_head(const struct ref *our, const struct ref *remote,
 		/* Local default branch link */
 		create_symref("HEAD", our->name, NULL);
 		if (!option_bare) {
-			update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
+			update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
 				   UPDATE_REFS_DIE_ON_ERR);
 			install_branch_config(0, head, option_origin, our->name);
 		}
 	} else if (our) {
-		struct commit *c = lookup_commit_reference(our->old_sha1);
+		struct commit *c = lookup_commit_reference(our->old_oid.hash);
 		/* --branch specifies a non-branch (i.e. tags), detach HEAD */
 		update_ref(msg, "HEAD", c->object.sha1,
 			   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
@@ -597,7 +597,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
 		 * HEAD points to a branch but we don't know which one.
 		 * Detach HEAD in all these cases.
 		 */
-		update_ref(msg, "HEAD", remote->old_sha1,
+		update_ref(msg, "HEAD", remote->old_oid.hash,
 			   NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
 	}
 }
@@ -948,7 +948,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		 * remote HEAD check.
 		 */
 		for (ref = refs; ref; ref = ref->next)
-			if (is_null_sha1(ref->old_sha1)) {
+			if (is_null_oid(&ref->old_oid)) {
 				complete_refs_before_fetch = 0;
 				break;
 			}
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 4a6b340..19215b3 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -17,7 +17,7 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
 	unsigned char sha1[20];
 
 	if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
-		hashcpy(ref->old_sha1, sha1);
+		hashcpy(ref->old_oid.hash, sha1);
 		name += 41;
 		namelen -= 41;
 	}
@@ -210,7 +210,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 
 	while (ref) {
 		printf("%s %s\n",
-		       sha1_to_hex(ref->old_sha1), ref->name);
+		       oid_to_hex(&ref->old_oid), ref->name);
 		ref = ref->next;
 	}
 
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 8d5b2db..af42cde 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -195,7 +195,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
 {
 	struct ref *rm = *head;
 	while (rm) {
-		if (!hashcmp(rm->old_sha1, sha1))
+		if (!hashcmp(rm->old_oid.hash, sha1))
 			return 1;
 		rm = rm->next;
 	}
@@ -223,8 +223,8 @@ static void find_non_local_tags(struct transport *transport,
 		 * as one to ignore by setting util to NULL.
 		 */
 		if (ends_with(ref->name, "^{}")) {
-			if (item && !has_sha1_file(ref->old_sha1) &&
-			    !will_fetch(head, ref->old_sha1) &&
+			if (item && !has_object_file(&ref->old_oid) &&
+			    !will_fetch(head, ref->old_oid.hash) &&
 			    !has_sha1_file(item->util) &&
 			    !will_fetch(head, item->util))
 				item->util = NULL;
@@ -250,7 +250,7 @@ static void find_non_local_tags(struct transport *transport,
 			continue;
 
 		item = string_list_insert(&remote_refs, ref->name);
-		item->util = (void *)ref->old_sha1;
+		item->util = (void *)&ref->old_oid;
 	}
 	string_list_clear(&existing_refs, 1);
 
@@ -272,7 +272,7 @@ static void find_non_local_tags(struct transport *transport,
 		{
 			struct ref *rm = alloc_ref(item->string);
 			rm->peer_ref = alloc_ref(item->string);
-			hashcpy(rm->old_sha1, item->util);
+			oidcpy(&rm->old_oid, item->util);
 			**tail = rm;
 			*tail = &rm->next;
 		}
@@ -418,8 +418,8 @@ static int s_update_ref(const char *action,
 	transaction = ref_transaction_begin(&err);
 	if (!transaction ||
 	    ref_transaction_update(transaction, ref->name,
-				   ref->new_sha1,
-				   check_old ? ref->old_sha1 : NULL,
+				   ref->new_oid.hash,
+				   check_old ? ref->old_oid.hash : NULL,
 				   0, msg, &err))
 		goto fail;
 
@@ -452,11 +452,11 @@ static int update_local_ref(struct ref *ref,
 	struct branch *current_branch = branch_get(NULL);
 	const char *pretty_ref = prettify_refname(ref->name);
 
-	type = sha1_object_info(ref->new_sha1, NULL);
+	type = sha1_object_info(ref->new_oid.hash, NULL);
 	if (type < 0)
-		die(_("object %s not found"), sha1_to_hex(ref->new_sha1));
+		die(_("object %s not found"), oid_to_hex(&ref->new_oid));
 
-	if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
+	if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
 		if (verbosity > 0)
 			strbuf_addf(display, "= %-*s %-*s -> %s",
 				    TRANSPORT_SUMMARY(_("[up to date]")),
@@ -467,7 +467,7 @@ static int update_local_ref(struct ref *ref,
 	if (current_branch &&
 	    !strcmp(ref->name, current_branch->name) &&
 	    !(update_head_ok || is_bare_repository()) &&
-	    !is_null_sha1(ref->old_sha1)) {
+	    !is_null_oid(&ref->old_oid)) {
 		/*
 		 * If this is the head, and it's not okay to update
 		 * the head, and the old value of the head isn't empty...
@@ -479,7 +479,7 @@ static int update_local_ref(struct ref *ref,
 		return 1;
 	}
 
-	if (!is_null_sha1(ref->old_sha1) &&
+	if (!is_null_oid(&ref->old_oid) &&
 	    starts_with(ref->name, "refs/tags/")) {
 		int r;
 		r = s_update_ref("updating tag", ref, 0);
@@ -491,8 +491,8 @@ static int update_local_ref(struct ref *ref,
 		return r;
 	}
 
-	current = lookup_commit_reference_gently(ref->old_sha1, 1);
-	updated = lookup_commit_reference_gently(ref->new_sha1, 1);
+	current = lookup_commit_reference_gently(ref->old_oid.hash, 1);
+	updated = lookup_commit_reference_gently(ref->new_oid.hash, 1);
 	if (!current || !updated) {
 		const char *msg;
 		const char *what;
@@ -516,7 +516,7 @@ static int update_local_ref(struct ref *ref,
 
 		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 		    (recurse_submodules != RECURSE_SUBMODULES_ON))
-			check_for_new_submodule_commits(ref->new_sha1);
+			check_for_new_submodule_commits(ref->new_oid.hash);
 		r = s_update_ref(msg, ref, 0);
 		strbuf_addf(display, "%c %-*s %-*s -> %s%s",
 			    r ? '!' : '*',
@@ -531,10 +531,10 @@ static int update_local_ref(struct ref *ref,
 		int r;
 		strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
 		strcat(quickref, "..");
-		strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
+		strcat(quickref, find_unique_abbrev(ref->new_oid.hash, DEFAULT_ABBREV));
 		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 		    (recurse_submodules != RECURSE_SUBMODULES_ON))
-			check_for_new_submodule_commits(ref->new_sha1);
+			check_for_new_submodule_commits(ref->new_oid.hash);
 		r = s_update_ref("fast-forward", ref, 1);
 		strbuf_addf(display, "%c %-*s %-*s -> %s%s",
 			    r ? '!' : ' ',
@@ -547,10 +547,10 @@ static int update_local_ref(struct ref *ref,
 		int r;
 		strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
 		strcat(quickref, "...");
-		strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
+		strcat(quickref, find_unique_abbrev(ref->new_oid.hash, DEFAULT_ABBREV));
 		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 		    (recurse_submodules != RECURSE_SUBMODULES_ON))
-			check_for_new_submodule_commits(ref->new_sha1);
+			check_for_new_submodule_commits(ref->new_oid.hash);
 		r = s_update_ref("forced-update", ref, 1);
 		strbuf_addf(display, "%c %-*s %-*s -> %s  (%s)",
 			    r ? '!' : '+',
@@ -577,7 +577,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
 	if (!ref)
 		return -1; /* end of the list */
 	*rm = ref->next;
-	hashcpy(sha1, ref->old_sha1);
+	hashcpy(sha1, ref->old_oid.hash);
 	return 0;
 }
 
@@ -628,7 +628,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				continue;
 			}
 
-			commit = lookup_commit_reference_gently(rm->old_sha1, 1);
+			commit = lookup_commit_reference_gently(rm->old_oid.hash, 1);
 			if (!commit)
 				rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE;
 
@@ -638,8 +638,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 			if (rm->peer_ref) {
 				ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
 				strcpy(ref->name, rm->peer_ref->name);
-				hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
-				hashcpy(ref->new_sha1, rm->old_sha1);
+				oidcpy(&ref->old_oid, &rm->peer_ref->old_oid);
+				oidcpy(&ref->new_oid, &rm->old_oid);
 				ref->force = rm->peer_ref->force;
 			}
 
@@ -684,7 +684,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 				/* fall-through */
 			case FETCH_HEAD_MERGE:
 				fprintf(fp, "%s\t%s\t%s",
-					sha1_to_hex(rm->old_sha1),
+					oid_to_hex(&rm->old_oid),
 					merge_status_marker,
 					note.buf);
 				for (i = 0; i < url_len; ++i)
@@ -917,7 +917,7 @@ static int do_fetch(struct transport *transport,
 						   rm->peer_ref->name);
 			if (peer_item) {
 				struct object_id *old_oid = peer_item->util;
-				hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
+				oidcpy(&rm->peer_ref->old_oid, old_oid);
 			}
 		}
 	}
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 4554dbc..db35e58 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -129,7 +129,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 			continue;
 		if (!tail_match(pattern, ref->name))
 			continue;
-		printf("%s	%s\n", sha1_to_hex(ref->old_sha1), ref->name);
+		printf("%s	%s\n", oid_to_hex(&ref->old_oid), ref->name);
 		status = 0; /* we found something */
 	}
 	return status;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 94d0571..5941c78 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -222,7 +222,7 @@ static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
 static void collect_one_alternate_ref(const struct ref *ref, void *data)
 {
 	struct sha1_array *sa = data;
-	sha1_array_append(sa, ref->old_sha1);
+	sha1_array_append(sa, ref->old_oid.hash);
 }
 
 static void write_head_info(void)
diff --git a/builtin/remote.c b/builtin/remote.c
index f4a6ec9..fa4d04c 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -395,7 +395,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
 
 		if (!ref->peer_ref)
 			continue;
-		hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
+		oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
 
 		item = string_list_append(&states->push,
 					  abbrev_branch(ref->peer_ref->name));
@@ -404,14 +404,14 @@ static int get_push_ref_states(const struct ref *remote_refs,
 		info->forced = ref->force;
 		info->dest = xstrdup(abbrev_branch(ref->name));
 
-		if (is_null_sha1(ref->new_sha1)) {
+		if (is_null_oid(&ref->new_oid)) {
 			info->status = PUSH_STATUS_DELETE;
-		} else if (!hashcmp(ref->old_sha1, ref->new_sha1))
+		} else if (!oidcmp(&ref->old_oid, &ref->new_oid))
 			info->status = PUSH_STATUS_UPTODATE;
-		else if (is_null_sha1(ref->old_sha1))
+		else if (is_null_oid(&ref->old_oid))
 			info->status = PUSH_STATUS_CREATE;
-		else if (has_sha1_file(ref->old_sha1) &&
-			 ref_newer(ref->new_sha1, ref->old_sha1))
+		else if (has_object_file(&ref->old_oid) &&
+			 ref_newer(ref->new_oid.hash, ref->old_oid.hash))
 			info->status = PUSH_STATUS_FASTFORWARD;
 		else
 			info->status = PUSH_STATUS_OUTOFDATE;
diff --git a/connect.c b/connect.c
index c0144d8..f8b10eb 100644
--- a/connect.c
+++ b/connect.c
@@ -165,7 +165,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 		if (!check_ref(name, flags))
 			continue;
 		ref = alloc_ref(buffer + 41);
-		hashcpy(ref->old_sha1, old_sha1);
+		hashcpy(ref->old_oid.hash, old_sha1);
 		*list = ref;
 		list = &ref->next;
 		got_at_least_one_head = 1;
diff --git a/fetch-pack.c b/fetch-pack.c
index a912935..c02ea87 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -238,7 +238,7 @@ static void send_request(struct fetch_pack_args *args,
 
 static void insert_one_alternate_ref(const struct ref *ref, void *unused)
 {
-	rev_list_insert_ref(NULL, ref->old_sha1);
+	rev_list_insert_ref(NULL, ref->old_oid.hash);
 }
 
 #define INITIAL_FLUSH 16
@@ -280,7 +280,7 @@ static int find_common(struct fetch_pack_args *args,
 
 	fetching = 0;
 	for ( ; refs ; refs = refs->next) {
-		unsigned char *remote = refs->old_sha1;
+		unsigned char *remote = refs->old_oid.hash;
 		const char *remote_hex;
 		struct object *o;
 
@@ -570,7 +570,7 @@ static void filter_refs(struct fetch_pack_args *args,
 				continue;
 			if (get_sha1_hex(ref->name, sha1) ||
 			    ref->name[40] != '\0' ||
-			    hashcmp(sha1, ref->old_sha1))
+			    hashcmp(sha1, ref->old_oid.hash))
 				continue;
 
 			ref->matched = 1;
@@ -583,7 +583,7 @@ static void filter_refs(struct fetch_pack_args *args,
 
 static void mark_alternate_complete(const struct ref *ref, void *unused)
 {
-	mark_complete(ref->old_sha1);
+	mark_complete(ref->old_oid.hash);
 }
 
 static int everything_local(struct fetch_pack_args *args,
@@ -599,10 +599,10 @@ static int everything_local(struct fetch_pack_args *args,
 	for (ref = *refs; ref; ref = ref->next) {
 		struct object *o;
 
-		if (!has_sha1_file(ref->old_sha1))
+		if (!has_object_file(&ref->old_oid))
 			continue;
 
-		o = parse_object(ref->old_sha1);
+		o = parse_object(ref->old_oid.hash);
 		if (!o)
 			continue;
 
@@ -630,7 +630,7 @@ static int everything_local(struct fetch_pack_args *args,
 	 * Don't mark them common yet; the server has to be told so first.
 	 */
 	for (ref = *refs; ref; ref = ref->next) {
-		struct object *o = deref_tag(lookup_object(ref->old_sha1),
+		struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
 					     NULL, 0);
 
 		if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -646,7 +646,7 @@ static int everything_local(struct fetch_pack_args *args,
 	filter_refs(args, refs, sought, nr_sought);
 
 	for (retval = 1, ref = *refs; ref ; ref = ref->next) {
-		const unsigned char *remote = ref->old_sha1;
+		const unsigned char *remote = ref->old_oid.hash;
 		struct object *o;
 
 		o = lookup_object(remote);
@@ -987,7 +987,7 @@ static void update_shallow(struct fetch_pack_args *args,
 	if (!si->nr_ours && !si->nr_theirs)
 		return;
 	for (i = 0; i < nr_sought; i++)
-		sha1_array_append(&ref, sought[i]->old_sha1);
+		sha1_array_append(&ref, sought[i]->old_oid.hash);
 	si->ref = &ref;
 
 	if (args->update_shallow) {
diff --git a/http-push.c b/http-push.c
index c98dad2..d054fdb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1437,11 +1437,11 @@ static void one_remote_ref(const char *refname)
 	 * Fetch a copy of the object if it doesn't exist locally - it
 	 * may be required for updating server info later.
 	 */
-	if (repo->can_update_info_refs && !has_sha1_file(ref->old_sha1)) {
-		obj = lookup_unknown_object(ref->old_sha1);
+	if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {
+		obj = lookup_unknown_object(ref->old_oid.hash);
 		if (obj) {
 			fprintf(stderr,	"  fetch %s for %s\n",
-				sha1_to_hex(ref->old_sha1), refname);
+				oid_to_hex(&ref->old_oid), refname);
 			add_fetch_request(obj);
 		}
 	}
@@ -1474,11 +1474,11 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
 		return;
 	}
 
-	o = parse_object(ref->old_sha1);
+	o = parse_object(ref->old_oid.hash);
 	if (!o) {
 		fprintf(stderr,
 			"Unable to parse object %s for remote ref %s\n",
-			sha1_to_hex(ref->old_sha1), ls->dentry_name);
+			oid_to_hex(&ref->old_oid), ls->dentry_name);
 		aborted = 1;
 		free(ref);
 		return;
@@ -1487,7 +1487,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
 	len = strlen(ls->dentry_name) + 42;
 	ref_info = xcalloc(len + 1, 1);
 	sprintf(ref_info, "%s	%s\n",
-		sha1_to_hex(ref->old_sha1), ls->dentry_name);
+		oid_to_hex(&ref->old_oid), ls->dentry_name);
 	fwrite_buffer(ref_info, 1, len, buf);
 	free(ref_info);
 
@@ -1591,7 +1591,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
 static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
 {
 	struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
-	struct commit *branch = lookup_commit_or_die(remote->old_sha1, remote->name);
+	struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name);
 
 	return in_merge_bases(branch, head);
 }
@@ -1654,11 +1654,11 @@ static int delete_remote_branch(const char *pattern, int force)
 			return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1));
 
 		/* Remote branch must resolve to a known object */
-		if (is_null_sha1(remote_ref->old_sha1))
+		if (is_null_oid(&remote_ref->old_oid))
 			return error("Unable to resolve remote branch %s",
 				     remote_ref->name);
-		if (!has_sha1_file(remote_ref->old_sha1))
-			return 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));
+		if (!has_object_file(&remote_ref->old_oid))
+			return 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));
 
 		/* Remote branch must be an ancestor of remote HEAD */
 		if (!verify_merge_base(head_sha1, remote_ref)) {
@@ -1874,7 +1874,7 @@ int main(int argc, char **argv)
 		if (!ref->peer_ref)
 			continue;
 
-		if (is_null_sha1(ref->peer_ref->new_sha1)) {
+		if (is_null_oid(&ref->peer_ref->new_oid)) {
 			if (delete_remote_branch(ref->name, 1) == -1) {
 				error("Could not remove %s", ref->name);
 				if (helper_status)
@@ -1887,7 +1887,7 @@ int main(int argc, char **argv)
 			continue;
 		}
 
-		if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
+		if (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {
 			if (push_verbosely)
 				fprintf(stderr, "'%s': up-to-date\n", ref->name);
 			if (helper_status)
@@ -1896,11 +1896,11 @@ int main(int argc, char **argv)
 		}
 
 		if (!force_all &&
-		    !is_null_sha1(ref->old_sha1) &&
+		    !is_null_oid(&ref->old_oid) &&
 		    !ref->force) {
-			if (!has_sha1_file(ref->old_sha1) ||
-			    !ref_newer(ref->peer_ref->new_sha1,
-				       ref->old_sha1)) {
+			if (!has_object_file(&ref->old_oid) ||
+			    !ref_newer(ref->peer_ref->new_oid.hash,
+				       ref->old_oid.hash)) {
 				/*
 				 * We do not have the remote ref, or
 				 * we know that the remote ref is not
@@ -1921,10 +1921,10 @@ int main(int argc, char **argv)
 				continue;
 			}
 		}
-		hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
+		oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
 		new_refs++;
-		strcpy(old_hex, sha1_to_hex(ref->old_sha1));
-		new_hex = sha1_to_hex(ref->new_sha1);
+		strcpy(old_hex, oid_to_hex(&ref->old_oid));
+		new_hex = oid_to_hex(&ref->new_oid);
 
 		fprintf(stderr, "updating '%s'", ref->name);
 		if (strcmp(ref->name, ref->peer_ref->name))
@@ -1949,14 +1949,14 @@ int main(int argc, char **argv)
 
 		/* Set up revision info for this refspec */
 		commit_argc = 3;
-		new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));
+		new_sha1_hex = xstrdup(oid_to_hex(&ref->new_oid));
 		old_sha1_hex = NULL;
 		commit_argv[1] = "--objects";
 		commit_argv[2] = new_sha1_hex;
-		if (!push_all && !is_null_sha1(ref->old_sha1)) {
+		if (!push_all && !is_null_oid(&ref->old_oid)) {
 			old_sha1_hex = xmalloc(42);
 			sprintf(old_sha1_hex, "^%s",
-				sha1_to_hex(ref->old_sha1));
+				oid_to_hex(&ref->old_oid));
 			commit_argv[3] = old_sha1_hex;
 			commit_argc++;
 		}
@@ -1988,7 +1988,7 @@ int main(int argc, char **argv)
 		run_request_queue();
 
 		/* Update the remote branch if all went well */
-		if (aborted || !update_remote(ref->new_sha1, ref_lock))
+		if (aborted || !update_remote(ref->new_oid.hash, ref_lock))
 			rc = 1;
 
 		if (!rc)
diff --git a/http.c b/http.c
index f0c5bbc..96b7863 100644
--- a/http.c
+++ b/http.c
@@ -1338,7 +1338,7 @@ int http_fetch_ref(const char *base, struct ref *ref)
 	if (http_get_strbuf(url, &buffer, &options) == HTTP_OK) {
 		strbuf_rtrim(&buffer);
 		if (buffer.len == 40)
-			ret = get_sha1_hex(buffer.buf, ref->old_sha1);
+			ret = get_oid_hex(buffer.buf, &ref->old_oid);
 		else if (starts_with(buffer.buf, "ref: ")) {
 			ref->symref = xstrdup(buffer.buf + 5);
 			ret = 0;
diff --git a/remote-curl.c b/remote-curl.c
index af7b678..80cb4c7 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -168,7 +168,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
 				      strlen(ref_name) + 1);
 			memset(ref, 0, sizeof(struct ref));
 			strcpy(ref->name, ref_name);
-			get_sha1_hex(start, ref->old_sha1);
+			get_oid_hex(start, &ref->old_oid);
 			if (!refs)
 				refs = ref;
 			if (last_ref)
@@ -347,7 +347,7 @@ static void output_refs(struct ref *refs)
 		if (posn->symref)
 			printf("@%s %s\n", posn->symref, posn->name);
 		else
-			printf("%s %s\n", sha1_to_hex(posn->old_sha1), posn->name);
+			printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name);
 	}
 	printf("\n");
 	fflush(stdout);
@@ -701,7 +701,7 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
 	if (options.depth)
 		die("dumb http transport does not support --depth");
 	for (i = 0; i < nr_heads; i++)
-		targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
+		targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
 
 	walker = get_http_walker(url.buf);
 	walker->get_all = 1;
@@ -762,7 +762,7 @@ static int fetch_git(struct discovery *heads,
 		if (!*ref->name)
 			die("cannot fetch by sha1 over smart http");
 		packet_buf_write(&preamble, "%s %s\n",
-				 sha1_to_hex(ref->old_sha1), ref->name);
+				 oid_to_hex(&ref->old_oid), ref->name);
 	}
 	packet_buf_flush(&preamble);
 
@@ -814,7 +814,7 @@ static void parse_fetch(struct strbuf *buf)
 				die("protocol error: expected sha/ref, got %s'", p);
 
 			ref = alloc_ref(name);
-			hashcpy(ref->old_sha1, old_sha1);
+			hashcpy(ref->old_oid.hash, old_sha1);
 
 			*list = ref;
 			list = &ref->next;
diff --git a/remote.c b/remote.c
index 26504b7..0574120 100644
--- a/remote.c
+++ b/remote.c
@@ -1111,7 +1111,7 @@ static void tail_link_ref(struct ref *ref, struct ref ***tail)
 static struct ref *alloc_delete_ref(void)
 {
 	struct ref *ref = alloc_ref("(delete)");
-	hashclr(ref->new_sha1);
+	oidclr(&ref->new_oid);
 	return ref;
 }
 
@@ -1131,7 +1131,7 @@ static int try_explicit_object_name(const char *name,
 
 	if (match) {
 		*match = alloc_ref(name);
-		hashcpy((*match)->new_sha1, sha1);
+		hashcpy((*match)->new_oid.hash, sha1);
 	}
 	return 0;
 }
@@ -1226,7 +1226,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
 	case 0:
 		if (starts_with(dst_value, "refs/"))
 			matched_dst = make_linked_ref(dst_value, dst_tail);
-		else if (is_null_sha1(matched_src->new_sha1))
+		else if (is_null_oid(&matched_src->new_oid))
 			error("unable to delete '%s': remote ref does not exist",
 			      dst_value);
 		else if ((dst_guess = guess_ref(dst_value, matched_src)))
@@ -1357,10 +1357,10 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 	memset(&sent_tips, 0, sizeof(sent_tips));
 	for (ref = *dst; ref; ref = ref->next) {
 		if (ref->peer_ref &&
-		    !is_null_sha1(ref->peer_ref->new_sha1))
-			add_to_tips(&sent_tips, ref->peer_ref->new_sha1);
+		    !is_null_oid(&ref->peer_ref->new_oid))
+			add_to_tips(&sent_tips, ref->peer_ref->new_oid.hash);
 		else
-			add_to_tips(&sent_tips, ref->old_sha1);
+			add_to_tips(&sent_tips, ref->old_oid.hash);
 		if (starts_with(ref->name, "refs/tags/"))
 			string_list_append(&dst_tag, ref->name);
 	}
@@ -1374,7 +1374,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 			continue; /* not a tag */
 		if (string_list_has_string(&dst_tag, ref->name))
 			continue; /* they already have it */
-		if (sha1_object_info(ref->new_sha1, NULL) != OBJ_TAG)
+		if (sha1_object_info(ref->new_oid.hash, NULL) != OBJ_TAG)
 			continue; /* be conservative */
 		item = string_list_append(&src_tag, ref->name);
 		item->util = ref;
@@ -1394,9 +1394,9 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 			struct ref *dst_ref;
 			struct commit *commit;
 
-			if (is_null_sha1(ref->new_sha1))
+			if (is_null_oid(&ref->new_oid))
 				continue;
-			commit = lookup_commit_reference_gently(ref->new_sha1, 1);
+			commit = lookup_commit_reference_gently(ref->new_oid.hash, 1);
 			if (!commit)
 				/* not pushing a commit, which is not an error */
 				continue;
@@ -1410,7 +1410,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 
 			/* Add it in */
 			dst_ref = make_linked_ref(ref->name, dst_tail);
-			hashcpy(dst_ref->new_sha1, ref->new_sha1);
+			oidcpy(&dst_ref->new_oid, &ref->new_oid);
 			dst_ref->peer_ref = copy_ref(ref);
 		}
 	}
@@ -1517,7 +1517,7 @@ int match_push_refs(struct ref *src, struct ref **dst,
 
 			/* Create a new one and link it */
 			dst_peer = make_linked_ref(dst_name, &dst_tail);
-			hashcpy(dst_peer->new_sha1, ref->new_sha1);
+			oidcpy(&dst_peer->new_oid, &ref->new_oid);
 			string_list_insert(&dst_ref_index,
 				dst_peer->name)->util = dst_peer;
 		}
@@ -1569,13 +1569,13 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		int reject_reason = 0;
 
 		if (ref->peer_ref)
-			hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
+			oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
 		else if (!send_mirror)
 			continue;
 
-		ref->deletion = is_null_sha1(ref->new_sha1);
+		ref->deletion = is_null_oid(&ref->new_oid);
 		if (!ref->deletion &&
-			!hashcmp(ref->old_sha1, ref->new_sha1)) {
+			!oidcmp(&ref->old_oid, &ref->new_oid)) {
 			ref->status = REF_STATUS_UPTODATE;
 			continue;
 		}
@@ -1594,7 +1594,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		 */
 		if (ref->expect_old_sha1) {
 			if (ref->expect_old_no_trackback ||
-			    hashcmp(ref->old_sha1, ref->old_sha1_expect))
+			    oidcmp(&ref->old_oid, &ref->old_oid_expect))
 				reject_reason = REF_STATUS_REJECT_STALE;
 		}
 
@@ -1618,15 +1618,15 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		 *     passing the --force argument
 		 */
 
-		else if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {
+		else if (!ref->deletion && !is_null_oid(&ref->old_oid)) {
 			if (starts_with(ref->name, "refs/tags/"))
 				reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
-			else if (!has_sha1_file(ref->old_sha1))
+			else if (!has_object_file(&ref->old_oid))
 				reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
-			else if (!lookup_commit_reference_gently(ref->old_sha1, 1) ||
-				 !lookup_commit_reference_gently(ref->new_sha1, 1))
+			else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) ||
+				 !lookup_commit_reference_gently(ref->new_oid.hash, 1))
 				reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
-			else if (!ref_newer(ref->new_sha1, ref->old_sha1))
+			else if (!ref_newer(ref->new_oid.hash, ref->old_oid.hash))
 				reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
 		}
 
@@ -1925,7 +1925,7 @@ int get_fetch_map(const struct ref *remote_refs,
 
 		if (refspec->exact_sha1) {
 			ref_map = alloc_ref(name);
-			get_sha1_hex(name, ref_map->old_sha1);
+			get_oid_hex(name, &ref_map->old_oid);
 		} else {
 			ref_map = get_remote_ref(remote_refs, name);
 		}
@@ -1966,7 +1966,7 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
 		return 0;
 	for (; list; list = list->next)
 		if (!strcmp(ref->symref, list->name)) {
-			hashcpy(ref->old_sha1, list->old_sha1);
+			oidcpy(&ref->old_oid, &list->old_oid);
 			return 0;
 		}
 	return 1;
@@ -2181,7 +2181,7 @@ static int one_local_ref(const char *refname, const struct object_id *oid,
 
 	len = strlen(refname) + 1;
 	ref = xcalloc(1, sizeof(*ref) + len);
-	hashcpy(ref->new_sha1, oid->hash);
+	oidcpy(&ref->new_oid, oid);
 	memcpy(ref->name, refname, len);
 	**local_tail = ref;
 	*local_tail = &ref->next;
@@ -2218,7 +2218,7 @@ struct ref *guess_remote_head(const struct ref *head,
 	/* If refs/heads/master could be right, it is. */
 	if (!all) {
 		r = find_ref_by_name(refs, "refs/heads/master");
-		if (r && !hashcmp(r->old_sha1, head->old_sha1))
+		if (r && !oidcmp(&r->old_oid, &head->old_oid))
 			return copy_ref(r);
 	}
 
@@ -2226,7 +2226,7 @@ struct ref *guess_remote_head(const struct ref *head,
 	for (r = refs; r; r = r->next) {
 		if (r != head &&
 		    starts_with(r->name, "refs/heads/") &&
-		    !hashcmp(r->old_sha1, head->old_sha1)) {
+		    !oidcmp(&r->old_oid, &head->old_oid)) {
 			*tail = copy_ref(r);
 			tail = &((*tail)->next);
 			if (!all)
@@ -2274,7 +2274,7 @@ static int get_stale_heads_cb(const char *refname, const struct object_id *oid,
 
 	if (stale) {
 		struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);
-		hashcpy(ref->new_sha1, oid->hash);
+		oidcpy(&ref->new_oid, oid);
 	}
 
 clean_exit:
@@ -2394,8 +2394,8 @@ static void apply_cas(struct push_cas_option *cas,
 			continue;
 		ref->expect_old_sha1 = 1;
 		if (!entry->use_tracking)
-			hashcpy(ref->old_sha1_expect, cas->entry[i].expect);
-		else if (remote_tracking(remote, ref->name, ref->old_sha1_expect))
+			hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
+		else if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
 			ref->expect_old_no_trackback = 1;
 		return;
 	}
@@ -2405,7 +2405,7 @@ static void apply_cas(struct push_cas_option *cas,
 		return;
 
 	ref->expect_old_sha1 = 1;
-	if (remote_tracking(remote, ref->name, ref->old_sha1_expect))
+	if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
 		ref->expect_old_no_trackback = 1;
 }
 
diff --git a/remote.h b/remote.h
index 312b7ca..163ea5e 100644
--- a/remote.h
+++ b/remote.h
@@ -79,9 +79,9 @@ extern const struct refspec *tag_refspec;
 
 struct ref {
 	struct ref *next;
-	unsigned char old_sha1[20];
-	unsigned char new_sha1[20];
-	unsigned char old_sha1_expect[20]; /* used by expect-old */
+	struct object_id old_oid;
+	struct object_id new_oid;
+	struct object_id old_oid_expect; /* used by expect-old */
 	char *symref;
 	unsigned int
 		force:1,
diff --git a/send-pack.c b/send-pack.c
index 2a64fec..ae3a104 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -79,11 +79,11 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
 			break;
 
 	while (refs) {
-		if (!is_null_sha1(refs->old_sha1) &&
-		    !feed_object(refs->old_sha1, po.in, 1))
+		if (!is_null_oid(&refs->old_oid) &&
+		    !feed_object(refs->old_oid.hash, po.in, 1))
 			break;
-		if (!is_null_sha1(refs->new_sha1) &&
-		    !feed_object(refs->new_sha1, po.in, 0))
+		if (!is_null_oid(&refs->new_oid) &&
+		    !feed_object(refs->new_oid.hash, po.in, 0))
 			break;
 		refs = refs->next;
 	}
@@ -261,8 +261,8 @@ static int generate_push_cert(struct strbuf *req_buf,
 			continue;
 		update_seen = 1;
 		strbuf_addf(&cert, "%s %s %s\n",
-			    sha1_to_hex(ref->old_sha1),
-			    sha1_to_hex(ref->new_sha1),
+			    oid_to_hex(&ref->old_oid),
+			    oid_to_hex(&ref->new_oid),
 			    ref->name);
 	}
 	if (!update_seen)
@@ -458,8 +458,8 @@ int send_pack(struct send_pack_args *args,
 		if (check_to_send_update(ref, args) < 0)
 			continue;
 
-		old_hex = sha1_to_hex(ref->old_sha1);
-		new_hex = sha1_to_hex(ref->new_sha1);
+		old_hex = oid_to_hex(&ref->old_oid);
+		new_hex = oid_to_hex(&ref->new_oid);
 		if (!cmds_sent) {
 			packet_buf_write(&req_buf,
 					 "%s %s %s%c%s",
diff --git a/transport-helper.c b/transport-helper.c
index 5d99a6b..4ca3e80 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -347,7 +347,7 @@ static int fetch_with_fetch(struct transport *transport,
 			continue;
 
 		strbuf_addf(&buf, "fetch %s %s\n",
-			    sha1_to_hex(posn->old_sha1),
+			    oid_to_hex(&posn->old_oid),
 			    posn->symref ? posn->symref : posn->name);
 	}
 
@@ -490,7 +490,7 @@ static int fetch_with_import(struct transport *transport,
 		else
 			private = xstrdup(name);
 		if (private) {
-			read_ref(private, posn->old_sha1);
+			read_ref(private, posn->old_oid.hash);
 			free(private);
 		}
 	}
@@ -756,7 +756,7 @@ static int push_update_refs_status(struct helper_data *data,
 		private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
 		if (!private)
 			continue;
-		update_ref("update by helper", private, ref->new_sha1, NULL, 0, 0);
+		update_ref("update by helper", private, ref->new_oid.hash, NULL, 0, 0);
 		free(private);
 	}
 	strbuf_release(&buf);
@@ -803,7 +803,7 @@ static int push_refs_with_push(struct transport *transport,
 			if (ref->peer_ref)
 				strbuf_addstr(&buf, ref->peer_ref->name);
 			else
-				strbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));
+				strbuf_addstr(&buf, oid_to_hex(&ref->new_oid));
 		}
 		strbuf_addch(&buf, ':');
 		strbuf_addstr(&buf, ref->name);
@@ -812,14 +812,14 @@ static int push_refs_with_push(struct transport *transport,
 		/*
 		 * The "--force-with-lease" options without explicit
 		 * values to expect have already been expanded into
-		 * the ref->old_sha1_expect[] field; we can ignore
+		 * the ref->old_oid_expect[] field; we can ignore
 		 * transport->smart_options->cas altogether and instead
 		 * can enumerate them from the refs.
 		 */
 		if (ref->expect_old_sha1) {
 			struct strbuf cas = STRBUF_INIT;
 			strbuf_addf(&cas, "%s:%s",
-				    ref->name, sha1_to_hex(ref->old_sha1_expect));
+				    ref->name, oid_to_hex(&ref->old_oid_expect));
 			string_list_append(&cas_options, strbuf_detach(&cas, NULL));
 		}
 	}
@@ -883,7 +883,7 @@ static int push_refs_with_export(struct transport *transport,
 		if (private && !get_sha1(private, sha1)) {
 			strbuf_addf(&buf, "^%s", private);
 			string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
-			hashcpy(ref->old_sha1, sha1);
+			hashcpy(ref->old_oid.hash, sha1);
 		}
 		free(private);
 
@@ -1015,11 +1015,11 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
 		if (buf.buf[0] == '@')
 			(*tail)->symref = xstrdup(buf.buf + 1);
 		else if (buf.buf[0] != '?')
-			get_sha1_hex(buf.buf, (*tail)->old_sha1);
+			get_oid_hex(buf.buf, &(*tail)->old_oid);
 		if (eon) {
 			if (has_attribute(eon + 1, "unchanged")) {
 				(*tail)->status |= REF_STATUS_UPTODATE;
-				read_ref((*tail)->name, (*tail)->old_sha1);
+				read_ref((*tail)->name, (*tail)->old_oid.hash);
 			}
 		}
 		tail = &((*tail)->next);
diff --git a/transport.c b/transport.c
index 40692f8..e880d94 100644
--- a/transport.c
+++ b/transport.c
@@ -79,7 +79,7 @@ static int read_loose_refs(struct strbuf *path, int name_offset,
 				continue;
 			next = alloc_ref(path->buf + name_offset);
 			if (read_in_full(fd, buffer, 40) != 40 ||
-					get_sha1_hex(buffer, next->old_sha1)) {
+					get_oid_hex(buffer, &next->old_oid)) {
 				close(fd);
 				free(next);
 				continue;
@@ -131,7 +131,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 		if (!(*list)->next || cmp < 0) {
 			struct ref *next = alloc_ref(buffer + 41);
 			buffer[40] = '\0';
-			if (get_sha1_hex(buffer, next->old_sha1)) {
+			if (get_oid_hex(buffer, &next->old_oid)) {
 				warning ("invalid SHA-1: %s", buffer);
 				free(next);
 				continue;
@@ -162,7 +162,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 			continue;
 		if (!ref->peer_ref)
 			continue;
-		if (is_null_sha1(ref->new_sha1))
+		if (is_null_oid(&ref->new_oid))
 			continue;
 
 		/* Follow symbolic refs (mainly for HEAD). */
@@ -412,7 +412,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus
 	for (i = 0; i < data->header.references.nr; i++) {
 		struct ref_list_entry *e = data->header.references.list + i;
 		struct ref *ref = alloc_ref(e->name);
-		hashcpy(ref->old_sha1, e->sha1);
+		hashcpy(ref->old_oid.hash, e->sha1);
 		ref->next = result;
 		result = ref;
 	}
@@ -611,7 +611,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
 			delete_ref(rs.dst, NULL, 0);
 		} else
 			update_ref("update by push", rs.dst,
-					ref->new_sha1, NULL, 0, 0);
+					ref->new_oid.hash, NULL, 0, 0);
 		free(rs.dst);
 	}
 }
@@ -651,7 +651,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 {
 	if (ref->deletion)
 		print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
-	else if (is_null_sha1(ref->old_sha1))
+	else if (is_null_oid(&ref->old_oid))
 		print_ref_status('*',
 			(starts_with(ref->name, "refs/tags/") ? "[new tag]" :
 			"[new branch]"),
@@ -661,7 +661,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 		char type;
 		const char *msg;
 
-		strcpy(quickref, status_abbrev(ref->old_sha1));
+		strcpy(quickref, status_abbrev(ref->old_oid.hash));
 		if (ref->forced_update) {
 			strcat(quickref, "...");
 			type = '+';
@@ -671,7 +671,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 			type = ' ';
 			msg = NULL;
 		}
-		strcat(quickref, status_abbrev(ref->new_sha1));
+		strcat(quickref, status_abbrev(ref->new_oid.hash));
 
 		print_ref_status(type, quickref, ref, ref->peer_ref, msg, porcelain);
 	}
@@ -1092,8 +1092,8 @@ static int run_pre_push_hook(struct transport *transport,
 
 		strbuf_reset(&buf);
 		strbuf_addf( &buf, "%s %s %s %s\n",
-			 r->peer_ref->name, sha1_to_hex(r->new_sha1),
-			 r->name, sha1_to_hex(r->old_sha1));
+			 r->peer_ref->name, oid_to_hex(&r->new_oid),
+			 r->name, oid_to_hex(&r->old_oid));
 
 		if (write_in_full(proc.in, buf.buf, buf.len) != buf.len) {
 			ret = -1;
@@ -1173,8 +1173,8 @@ int transport_push(struct transport *transport,
 		if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
 			struct ref *ref = remote_refs;
 			for (; ref; ref = ref->next)
-				if (!is_null_sha1(ref->new_sha1) &&
-				    !push_unpushed_submodules(ref->new_sha1,
+				if (!is_null_oid(&ref->new_oid) &&
+				    !push_unpushed_submodules(ref->new_oid.hash,
 					    transport->remote->name))
 				    die ("Failed to push all needed submodules!");
 		}
@@ -1185,8 +1185,8 @@ int transport_push(struct transport *transport,
 			struct string_list needs_pushing = STRING_LIST_INIT_DUP;
 
 			for (; ref; ref = ref->next)
-				if (!is_null_sha1(ref->new_sha1) &&
-				    find_unpushed_submodules(ref->new_sha1,
+				if (!is_null_oid(&ref->new_oid) &&
+				    find_unpushed_submodules(ref->new_oid.hash,
 					    transport->remote->name, &needs_pushing))
 					die_with_unpushed_submodules(&needs_pushing);
 		}
@@ -1239,8 +1239,8 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
 	for (rm = refs; rm; rm = rm->next) {
 		nr_refs++;
 		if (rm->peer_ref &&
-		    !is_null_sha1(rm->old_sha1) &&
-		    !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
+		    !is_null_oid(&rm->old_oid) &&
+		    !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
 			continue;
 		ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
 		heads[nr_heads++] = rm;
diff --git a/transport.h b/transport.h
index 18d2cf8..4a4aaac 100644
--- a/transport.h
+++ b/transport.h
@@ -75,15 +75,15 @@ struct transport {
 	/**
 	 * Push the objects and refs. Send the necessary objects, and
 	 * then, for any refs where peer_ref is set and
-	 * peer_ref->new_sha1 is different from old_sha1, tell the
-	 * remote side to update each ref in the list from old_sha1 to
-	 * peer_ref->new_sha1.
+	 * peer_ref->new_oid is different from old_oid, tell the
+	 * remote side to update each ref in the list from old_oid to
+	 * peer_ref->new_oid.
 	 *
 	 * Where possible, set the status for each ref appropriately.
 	 *
 	 * The transport must modify new_sha1 in the ref to the new
 	 * value if the remote accepted the change. Note that this
-	 * could be a different value from peer_ref->new_sha1 if the
+	 * could be a different value from peer_ref->new_oid if the
 	 * process involved generating new commits.
 	 **/
 	int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
diff --git a/walker.c b/walker.c
index 44a936c..14f71c0 100644
--- a/walker.c
+++ b/walker.c
@@ -191,7 +191,7 @@ static int interpret_target(struct walker *walker, char *target, unsigned char *
 	if (!check_refname_format(target, 0)) {
 		struct ref *ref = alloc_ref(target);
 		if (!walker->fetch_ref(walker, ref)) {
-			hashcpy(sha1, ref->old_sha1);
+			hashcpy(sha1, ref->old_oid.hash);
 			free(ref);
 			return 0;
 		}
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 04/10] add_sought_entry_mem: convert to struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (2 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 03/10] Convert struct ref to use object_id brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 05/10] parse_fetch: convert to use " brian m. carlson
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Convert this function to use struct object_id.  Express several
hardcoded constants in terms of GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/fetch-pack.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 19215b3..cf3019e 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
 				 const char *name, int namelen)
 {
 	struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);
-	unsigned char sha1[20];
+	struct object_id oid;
+	const int chunksz = GIT_SHA1_HEXSZ + 1;
 
-	if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
-		hashcpy(ref->old_oid.hash, sha1);
-		name += 41;
-		namelen -= 41;
+	if (namelen > chunksz && name[chunksz - 1] == ' ' &&
+		!get_oid_hex(name, &oid)) {
+		oidcpy(&ref->old_oid, &oid);
+		name += chunksz;
+		namelen -= chunksz;
 	}
 
 	memcpy(ref->name, name, namelen);
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 05/10] parse_fetch: convert to use struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (3 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 04/10] add_sought_entry_mem: convert to struct object_id brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 06/10] get_remote_heads: convert to " brian m. carlson
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Convert the parse_fetch function to use struct object_id.  Remove the
strlen check as get_oid_hex will fail safely on receiving a too-short
NUL-terminated string.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 remote-curl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/remote-curl.c b/remote-curl.c
index 80cb4c7..1709346 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -802,19 +802,19 @@ static void parse_fetch(struct strbuf *buf)
 		if (skip_prefix(buf->buf, "fetch ", &p)) {
 			const char *name;
 			struct ref *ref;
-			unsigned char old_sha1[20];
+			struct object_id old_oid;
 
-			if (strlen(p) < 40 || get_sha1_hex(p, old_sha1))
+			if (get_oid_hex(p, &old_oid))
 				die("protocol error: expected sha/ref, got %s'", p);
-			if (p[40] == ' ')
-				name = p + 41;
-			else if (!p[40])
+			if (p[GIT_SHA1_HEXSZ] == ' ')
+				name = p + GIT_SHA1_HEXSZ + 1;
+			else if (!p[GIT_SHA1_HEXSZ])
 				name = "";
 			else
 				die("protocol error: expected sha/ref, got %s'", p);
 
 			ref = alloc_ref(name);
-			hashcpy(ref->old_oid.hash, old_sha1);
+			oidcpy(&ref->old_oid, &old_oid);
 
 			*list = ref;
 			list = &ref->next;
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 06/10] get_remote_heads: convert to struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (4 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 05/10] parse_fetch: convert to use " brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 07/10] push_refs_with_export: " brian m. carlson
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Replace an unsigned char array with struct object_id and express several
hard-coded constants in terms of GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 connect.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/connect.c b/connect.c
index f8b10eb..7f005a7 100644
--- a/connect.c
+++ b/connect.c
@@ -119,7 +119,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 	*list = NULL;
 	for (;;) {
 		struct ref *ref;
-		unsigned char old_sha1[20];
+		struct object_id old_oid;
 		char *name;
 		int len, name_len;
 		char *buffer = packet_buffer;
@@ -138,34 +138,36 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 		if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
 			die("remote error: %s", arg);
 
-		if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
-			if (get_sha1_hex(arg, old_sha1))
+		if (len == GIT_SHA1_HEXSZ + strlen("shallow ") &&
+			skip_prefix(buffer, "shallow ", &arg)) {
+			if (get_oid_hex(arg, &old_oid))
 				die("protocol error: expected shallow sha-1, got '%s'", arg);
 			if (!shallow_points)
 				die("repository on the other end cannot be shallow");
-			sha1_array_append(shallow_points, old_sha1);
+			sha1_array_append(shallow_points, old_oid.hash);
 			continue;
 		}
 
-		if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
+		if (len < GIT_SHA1_HEXSZ + 2 || get_oid_hex(buffer, &old_oid) ||
+			buffer[GIT_SHA1_HEXSZ] != ' ')
 			die("protocol error: expected sha/ref, got '%s'", buffer);
-		name = buffer + 41;
+		name = buffer + GIT_SHA1_HEXSZ + 1;
 
 		name_len = strlen(name);
-		if (len != name_len + 41) {
+		if (len != name_len + GIT_SHA1_HEXSZ + 1) {
 			free(server_capabilities);
 			server_capabilities = xstrdup(name + name_len + 1);
 		}
 
 		if (extra_have && !strcmp(name, ".have")) {
-			sha1_array_append(extra_have, old_sha1);
+			sha1_array_append(extra_have, old_oid.hash);
 			continue;
 		}
 
 		if (!check_ref(name, flags))
 			continue;
-		ref = alloc_ref(buffer + 41);
-		hashcpy(ref->old_oid.hash, old_sha1);
+		ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
+		oidcpy(&ref->old_oid, &old_oid);
 		*list = ref;
 		list = &ref->next;
 		got_at_least_one_head = 1;
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 07/10] push_refs_with_export: convert to struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (5 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 06/10] get_remote_heads: convert to " brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 08/10] ref_newer: convert to use " brian m. carlson
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 transport-helper.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/transport-helper.c b/transport-helper.c
index 4ca3e80..1f28b82 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -877,13 +877,13 @@ static int push_refs_with_export(struct transport *transport,
 
 	for (ref = remote_refs; ref; ref = ref->next) {
 		char *private;
-		unsigned char sha1[20];
+		struct object_id oid;
 
 		private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
-		if (private && !get_sha1(private, sha1)) {
+		if (private && !get_sha1(private, oid.hash)) {
 			strbuf_addf(&buf, "^%s", private);
 			string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
-			hashcpy(ref->old_oid.hash, sha1);
+			oidcpy(&ref->old_oid, &oid);
 		}
 		free(private);
 
@@ -897,7 +897,7 @@ static int push_refs_with_export(struct transport *transport,
 					name = resolve_ref_unsafe(
 						 ref->peer_ref->name,
 						 RESOLVE_REF_READING,
-						 sha1, &flag);
+						 oid.hash, &flag);
 					if (!name || !(flag & REF_ISSYMREF))
 						name = ref->peer_ref->name;
 
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 08/10] ref_newer: convert to use struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (6 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 07/10] push_refs_with_export: " brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-06-13 22:16 ` [PATCH v2 10/10] remote: convert functions to " brian m. carlson
  2015-08-02 23:33 ` [PATCH v2 00/10] object_id part 2 Michael Haggerty
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Convert ref_newer and its caller to use struct object_id instead of
unsigned char *.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/remote.c | 2 +-
 http-push.c      | 4 ++--
 remote.c         | 8 ++++----
 remote.h         | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index fa4d04c..0efc388 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -411,7 +411,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
 		else if (is_null_oid(&ref->old_oid))
 			info->status = PUSH_STATUS_CREATE;
 		else if (has_object_file(&ref->old_oid) &&
-			 ref_newer(ref->new_oid.hash, ref->old_oid.hash))
+			 ref_newer(&ref->new_oid, &ref->old_oid))
 			info->status = PUSH_STATUS_FASTFORWARD;
 		else
 			info->status = PUSH_STATUS_OUTOFDATE;
diff --git a/http-push.c b/http-push.c
index d054fdb..0e688a7 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1899,8 +1899,8 @@ int main(int argc, char **argv)
 		    !is_null_oid(&ref->old_oid) &&
 		    !ref->force) {
 			if (!has_object_file(&ref->old_oid) ||
-			    !ref_newer(ref->peer_ref->new_oid.hash,
-				       ref->old_oid.hash)) {
+			    !ref_newer(&ref->peer_ref->new_oid,
+				       &ref->old_oid)) {
 				/*
 				 * We do not have the remote ref, or
 				 * we know that the remote ref is not
diff --git a/remote.c b/remote.c
index 0574120..cb85c3e 100644
--- a/remote.c
+++ b/remote.c
@@ -1626,7 +1626,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 			else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) ||
 				 !lookup_commit_reference_gently(ref->new_oid.hash, 1))
 				reject_reason = REF_STATUS_REJECT_NEEDS_FORCE;
-			else if (!ref_newer(ref->new_oid.hash, ref->old_oid.hash))
+			else if (!ref_newer(&ref->new_oid, &ref->old_oid))
 				reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
 		}
 
@@ -1982,7 +1982,7 @@ static void unmark_and_free(struct commit_list *list, unsigned int mark)
 	}
 }
 
-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 {
 	struct object *o;
 	struct commit *old, *new;
@@ -1993,12 +1993,12 @@ int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
 	 * Both new and old must be commit-ish and new is descendant of
 	 * old.  Otherwise we require --force.
 	 */
-	o = deref_tag(parse_object(old_sha1), NULL, 0);
+	o = deref_tag(parse_object(old_oid->hash), NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	old = (struct commit *) o;
 
-	o = deref_tag(parse_object(new_sha1), NULL, 0);
+	o = deref_tag(parse_object(new_oid->hash), NULL, 0);
 	if (!o || o->type != OBJ_COMMIT)
 		return 0;
 	new = (struct commit *) o;
diff --git a/remote.h b/remote.h
index 163ea5e..4a039ba 100644
--- a/remote.h
+++ b/remote.h
@@ -150,7 +150,7 @@ extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
 				     struct sha1_array *shallow);
 
 int resolve_remote_symref(struct ref *ref, struct ref *list);
-int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
+int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);
 
 /*
  * Remove and free all but the first of any entries in the input list
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 10/10] remote: convert functions to struct object_id
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (7 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 08/10] ref_newer: convert to use " brian m. carlson
@ 2015-06-13 22:16 ` brian m. carlson
  2015-08-02 23:33 ` [PATCH v2 00/10] object_id part 2 Michael Haggerty
  9 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-06-13 22:16 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

Convert several unsigned char arrays to use struct object_id instead,
and change hard-coded 40-based constants to use GIT_SHA1_HEXSZ as well.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 remote.c | 64 ++++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/remote.c b/remote.c
index c72d796..92dc8d6 100644
--- a/remote.c
+++ b/remote.c
@@ -492,7 +492,7 @@ static void alias_all_urls(void)
 static void read_config(void)
 {
 	static int loaded;
-	unsigned char sha1[20];
+	struct object_id oid;
 	const char *head_ref;
 	int flag;
 
@@ -501,7 +501,7 @@ static void read_config(void)
 	loaded = 1;
 
 	current_branch = NULL;
-	head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
+	head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
 	if (head_ref && (flag & REF_ISSYMREF) &&
 	    skip_prefix(head_ref, "refs/heads/", &head_ref)) {
 		current_branch = make_branch(head_ref, 0);
@@ -580,12 +580,12 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
 		flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
 
 		if (fetch) {
-			unsigned char unused[40];
+			struct object_id unused;
 
 			/* LHS */
 			if (!*rs[i].src)
 				; /* empty is ok; it means "HEAD" */
-			else if (llen == 40 && !get_sha1_hex(rs[i].src, unused))
+			else if (llen == GIT_SHA1_HEXSZ && !get_oid_hex(rs[i].src, &unused))
 				rs[i].exact_sha1 = 1; /* ok */
 			else if (!check_refname_format(rs[i].src, flags))
 				; /* valid looking ref is ok */
@@ -1118,7 +1118,7 @@ static struct ref *alloc_delete_ref(void)
 static int try_explicit_object_name(const char *name,
 				    struct ref **match)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 
 	if (!*name) {
 		if (match)
@@ -1126,12 +1126,12 @@ static int try_explicit_object_name(const char *name,
 		return 0;
 	}
 
-	if (get_sha1(name, sha1))
+	if (get_sha1(name, oid.hash))
 		return -1;
 
 	if (match) {
 		*match = alloc_ref(name);
-		hashcpy((*match)->new_oid.hash, sha1);
+		oidcpy(&(*match)->new_oid, &oid);
 	}
 	return 0;
 }
@@ -1146,10 +1146,10 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail)
 static char *guess_ref(const char *name, struct ref *peer)
 {
 	struct strbuf buf = STRBUF_INIT;
-	unsigned char sha1[20];
+	struct object_id oid;
 
 	const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
-					   sha1, NULL);
+					   oid.hash, NULL);
 	if (!r)
 		return NULL;
 
@@ -1207,12 +1207,12 @@ static int match_explicit(struct ref *src, struct ref *dst,
 		return -1;
 
 	if (!dst_value) {
-		unsigned char sha1[20];
+		struct object_id oid;
 		int flag;
 
 		dst_value = resolve_ref_unsafe(matched_src->name,
 					       RESOLVE_REF_READING,
-					       sha1, &flag);
+					       oid.hash, &flag);
 		if (!dst_value ||
 		    ((flag & REF_ISSYMREF) &&
 		     !starts_with(dst_value, "refs/heads/")))
@@ -1328,13 +1328,13 @@ struct tips {
 	int nr, alloc;
 };
 
-static void add_to_tips(struct tips *tips, const unsigned char *sha1)
+static void add_to_tips(struct tips *tips, const struct object_id *oid)
 {
 	struct commit *commit;
 
-	if (is_null_sha1(sha1))
+	if (is_null_oid(oid))
 		return;
-	commit = lookup_commit_reference_gently(sha1, 1);
+	commit = lookup_commit_reference_gently(oid->hash, 1);
 	if (!commit || (commit->object.flags & TMP_MARK))
 		return;
 	commit->object.flags |= TMP_MARK;
@@ -1358,9 +1358,9 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 	for (ref = *dst; ref; ref = ref->next) {
 		if (ref->peer_ref &&
 		    !is_null_oid(&ref->peer_ref->new_oid))
-			add_to_tips(&sent_tips, ref->peer_ref->new_oid.hash);
+			add_to_tips(&sent_tips, &ref->peer_ref->new_oid);
 		else
-			add_to_tips(&sent_tips, ref->old_oid.hash);
+			add_to_tips(&sent_tips, &ref->old_oid);
 		if (starts_with(ref->name, "refs/tags/"))
 			string_list_append(&dst_tag, ref->name);
 	}
@@ -1645,7 +1645,7 @@ static void set_merge(struct branch *ret)
 {
 	struct remote *remote;
 	char *ref;
-	unsigned char sha1[20];
+	struct object_id oid;
 	int i;
 
 	if (!ret)
@@ -1671,7 +1671,7 @@ static void set_merge(struct branch *ret)
 		    strcmp(ret->remote_name, "."))
 			continue;
 		if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
-			     sha1, &ref) == 1)
+			     oid.hash, &ref) == 1)
 			ret->merge[i]->dst = ref;
 		else
 			ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
@@ -1831,10 +1831,10 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
 
 static int ignore_symref_update(const char *refname)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	int flag;
 
-	if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
+	if (!resolve_ref_unsafe(refname, 0, oid.hash, &flag))
 		return 0; /* non-existing refs are OK */
 	return (flag & REF_ISSYMREF);
 }
@@ -2033,9 +2033,9 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		       const char **upstream_name)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	struct commit *ours, *theirs;
-	char symmetric[84];
+	char symmetric[GIT_SHA1_HEXSZ * 2 + 4];
 	struct rev_info revs;
 	const char *rev_argv[10], *base;
 	int rev_argc;
@@ -2048,15 +2048,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		return -1;
 
 	/* Cannot stat if what we used to build on no longer exists */
-	if (read_ref(base, sha1))
+	if (read_ref(base, oid.hash))
 		return -1;
-	theirs = lookup_commit_reference(sha1);
+	theirs = lookup_commit_reference(oid.hash);
 	if (!theirs)
 		return -1;
 
-	if (read_ref(branch->refname, sha1))
+	if (read_ref(branch->refname, oid.hash))
 		return -1;
-	ours = lookup_commit_reference(sha1);
+	ours = lookup_commit_reference(oid.hash);
 	if (!ours)
 		return -1;
 
@@ -2075,8 +2075,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 	rev_argv[rev_argc] = NULL;
 
 	strcpy(symmetric, oid_to_hex(&ours->object.oid));
-	strcpy(symmetric + 40, "...");
-	strcpy(symmetric + 43, oid_to_hex(&theirs->object.oid));
+	strcpy(symmetric + GIT_SHA1_HEXSZ, "...");
+	strcpy(symmetric + GIT_SHA1_HEXSZ + 3, oid_to_hex(&theirs->object.oid));
 
 	init_revisions(&revs, NULL);
 	setup_revisions(rev_argc, rev_argv, &revs, NULL);
@@ -2369,14 +2369,14 @@ int is_empty_cas(const struct push_cas_option *cas)
  * If we cannot do so, return negative to signal an error.
  */
 static int remote_tracking(struct remote *remote, const char *refname,
-			   unsigned char sha1[20])
+			   struct object_id *oid)
 {
 	char *dst;
 
 	dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
 	if (!dst)
 		return -1; /* no tracking ref for refname at remote */
-	if (read_ref(dst, sha1))
+	if (read_ref(dst, oid->hash))
 		return -1; /* we know what the tracking ref is but we cannot read it */
 	return 0;
 }
@@ -2395,7 +2395,7 @@ static void apply_cas(struct push_cas_option *cas,
 		ref->expect_old_sha1 = 1;
 		if (!entry->use_tracking)
 			hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
-		else if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
+		else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
 			ref->expect_old_no_trackback = 1;
 		return;
 	}
@@ -2405,7 +2405,7 @@ static void apply_cas(struct push_cas_option *cas,
 		return;
 
 	ref->expect_old_sha1 = 1;
-	if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
+	if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
 		ref->expect_old_no_trackback = 1;
 }
 
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 03/10] Convert struct ref to use object_id.
  2015-06-13 22:16 ` [PATCH v2 03/10] Convert struct ref to use object_id brian m. carlson
@ 2015-06-15 22:13   ` Junio C Hamano
  0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2015-06-15 22:13 UTC (permalink / raw)
  To: brian m. carlson
  Cc: git, Jeff King, Nguyễn Thái Ngọc Duy, Michael Haggerty

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> Use struct object_id in three fields in struct ref and convert all the
> necessary places that use it.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  builtin/clone.c        | 16 +++++++-------
>  builtin/fetch-pack.c   |  4 ++--
>  builtin/fetch.c        | 50 +++++++++++++++++++++----------------------
>  builtin/ls-remote.c    |  2 +-
>  builtin/receive-pack.c |  2 +-
>  builtin/remote.c       | 12 +++++------
>  connect.c              |  2 +-
>  fetch-pack.c           | 18 ++++++++--------
>  http-push.c            | 46 +++++++++++++++++++--------------------
>  http.c                 |  2 +-
>  remote-curl.c          | 10 ++++-----
>  remote.c               | 58 +++++++++++++++++++++++++-------------------------
>  remote.h               |  6 +++---
>  send-pack.c            | 16 +++++++-------
>  transport-helper.c     | 18 ++++++++--------
>  transport.c            | 32 ++++++++++++++--------------
>  transport.h            |  8 +++----
>  walker.c               |  2 +-
>  18 files changed, 152 insertions(+), 152 deletions(-)

Whew.  This was a big patch.

I've eyeballed it and did not find anything questionable.  Thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 00/10] object_id part 2
  2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
                   ` (8 preceding siblings ...)
  2015-06-13 22:16 ` [PATCH v2 10/10] remote: convert functions to " brian m. carlson
@ 2015-08-02 23:33 ` Michael Haggerty
  2015-08-03 23:45   ` brian m. carlson
  9 siblings, 1 reply; 13+ messages in thread
From: Michael Haggerty @ 2015-08-02 23:33 UTC (permalink / raw)
  To: brian m. carlson, git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy

On 06/14/2015 12:16 AM, brian m. carlson wrote:
> This is another series of conversions to struct object_id.
> 
> This series converts more of the refs code and struct object to use
> struct object_id.  It introduces an additional helper function,
> has_object_file, which is the equivalent of has_sha1_file.  The name was
> chosen to be slightly more logical than has_oid_file, although it can be
> changed if desired.
> 
> The next-to-last patch in this series is the conversion of struct object
> to use struct object_id.  This is a necessarily large patch because of
> the large number of places this code is used.  That patch will most
> likely be too large to make it through to the list, so this series is
> available in the object-id-part2 branch from:

FWIW I've skimmed patches 01-08 inclusive and nothing jumped out at me.

Brian, what was your experience when writing these patches? Did they
tend to work as soon as they compiled without errors (i.e., not super
risky) or did you often have test suite failures that you had to go back
and fix (i.e., risky)? If the latter, what kinds of code patterns tended
to be problematic? Your answers might help reviewers decide how much
diligence is needed when reviewing these patches and what kind of
changes to inspect extra carefully. Because doing a thorough review of
all of the patches would be quite a bit of work.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 00/10] object_id part 2
  2015-08-02 23:33 ` [PATCH v2 00/10] object_id part 2 Michael Haggerty
@ 2015-08-03 23:45   ` brian m. carlson
  0 siblings, 0 replies; 13+ messages in thread
From: brian m. carlson @ 2015-08-03 23:45 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: git, Jeff King, Nguyễn Thái Ngọc Duy

[-- Attachment #1: Type: text/plain, Size: 1416 bytes --]

On Mon, Aug 03, 2015 at 01:33:56AM +0200, Michael Haggerty wrote:
> Brian, what was your experience when writing these patches? Did they
> tend to work as soon as they compiled without errors (i.e., not super
> risky) or did you often have test suite failures that you had to go back
> and fix (i.e., risky)? If the latter, what kinds of code patterns tended
> to be problematic? Your answers might help reviewers decide how much
> diligence is needed when reviewing these patches and what kind of
> changes to inspect extra carefully. Because doing a thorough review of
> all of the patches would be quite a bit of work.

In this particular branch, I think I may have had one bad patch.  (I'm
trying to recall because I've been working on patches for part 3 in the
mean time, and they all seem to group together.)  In general, over all
my patches, the conversions I've had to fix the most have been the ones
to use the GIT_SHA1_* constants, because it's very easy to get
off-by-one errors in there or mess up the values such that things break.
Extra effort on those, or additional suggestions on how to make them
cleaner and less brittle, both now and in the future, would be welcome.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-08-03 23:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-13 22:16 [PATCH v2 00/10] object_id part 2 brian m. carlson
2015-06-13 22:16 ` [PATCH v2 01/10] refs: convert some internal functions to use object_id brian m. carlson
2015-06-13 22:16 ` [PATCH v2 02/10] sha1_file: introduce has_object_file helper brian m. carlson
2015-06-13 22:16 ` [PATCH v2 03/10] Convert struct ref to use object_id brian m. carlson
2015-06-15 22:13   ` Junio C Hamano
2015-06-13 22:16 ` [PATCH v2 04/10] add_sought_entry_mem: convert to struct object_id brian m. carlson
2015-06-13 22:16 ` [PATCH v2 05/10] parse_fetch: convert to use " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 06/10] get_remote_heads: convert to " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 07/10] push_refs_with_export: " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 08/10] ref_newer: convert to use " brian m. carlson
2015-06-13 22:16 ` [PATCH v2 10/10] remote: convert functions to " brian m. carlson
2015-08-02 23:33 ` [PATCH v2 00/10] object_id part 2 Michael Haggerty
2015-08-03 23:45   ` brian m. carlson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.