* [PATCH 0/8] object_id part 2
@ 2015-06-09 16:28 brian m. carlson
2015-06-09 16:28 ` [PATCH 1/8] refs: convert some internal functions to use object_id brian m. carlson
` (7 more replies)
0 siblings, 8 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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 two additional helper functions. One
is 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 second helper function is parse_oid_hex. It works much like
get_oid_hex, but it takes an optional length argument and returns the
number of bytes parsed on success (40) and 0 on error. It's designed to
be more useful in conditionals and to enable us to avoid having to write
GIT_SHA1_HEXSZ in favor of simply using the return value.
The final piece 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.
brian m. carlson (8):
refs: convert some internal functions to use object_id
sha1_file: introduce has_object_file helper.
Convert struct ref to use object_id.
Add a utility function to make parsing hex values easier.
add_sought_entry_mem: convert to struct object_id
parse_fetch: convert to use struct object_id
ref_newer: convert to use struct object_id
Convert struct object to 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 | 12 ++++++
combine-diff.c | 4 +-
commit.c | 32 +++++++-------
connect.c | 2 +-
decorate.c | 2 +-
diff-lib.c | 2 +-
fetch-pack.c | 24 +++++------
fsck.c | 10 ++---
hex.c | 7 ++++
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 | 21 +++++-----
remote.c | 68 +++++++++++++++---------------
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 | 18 ++++----
transport.c | 32 +++++++-------
transport.h | 8 ++--
tree.c | 10 ++---
upload-pack.c | 26 ++++++------
walker.c | 18 ++++----
wt-status.c | 2 +-
87 files changed, 706 insertions(+), 679 deletions(-)
--
2.4.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 1/8] refs: convert some internal functions to use object_id
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-09 16:28 ` [PATCH 2/8] sha1_file: introduce has_object_file helper brian m. carlson
` (6 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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 a742d79..b391a0f 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 {
@@ -2292,11 +2292,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);
@@ -2323,13 +2323,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))
@@ -2340,7 +2340,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;
@@ -2479,12 +2479,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));
}
/*
@@ -2497,9 +2497,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;
}
@@ -2889,7 +2889,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;
@@ -2901,7 +2901,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);
@@ -2915,13 +2915,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);
@@ -2944,10 +2944,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;
}
@@ -2964,8 +2964,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;
@@ -3218,11 +3218,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);
@@ -3243,10 +3243,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);
@@ -3292,8 +3292,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] 23+ messages in thread
* [PATCH 2/8] sha1_file: introduce has_object_file helper.
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
2015-06-09 16:28 ` [PATCH 1/8] refs: convert some internal functions to use object_id brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-10 9:59 ` Duy Nguyen
2015-06-09 16:28 ` [PATCH 3/8] Convert struct ref to use object_id brian m. carlson
` (5 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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 7e38148..09f7f03 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3173,6 +3173,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] 23+ messages in thread
* [PATCH 3/8] Convert struct ref to use object_id.
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
2015-06-09 16:28 ` [PATCH 1/8] refs: convert some internal functions to use object_id brian m. carlson
2015-06-09 16:28 ` [PATCH 2/8] sha1_file: introduce has_object_file helper brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-11 15:41 ` Michael Haggerty
2015-06-09 16:28 ` [PATCH 4/8] Add a utility function to make parsing hex values easier brian m. carlson
` (4 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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 b878252..c909574 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -505,7 +505,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())
@@ -520,9 +520,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);
}
}
@@ -542,7 +542,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;
}
@@ -591,12 +591,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);
@@ -606,7 +606,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);
}
}
@@ -957,7 +957,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..706d2fb 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);
+ hashcpy(ref->new_oid.hash, oid->hash);
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] 23+ messages in thread
* [PATCH 4/8] Add a utility function to make parsing hex values easier.
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
` (2 preceding siblings ...)
2015-06-09 16:28 ` [PATCH 3/8] Convert struct ref to use object_id brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-11 16:09 ` Michael Haggerty
2015-06-09 16:28 ` [PATCH 5/8] add_sought_entry_mem: convert to struct object_id brian m. carlson
` (3 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 UTC (permalink / raw)
To: git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
get_oid_hex is already available for parsing hex object IDs into struct
object_id, but parsing code still must hard-code the number of bytes
read. Introduce parse_oid_hex, which accepts an optional length, and
also returns the number of bytes parsed on success, or 0 on failure.
This makes it easier for code not to assume fixed values when parsing,
and to move to larger hash functions in the future.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
cache.h | 9 +++++++++
hex.c | 7 +++++++
2 files changed, 16 insertions(+)
diff --git a/cache.h b/cache.h
index fa1f067..f3b829f 100644
--- a/cache.h
+++ b/cache.h
@@ -1012,6 +1012,15 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern int get_oid_hex(const char *hex, struct object_id *sha1);
+/*
+ * Like get_oid_hex, but accepts an optional length argument, which may be -1
+ * if the string is terminated by a non-hex character. As with get_oid_hex,
+ * reading stops if a NUL is encountered. Returns the number of characters
+ * read (40) on success and 0 on failure. This is designed to be easier to
+ * use for parsing data than get_oid_hex.
+ */
+extern int parse_oid_hex(const char *hex, int len, struct object_id *oid);
+
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
extern int read_ref_full(const char *refname, int resolve_flags,
diff --git a/hex.c b/hex.c
index 899b74a..ba196d7 100644
--- a/hex.c
+++ b/hex.c
@@ -61,6 +61,13 @@ int get_oid_hex(const char *hex, struct object_id *oid)
return get_sha1_hex(hex, oid->hash);
}
+int parse_oid_hex(const char *hex, int len, struct object_id *oid)
+{
+ if (len != -1 && len < GIT_SHA1_HEXSZ)
+ return 0;
+ return get_sha1_hex(hex, oid->hash) ? GIT_SHA1_HEXSZ : 0;
+}
+
char *sha1_to_hex(const unsigned char *sha1)
{
static int bufno;
--
2.4.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 5/8] add_sought_entry_mem: convert to struct object_id
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
` (3 preceding siblings ...)
2015-06-09 16:28 ` [PATCH 4/8] Add a utility function to make parsing hex values easier brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-09 16:28 ` [PATCH 6/8] parse_fetch: convert to use " brian m. carlson
` (2 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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. Use parse_oid_hex to
avoid having to hard-code the number of bytes to be parsed.
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..f3b89a9 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;
+ int hexlen;
- if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) {
- hashcpy(ref->old_oid.hash, sha1);
- name += 41;
- namelen -= 41;
+ if ((hexlen = parse_oid_hex(name, namelen, &oid)) && namelen > hexlen + 1 &&
+ name[hexlen] == ' ') {
+ oidcpy(&ref->old_oid, &oid);
+ name += hexlen + 1;
+ namelen -= hexlen + 1;
}
memcpy(ref->name, name, namelen);
--
2.4.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 6/8] parse_fetch: convert to use struct object_id
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
` (4 preceding siblings ...)
2015-06-09 16:28 ` [PATCH 5/8] add_sought_entry_mem: convert to struct object_id brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-09 16:28 ` [PATCH 7/8] ref_newer: " brian m. carlson
2015-06-10 22:50 ` [PATCH 0/8] object_id part 2 Junio C Hamano
7 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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. Switch from
get_sha1_hex to parse_oid_hex to avoid hard-coding constants. Remove
the strlen check as parse_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 | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 80cb4c7..46206a0 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -802,19 +802,20 @@ 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;
+ int hexlen;
- if (strlen(p) < 40 || get_sha1_hex(p, old_sha1))
+ if (!(hexlen = parse_oid_hex(p, -1, &old_oid)))
die("protocol error: expected sha/ref, got %s'", p);
- if (p[40] == ' ')
- name = p + 41;
- else if (!p[40])
+ if (p[hexlen] == ' ')
+ name = p + hexlen + 1;
+ else if (!p[hexlen])
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] 23+ messages in thread
* [PATCH 7/8] ref_newer: convert to use struct object_id
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
` (5 preceding siblings ...)
2015-06-09 16:28 ` [PATCH 6/8] parse_fetch: convert to use " brian m. carlson
@ 2015-06-09 16:28 ` brian m. carlson
2015-06-10 22:50 ` [PATCH 0/8] object_id part 2 Junio C Hamano
7 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-09 16:28 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 706d2fb..675cb23 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] 23+ messages in thread
* Re: [PATCH 2/8] sha1_file: introduce has_object_file helper.
2015-06-09 16:28 ` [PATCH 2/8] sha1_file: introduce has_object_file helper brian m. carlson
@ 2015-06-10 9:59 ` Duy Nguyen
2015-06-10 13:55 ` brian m. carlson
0 siblings, 1 reply; 23+ messages in thread
From: Duy Nguyen @ 2015-06-10 9:59 UTC (permalink / raw)
To: brian m. carlson; +Cc: Git Mailing List, Jeff King, Michael Haggerty
On Tue, Jun 9, 2015 at 11:28 PM, brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> diff --git a/sha1_file.c b/sha1_file.c
> index 7e38148..09f7f03 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -3173,6 +3173,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);
> +}
> +
This version could be "static inline" and placed in cache.h. Though it
may be premature optimization. On top of my head I can't recall any
place where has_sha1_file() is used so many times for this extra call
to become significant overhead.
--
Duy
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] sha1_file: introduce has_object_file helper.
2015-06-10 9:59 ` Duy Nguyen
@ 2015-06-10 13:55 ` brian m. carlson
0 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-10 13:55 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List, Jeff King, Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]
On Wed, Jun 10, 2015 at 04:59:58PM +0700, Duy Nguyen wrote:
> On Tue, Jun 9, 2015 at 11:28 PM, brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > diff --git a/sha1_file.c b/sha1_file.c
> > index 7e38148..09f7f03 100644
> > --- a/sha1_file.c
> > +++ b/sha1_file.c
> > @@ -3173,6 +3173,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);
> > +}
> > +
>
> This version could be "static inline" and placed in cache.h. Though it
> may be premature optimization. On top of my head I can't recall any
> place where has_sha1_file() is used so many times for this extra call
> to become significant overhead.
I planned on merging the two into has_object_file when has_sha1_file has
no more callers, so it's more of an incidental artifact that one calls
the other rather than a long-term goal. In the branch I'm working on
now, I'm down to 27 callers, so it may be rather soon that it goes away.
Of course, if the consensus is that the performance increase is worth it
in the mean time, I can certainly just move it back when they merge.
--
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] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
` (6 preceding siblings ...)
2015-06-09 16:28 ` [PATCH 7/8] ref_newer: " brian m. carlson
@ 2015-06-10 22:50 ` Junio C Hamano
2015-06-10 23:51 ` brian m. carlson
7 siblings, 1 reply; 23+ messages in thread
From: Junio C Hamano @ 2015-06-10 22:50 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:
> The final piece 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.
>
> brian m. carlson (8):
> refs: convert some internal functions to use object_id
> sha1_file: introduce has_object_file helper.
> Convert struct ref to use object_id.
> Add a utility function to make parsing hex values easier.
> add_sought_entry_mem: convert to struct object_id
> parse_fetch: convert to use struct object_id
> ref_newer: convert to use struct object_id
> Convert struct object to object_id
It seems that the last one didn't make it...
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-10 22:50 ` [PATCH 0/8] object_id part 2 Junio C Hamano
@ 2015-06-10 23:51 ` brian m. carlson
2015-06-11 0:02 ` brian m. carlson
0 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-10 23:51 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 592 bytes --]
On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> > Convert struct object to object_id
>
> It seems that the last one didn't make it...
It appears the mail was too large for vger. Unfortunately for
bisectability reasons, it is necessarily large. I'll resubmit the patch
with less context.
--
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] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-10 23:51 ` brian m. carlson
@ 2015-06-11 0:02 ` brian m. carlson
2015-06-11 0:21 ` Junio C Hamano
0 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-11 0:02 UTC (permalink / raw)
To: Junio C Hamano, git, Jeff King,
Nguyễn Thái Ngọc Duy, Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 990 bytes --]
On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:
> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:
> > "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> > > Convert struct object to object_id
> >
> > It seems that the last one didn't make it...
>
> It appears the mail was too large for vger. Unfortunately for
> bisectability reasons, it is necessarily large. I'll resubmit the patch
> with less context.
Unfortunately, the only patch I can generate that falls under to 100 KB
limit is with -U0, which isn't very useful. How do you want to proceed?
The branch is available at [0], or I can send the -U0 patch, or I can
split it into unbisectable pieces.
[0] https://github.com/bk2204/git.git object-id-part2
--
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] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-11 0:02 ` brian m. carlson
@ 2015-06-11 0:21 ` Junio C Hamano
2015-06-11 3:31 ` brian m. carlson
2015-06-11 20:00 ` Junio C Hamano
0 siblings, 2 replies; 23+ messages in thread
From: Junio C Hamano @ 2015-06-11 0:21 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:
> On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:
>> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:
>> > "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>> > > Convert struct object to object_id
>> >
>> > It seems that the last one didn't make it...
>>
>> It appears the mail was too large for vger. Unfortunately for
>> bisectability reasons, it is necessarily large. I'll resubmit the patch
>> with less context.
>
> Unfortunately, the only patch I can generate that falls under to 100 KB
> limit is with -U0, which isn't very useful. How do you want to proceed?
> The branch is available at [0], or I can send the -U0 patch, or I can
> split it into unbisectable pieces.
>
> [0] https://github.com/bk2204/git.git object-id-part2
No approach other than just letting reviewers fetch from there and
taking a look is reasonable, I would think.
Did you create this manually, or is it a mechanical scripted rewrite
followed by manual clean-up? If the latter, it may help people by
posting the mechanical recipe _and_ a patch that shows the manual
clean-up. That is something we can reasonably review and discuss.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-11 0:21 ` Junio C Hamano
@ 2015-06-11 3:31 ` brian m. carlson
2015-06-11 20:00 ` Junio C Hamano
1 sibling, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-11 3:31 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 1656 bytes --]
On Wed, Jun 10, 2015 at 05:21:33PM -0700, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> > [0] https://github.com/bk2204/git.git object-id-part2
>
> No approach other than just letting reviewers fetch from there and
> taking a look is reasonable, I would think.
>
> Did you create this manually, or is it a mechanical scripted rewrite
> followed by manual clean-up? If the latter, it may help people by
> posting the mechanical recipe _and_ a patch that shows the manual
> clean-up. That is something we can reasonably review and discuss.
It's mostly manual, but some pieces (the is_null_sha1 and sha1_to_hex
conversions) were scripted using the embedded Ruby interpreter in Vim.
The script I used to do that is below.
def refactor(s)
methods = %w(is_null_sha1 sha1_to_hex).map do |m|
[m, m.sub('sha1', 'oid')]
end.to_h
s.sub(/\A(.*)(is_null_sha1|sha1_to_hex)\(([^)]+)(\.|->)sha1\)(.*)\z/) do
[$1, methods[$2], "(&#{$3}#{$4}oid)", $5].join('')
end
end
def replace_line(method)
func = Object.method(method)
VIM::Buffer.current.line = func.call(VIM::Buffer.current.line)
end
It was invoked as replace_line(:refactor), so it basically modified each
relevant line by passing it through refactor.
Sorry for choosing a language that's less familiar to the list: if I had
known you'd want to see it, I would have used Perl.
--
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] 23+ messages in thread
* Re: [PATCH 3/8] Convert struct ref to use object_id.
2015-06-09 16:28 ` [PATCH 3/8] Convert struct ref to use object_id brian m. carlson
@ 2015-06-11 15:41 ` Michael Haggerty
0 siblings, 0 replies; 23+ messages in thread
From: Michael Haggerty @ 2015-06-11 15:41 UTC (permalink / raw)
To: brian m. carlson, git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy
I visually inspected patches 1 and 2 without finding any problems.
Regarding this patch, I saw a few functions where you could convert
local variables to "struct object_id" and then change function calls
like hashcpy() to oidcpy(). See below. I'm not sure if it makes sense to
do that in this same patch.
For that matter, it seems to me that it should be possible to change
*all* local
unsigned char $variable[20];
to
struct object_id $variable;
without having to change any external interfaces. I wonder whether it
would be advisable to make that change early in this transition? It
would have the advantage that during later refactorings, where, e.g., a
function needs a "struct object_id *" parameter, you would often already
have one handy.
Michael
On 06/09/2015 06:28 PM, brian m. carlson wrote:
> 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/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;
> }
Variable "sha1" in this function could become "struct object_id".
> [...]
> 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;
old_sha1 in this function could become "struct object_id". Also, this
function has a few "20" and "41" and "42" hard-coded literals.
> [...]
> diff --git a/remote-curl.c b/remote-curl.c
> index af7b678..80cb4c7 100644
> --- a/remote-curl.c
> +++ b/remote-curl.c
> [...]
> @@ -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;
old_sha1 in this code block could be converted to "struct object_id".
> diff --git a/remote.c b/remote.c
> index 26504b7..706d2fb 100644
> --- a/remote.c
> +++ b/remote.c
> [...]
> @@ -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;
> }
The "sha1" variable in this function could become a "struct object_id".
> [...]
> @@ -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);
> + hashcpy(ref->new_oid.hash, oid->hash);
This could become oidcopy().
> memcpy(ref->name, refname, len);
> **local_tail = ref;
> *local_tail = &ref->next;
> [...]
> diff --git a/transport-helper.c b/transport-helper.c
> index 5d99a6b..4ca3e80 100644
> --- a/transport-helper.c
> +++ b/transport-helper.c
> [...]
> @@ -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);
>
sha1 in this function could become "struct object_id".
> [...]
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/8] Add a utility function to make parsing hex values easier.
2015-06-09 16:28 ` [PATCH 4/8] Add a utility function to make parsing hex values easier brian m. carlson
@ 2015-06-11 16:09 ` Michael Haggerty
0 siblings, 0 replies; 23+ messages in thread
From: Michael Haggerty @ 2015-06-11 16:09 UTC (permalink / raw)
To: brian m. carlson, git; +Cc: Jeff King, Nguyễn Thái Ngọc Duy
On 06/09/2015 06:28 PM, brian m. carlson wrote:
> get_oid_hex is already available for parsing hex object IDs into struct
> object_id, but parsing code still must hard-code the number of bytes
> read. Introduce parse_oid_hex, which accepts an optional length, and
> also returns the number of bytes parsed on success, or 0 on failure.
> This makes it easier for code not to assume fixed values when parsing,
> and to move to larger hash functions in the future.
I have an open mind, but I have the feeling that this will not be a very
handy interface:
* It will usually require a new int variable to catch the return value.
* We don't put assignments within conditional expressions. So often this
will require one line of code to call the function and a second one to
test the return value.
For example, consider how awkward it will be to rewrite code that now
looks like
if (hex && !get_sha1_hex(hex, sha1) && hex[40] == '\n')
You might instead consider the style of interface used by skip_prefix(),
which I've really come to like:
int parse_oid_hex(const char *hex, struct object_id *oid,
const char **out)
{
if (get_sha1_hex(hex, oid->hash))
return -1; /* failure */
if (out)
*out = hex + GIT_SHA1_HEXSZ;
return 0;
}
This function could of course take a "len" parameter too. Note that it
uses our usual convention that success is denoted by returning 0.
With this definition, the above code could be rewritten to (if the old
value of hex is not needed again)
if (hex && !parse_oid_hex(hex, &oid, &hex) && *hex == '\n')
> ---
> cache.h | 9 +++++++++
> hex.c | 7 +++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/cache.h b/cache.h
> index fa1f067..f3b829f 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -1012,6 +1012,15 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
> extern int get_sha1_hex(const char *hex, unsigned char *sha1);
> extern int get_oid_hex(const char *hex, struct object_id *sha1);
>
> +/*
> + * Like get_oid_hex, but accepts an optional length argument, which may be -1
> + * if the string is terminated by a non-hex character. As with get_oid_hex,
> + * reading stops if a NUL is encountered. Returns the number of characters
> + * read (40) on success and 0 on failure. This is designed to be easier to
> + * use for parsing data than get_oid_hex.
> + */
> +extern int parse_oid_hex(const char *hex, int len, struct object_id *oid);
> +
> extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
> extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
> extern int read_ref_full(const char *refname, int resolve_flags,
> diff --git a/hex.c b/hex.c
> index 899b74a..ba196d7 100644
> --- a/hex.c
> +++ b/hex.c
> @@ -61,6 +61,13 @@ int get_oid_hex(const char *hex, struct object_id *oid)
> return get_sha1_hex(hex, oid->hash);
> }
>
> +int parse_oid_hex(const char *hex, int len, struct object_id *oid)
> +{
> + if (len != -1 && len < GIT_SHA1_HEXSZ)
> + return 0;
> + return get_sha1_hex(hex, oid->hash) ? GIT_SHA1_HEXSZ : 0;
> +}
> +
Isn't this return-statement logic backwards? get_sha1_hex() returns 0 on
success, which you would want to convert to 40. This function would want
to return 0 on *error*.
Which is another disadvantage of this style. All the code that called
get_sha1_hex() had to treat 0 as success. With your function they would
have to be inverted to treat 0 as failure. I think this would cause
confusion.
> [...]
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-11 0:21 ` Junio C Hamano
2015-06-11 3:31 ` brian m. carlson
@ 2015-06-11 20:00 ` Junio C Hamano
2015-06-12 20:30 ` brian m. carlson
1 sibling, 1 reply; 23+ messages in thread
From: Junio C Hamano @ 2015-06-11 20:00 UTC (permalink / raw)
To: brian m. carlson
Cc: git, Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
Junio C Hamano <gitster@pobox.com> writes:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
>> On Wed, Jun 10, 2015 at 11:51:14PM +0000, brian m. carlson wrote:
>>> On Wed, Jun 10, 2015 at 03:50:32PM -0700, Junio C Hamano wrote:
>>> > "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>>> > > Convert struct object to object_id
>>> >
>>> > It seems that the last one didn't make it...
>>>
>>> It appears the mail was too large for vger. Unfortunately for
>>> bisectability reasons, it is necessarily large. I'll resubmit the patch
>>> with less context.
>>
>> Unfortunately, the only patch I can generate that falls under to 100 KB
>> limit is with -U0, which isn't very useful. How do you want to proceed?
>> The branch is available at [0], or I can send the -U0 patch, or I can
>> split it into unbisectable pieces.
>>
>> [0] https://github.com/bk2204/git.git object-id-part2
>
> No approach other than just letting reviewers fetch from there and
> taking a look is reasonable, I would think.
Fetched that branch, built and found out that it does not pass the
tests, at least these (there may be others I do not usually run that
are broken by this series; I dunno), so I'll discard what I fetched
for now X-<.
Test Summary Report
-------------------
t5540-http-push-webdav.sh (Wstat: 256 Tests: 19 Failed: 12)
Failed tests: 4-10, 12-15, 17
Non-zero exit status: 1
t5539-fetch-http-shallow.sh (Wstat: 256 Tests: 3 Failed: 2)
Failed tests: 2-3
Non-zero exit status: 1
t5541-http-push-smart.sh (Wstat: 256 Tests: 34 Failed: 27)
Failed tests: 3-17, 22-29, 31-34
Non-zero exit status: 1
t5551-http-fetch-smart.sh (Wstat: 256 Tests: 26 Failed: 17)
Failed tests: 4-14, 16, 19-20, 22, 24-25
Non-zero exit status: 1
t5550-http-fetch-dumb.sh (Wstat: 256 Tests: 29 Failed: 12)
Failed tests: 3, 7-16, 19
Non-zero exit status: 1
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-11 20:00 ` Junio C Hamano
@ 2015-06-12 20:30 ` brian m. carlson
2015-06-12 22:14 ` Junio C Hamano
0 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-12 20:30 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]
On Thu, Jun 11, 2015 at 01:00:04PM -0700, Junio C Hamano wrote:
> Fetched that branch, built and found out that it does not pass the
> tests, at least these (there may be others I do not usually run that
> are broken by this series; I dunno), so I'll discard what I fetched
> for now X-<.
>
> Test Summary Report
> -------------------
> t5540-http-push-webdav.sh (Wstat: 256 Tests: 19 Failed: 12)
> Failed tests: 4-10, 12-15, 17
> Non-zero exit status: 1
> t5539-fetch-http-shallow.sh (Wstat: 256 Tests: 3 Failed: 2)
> Failed tests: 2-3
> Non-zero exit status: 1
> t5541-http-push-smart.sh (Wstat: 256 Tests: 34 Failed: 27)
> Failed tests: 3-17, 22-29, 31-34
> Non-zero exit status: 1
> t5551-http-fetch-smart.sh (Wstat: 256 Tests: 26 Failed: 17)
> Failed tests: 4-14, 16, 19-20, 22, 24-25
> Non-zero exit status: 1
> t5550-http-fetch-dumb.sh (Wstat: 256 Tests: 29 Failed: 12)
> Failed tests: 3, 7-16, 19
> Non-zero exit status: 1
While I did run the tests between each commit, I hadn't noticed they
were failing because I don't have Apache installed on my laptop, so they
were silently skipped. I'll resubmit with that fixed.
--
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] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-12 20:30 ` brian m. carlson
@ 2015-06-12 22:14 ` Junio C Hamano
2015-06-12 22:27 ` brian m. carlson
0 siblings, 1 reply; 23+ messages in thread
From: Junio C Hamano @ 2015-06-12 22:14 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:
> While I did run the tests between each commit, I hadn't noticed they
> were failing because I don't have Apache installed on my laptop, so they
> were silently skipped. I'll resubmit with that fixed.
It is somewhat strange that _only_ http part had failures like this,
and is unnerving, too, given that a few people seem to have given at
least a cursory read over the patches and didn't spot anything
obviously wrong.
Was that because there was a single manual botch, or was that merely
that other parts of the system do not have sufficient test coverage?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-12 22:14 ` Junio C Hamano
@ 2015-06-12 22:27 ` brian m. carlson
2015-06-13 8:45 ` Michael Haggerty
0 siblings, 1 reply; 23+ messages in thread
From: brian m. carlson @ 2015-06-12 22:27 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Nguyễn Thái Ngọc Duy,
Michael Haggerty
[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]
On Fri, Jun 12, 2015 at 03:14:25PM -0700, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
> > While I did run the tests between each commit, I hadn't noticed they
> > were failing because I don't have Apache installed on my laptop, so they
> > were silently skipped. I'll resubmit with that fixed.
>
> It is somewhat strange that _only_ http part had failures like this,
> and is unnerving, too, given that a few people seem to have given at
> least a cursory read over the patches and didn't spot anything
> obviously wrong.
>
> Was that because there was a single manual botch, or was that merely
> that other parts of the system do not have sufficient test coverage?
It appears that I broke the change in "parse_fetch: convert to use
struct object_id" which modifies remote-curl.c, so I think it's a single
manual botch. I'm going to rework that patch anyway since Michael said
that he didn't like the idea of parse_oid_hex as it stands, so it will
end up being mostly moot.
I mostly introduced it in an effort to avoid having to use
GIT_SHA1_HEXSZ repeatedly throughout small blocks of code, but since we
don't use assignments in conditionals, it doesn't seem useful as it
currently stands.
--
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] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-12 22:27 ` brian m. carlson
@ 2015-06-13 8:45 ` Michael Haggerty
2015-06-13 15:28 ` brian m. carlson
0 siblings, 1 reply; 23+ messages in thread
From: Michael Haggerty @ 2015-06-13 8:45 UTC (permalink / raw)
To: brian m. carlson, Junio C Hamano, git, Jeff King,
Nguyễn Thái Ngọc Duy
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/13/2015 12:27 AM, brian m. carlson wrote:
> On Fri, Jun 12, 2015 at 03:14:25PM -0700, Junio C Hamano wrote:
>> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>>
>>> While I did run the tests between each commit, I hadn't noticed
>>> they were failing because I don't have Apache installed on my
>>> laptop, so they were silently skipped. I'll resubmit with that
>>> fixed.
>>
>> It is somewhat strange that _only_ http part had failures like
>> this, and is unnerving, too, given that a few people seem to have
>> given at least a cursory read over the patches and didn't spot
>> anything obviously wrong.
>>
>> Was that because there was a single manual botch, or was that
>> merely that other parts of the system do not have sufficient test
>> coverage?
>
> It appears that I broke the change in "parse_fetch: convert to use
> struct object_id" which modifies remote-curl.c, so I think it's a
> single manual botch. I'm going to rework that patch anyway since
> Michael said that he didn't like the idea of parse_oid_hex as it
> stands, so it will end up being mostly moot.
In the same email where I made those design suggestions, I also I
pointed out a bug in the implementation of parse_oid_hex(). Maybe that
is the reason for the test failures.
Michael
- --
Michael Haggerty
mhagger@alum.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iEYEARECAAYFAlV77aYACgkQwg9mrRwfmAnCyQCeIp9aSOTtQ1ABpiSybcFQFP87
fNwAoLNhQtyFQ2/fqQIvzl1gGEEOlWxa
=gI7/
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 0/8] object_id part 2
2015-06-13 8:45 ` Michael Haggerty
@ 2015-06-13 15:28 ` brian m. carlson
0 siblings, 0 replies; 23+ messages in thread
From: brian m. carlson @ 2015-06-13 15:28 UTC (permalink / raw)
To: Michael Haggerty
Cc: Junio C Hamano, git, Jeff King,
Nguyễn Thái Ngọc Duy
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
On Sat, Jun 13, 2015 at 10:45:29AM +0200, Michael Haggerty wrote:
> In the same email where I made those design suggestions, I also I
> pointed out a bug in the implementation of parse_oid_hex(). Maybe that
> is the reason for the test failures.
It probably is, although I either botched a conversion in the branch I'm
working on as well, or the area for that code is lacking tests, since I
don't think the tests are failing there. In the latter case, I'll send
a testsuite patch as part of my next series.
--
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] 23+ messages in thread
end of thread, other threads:[~2015-06-13 15:29 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-09 16:28 [PATCH 0/8] object_id part 2 brian m. carlson
2015-06-09 16:28 ` [PATCH 1/8] refs: convert some internal functions to use object_id brian m. carlson
2015-06-09 16:28 ` [PATCH 2/8] sha1_file: introduce has_object_file helper brian m. carlson
2015-06-10 9:59 ` Duy Nguyen
2015-06-10 13:55 ` brian m. carlson
2015-06-09 16:28 ` [PATCH 3/8] Convert struct ref to use object_id brian m. carlson
2015-06-11 15:41 ` Michael Haggerty
2015-06-09 16:28 ` [PATCH 4/8] Add a utility function to make parsing hex values easier brian m. carlson
2015-06-11 16:09 ` Michael Haggerty
2015-06-09 16:28 ` [PATCH 5/8] add_sought_entry_mem: convert to struct object_id brian m. carlson
2015-06-09 16:28 ` [PATCH 6/8] parse_fetch: convert to use " brian m. carlson
2015-06-09 16:28 ` [PATCH 7/8] ref_newer: " brian m. carlson
2015-06-10 22:50 ` [PATCH 0/8] object_id part 2 Junio C Hamano
2015-06-10 23:51 ` brian m. carlson
2015-06-11 0:02 ` brian m. carlson
2015-06-11 0:21 ` Junio C Hamano
2015-06-11 3:31 ` brian m. carlson
2015-06-11 20:00 ` Junio C Hamano
2015-06-12 20:30 ` brian m. carlson
2015-06-12 22:14 ` Junio C Hamano
2015-06-12 22:27 ` brian m. carlson
2015-06-13 8:45 ` Michael Haggerty
2015-06-13 15:28 ` brian m. carlson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).