[PATCH v3 52/53] tree: convert parse_tree_indirect to struct object_id

2017-05-06 Thread brian m. carlson
Convert parse_tree_indirect to take a pointer to struct object_id.
Update all the callers.  This transformation was achieved using the
following semantic patch and manual updates to the declaration and
definition.  Update builtin/checkout.c manually as well, since it uses a
ternary expression not handled by the semantic patch.

@@
expression E1;
@@
- parse_tree_indirect(E1.hash)
+ parse_tree_indirect()

@@
expression E1;
@@
- parse_tree_indirect(E1->hash)
+ parse_tree_indirect(E1)

Signed-off-by: brian m. carlson 
---
 archive.c   | 4 ++--
 builtin/am.c| 6 +++---
 builtin/checkout.c  | 8 
 builtin/clone.c | 2 +-
 builtin/commit.c| 2 +-
 builtin/ls-files.c  | 2 +-
 builtin/ls-tree.c   | 2 +-
 builtin/merge.c | 6 +++---
 builtin/read-tree.c | 2 +-
 builtin/reset.c | 4 ++--
 diff-lib.c  | 2 +-
 merge.c | 4 ++--
 sequencer.c | 2 +-
 t/helper/test-match-trees.c | 4 ++--
 tree.c  | 4 ++--
 tree.h  | 2 +-
 16 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/archive.c b/archive.c
index 54701e8bb..b15a922da 100644
--- a/archive.c
+++ b/archive.c
@@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
archive_time = time(NULL);
}
 
-   tree = parse_tree_indirect(oid.hash);
+   tree = parse_tree_indirect();
if (tree == NULL)
die("not a tree object");
 
@@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
if (err || !S_ISDIR(mode))
die("current working directory is untracked");
 
-   tree = parse_tree_indirect(tree_oid.hash);
+   tree = parse_tree_indirect(_oid);
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
diff --git a/builtin/am.c b/builtin/am.c
index 200d9dbed..a2867f347 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2045,11 +2045,11 @@ static int clean_index(const struct object_id *head, 
const struct object_id *rem
struct tree *head_tree, *remote_tree, *index_tree;
struct object_id index;
 
-   head_tree = parse_tree_indirect(head->hash);
+   head_tree = parse_tree_indirect(head);
if (!head_tree)
return error(_("Could not parse object '%s'."), 
oid_to_hex(head));
 
-   remote_tree = parse_tree_indirect(remote->hash);
+   remote_tree = parse_tree_indirect(remote);
if (!remote_tree)
return error(_("Could not parse object '%s'."), 
oid_to_hex(remote));
 
@@ -2061,7 +2061,7 @@ static int clean_index(const struct object_id *head, 
const struct object_id *rem
if (write_cache_as_tree(index.hash, 0, NULL))
return -1;
 
-   index_tree = parse_tree_indirect(index.hash);
+   index_tree = parse_tree_indirect();
if (!index_tree)
return error(_("Could not parse object '%s'."), 
oid_to_hex());
 
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 7f1eeea94..13365fb62 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts 
*opts,
setup_standard_excludes(topts.dir);
}
tree = parse_tree_indirect(old->commit ?
-  old->commit->object.oid.hash :
-  EMPTY_TREE_SHA1_BIN);
+  >commit->object.oid :
+  _tree_oid);
init_tree_desc([0], tree->buffer, tree->size);
-   tree = parse_tree_indirect(new->commit->object.oid.hash);
+   tree = parse_tree_indirect(>commit->object.oid);
init_tree_desc([1], tree->buffer, tree->size);
 
ret = unpack_trees(2, trees, );
@@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char 
**argv,
new->commit = lookup_commit_reference_gently(rev, 1);
if (!new->commit) {
/* not a commit */
-   *source_tree = parse_tree_indirect(rev->hash);
+   *source_tree = parse_tree_indirect(rev);
} else {
parse_commit_or_die(new->commit);
*source_tree = new->commit->tree;
diff --git a/builtin/clone.c b/builtin/clone.c
index 646f28792..da2d3c1ae 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -739,7 +739,7 @@ static int checkout(int submodule_progress)
opts.src_index = _index;
opts.dst_index = _index;
 
-   tree = parse_tree_indirect(oid.hash);
+   tree = parse_tree_indirect();
parse_tree(tree);
init_tree_desc(, tree->buffer, tree->size);
if (unpack_trees(1, , ) < 0)
diff --git a/builtin/commit.c b/builtin/commit.c
index 

[PATCH v3 46/53] builtin/ls-files: convert overlay_tree_on_cache to object_id

2017-05-06 Thread brian m. carlson
This is another caller of parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 builtin/ls-files.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a6c70dbe9..da0ff849f 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -414,14 +414,14 @@ static void prune_cache(const char *prefix, size_t 
prefixlen)
 void overlay_tree_on_cache(const char *tree_name, const char *prefix)
 {
struct tree *tree;
-   unsigned char sha1[20];
+   struct object_id oid;
struct pathspec pathspec;
struct cache_entry *last_stage0 = NULL;
int i;
 
-   if (get_sha1(tree_name, sha1))
+   if (get_oid(tree_name, ))
die("tree-ish %s not found.", tree_name);
-   tree = parse_tree_indirect(sha1);
+   tree = parse_tree_indirect(oid.hash);
if (!tree)
die("bad tree-ish %s", tree_name);
 


[PATCH v3 50/53] diff-lib: convert do_diff_cache to struct object_id

2017-05-06 Thread brian m. carlson
This is needed to convert parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 builtin/am.c|  2 +-
 builtin/blame.c |  6 +++---
 builtin/reset.c |  2 +-
 diff-lib.c  | 12 ++--
 diff.h  |  2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 642d7047d..200d9dbed 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1145,7 +1145,7 @@ static int index_has_changes(struct strbuf *sb)
DIFF_OPT_SET(, EXIT_WITH_STATUS);
if (!sb)
DIFF_OPT_SET(, QUICK);
-   do_diff_cache(head.hash, );
+   do_diff_cache(, );
diffcore_std();
for (i = 0; sb && i < diff_queued_diff.nr; i++) {
if (i)
diff --git a/builtin/blame.c b/builtin/blame.c
index 58bb274d0..e920314a7 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -563,7 +563,7 @@ static struct origin *find_origin(struct scoreboard *sb,
diff_setup_done(_opts);
 
if (is_null_oid(>commit->object.oid))
-   do_diff_cache(parent->tree->object.oid.hash, _opts);
+   do_diff_cache(>tree->object.oid, _opts);
else
diff_tree_sha1(parent->tree->object.oid.hash,
   origin->commit->tree->object.oid.hash,
@@ -633,7 +633,7 @@ static struct origin *find_rename(struct scoreboard *sb,
diff_setup_done(_opts);
 
if (is_null_oid(>commit->object.oid))
-   do_diff_cache(parent->tree->object.oid.hash, _opts);
+   do_diff_cache(>tree->object.oid, _opts);
else
diff_tree_sha1(parent->tree->object.oid.hash,
   origin->commit->tree->object.oid.hash,
@@ -1272,7 +1272,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
DIFF_OPT_SET(_opts, FIND_COPIES_HARDER);
 
if (is_null_oid(>commit->object.oid))
-   do_diff_cache(parent->tree->object.oid.hash, _opts);
+   do_diff_cache(>tree->object.oid, _opts);
else
diff_tree_sha1(parent->tree->object.oid.hash,
   target->commit->tree->object.oid.hash,
diff --git a/builtin/reset.c b/builtin/reset.c
index 0be52fa36..3415dac5d 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -154,7 +154,7 @@ static int read_from_tree(const struct pathspec *pathspec,
opt.format_callback = update_index_from_diff;
opt.format_callback_data = _to_add;
 
-   if (do_diff_cache(tree_oid->hash, ))
+   if (do_diff_cache(tree_oid, ))
return 1;
diffcore_std();
diff_flush();
diff --git a/diff-lib.c b/diff-lib.c
index 52447466b..ee9df0f84 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -478,7 +478,7 @@ static int oneway_diff(const struct cache_entry * const 
*src,
 }
 
 static int diff_cache(struct rev_info *revs,
- const unsigned char *tree_sha1,
+ const struct object_id *tree_oid,
  const char *tree_name,
  int cached)
 {
@@ -486,10 +486,10 @@ static int diff_cache(struct rev_info *revs,
struct tree_desc t;
struct unpack_trees_options opts;
 
-   tree = parse_tree_indirect(tree_sha1);
+   tree = parse_tree_indirect(tree_oid->hash);
if (!tree)
return error("bad tree object %s",
-tree_name ? tree_name : sha1_to_hex(tree_sha1));
+tree_name ? tree_name : oid_to_hex(tree_oid));
memset(, 0, sizeof(opts));
opts.head_idx = 1;
opts.index_only = cached;
@@ -512,7 +512,7 @@ int run_diff_index(struct rev_info *revs, int cached)
struct object_array_entry *ent;
 
ent = revs->pending.objects;
-   if (diff_cache(revs, ent->item->oid.hash, ent->name, cached))
+   if (diff_cache(revs, >item->oid, ent->name, cached))
exit(128);
 
diff_set_mnemonic_prefix(>diffopt, "c/", cached ? "i/" : "w/");
@@ -522,7 +522,7 @@ int run_diff_index(struct rev_info *revs, int cached)
return 0;
 }
 
-int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
+int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
 {
struct rev_info revs;
 
@@ -530,7 +530,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct 
diff_options *opt)
copy_pathspec(_data, >pathspec);
revs.diffopt = *opt;
 
-   if (diff_cache(, tree_sha1, NULL, 1))
+   if (diff_cache(, tree_oid, NULL, 1))
exit(128);
return 0;
 }
diff --git a/diff.h b/diff.h
index 5be1ee77a..d75e6d15e 100644
--- a/diff.h
+++ b/diff.h
@@ -354,7 +354,7 @@ extern const char *diff_aligned_abbrev(const struct 
object_id *sha1, int);
 extern int run_diff_files(struct rev_info *revs, unsigned int option);
 extern int run_diff_index(struct rev_info *revs, int 

[PATCH v3 53/53] object: convert parse_object* to take struct object_id

2017-05-06 Thread brian m. carlson
Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id.  Remove the temporary variables inserted
earlier, since they are no longer necessary.  Transform all of the
callers using the following semantic patch:

@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object()

@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)

@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(, E2)

@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)

@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(, E2, E3, E4, E5)

@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)

Signed-off-by: brian m. carlson 
---
 builtin/diff-tree.c  |  2 +-
 builtin/diff.c   |  2 +-
 builtin/fast-export.c|  4 ++--
 builtin/fmt-merge-msg.c  |  4 ++--
 builtin/fsck.c   |  8 
 builtin/grep.c   |  2 +-
 builtin/index-pack.c |  3 ++-
 builtin/log.c|  2 +-
 builtin/name-rev.c   |  6 +++---
 builtin/prune.c  |  3 ++-
 builtin/receive-pack.c   |  6 +++---
 builtin/reflog.c |  2 +-
 builtin/rev-list.c   |  2 +-
 builtin/unpack-objects.c |  3 ++-
 bundle.c | 10 ++
 commit.c |  4 ++--
 fetch-pack.c | 14 +++---
 fsck.c   |  2 +-
 http-backend.c   |  2 +-
 http-push.c  |  4 ++--
 log-tree.c   |  6 +++---
 merge-recursive.c|  2 +-
 object.c | 44 +++-
 object.h |  8 
 pack-bitmap.c|  4 ++--
 pretty.c |  2 +-
 reachable.c  |  4 ++--
 ref-filter.c |  4 ++--
 reflog-walk.c|  4 ++--
 refs/files-backend.c |  2 +-
 remote.c |  4 ++--
 revision.c   | 12 ++--
 server-info.c|  2 +-
 sha1_name.c  | 14 +++---
 tag.c|  4 ++--
 tree.c   |  4 ++--
 upload-pack.c|  8 
 walker.c |  2 +-
 38 files changed, 107 insertions(+), 108 deletions(-)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 95b8d1ba7..5ea1c1431 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line)
line[len-1] = 0;
if (parse_oid_hex(line, , ))
return -1;
-   obj = parse_object(oid.hash);
+   obj = parse_object();
if (!obj)
return -1;
if (obj->type == OBJ_COMMIT)
diff --git a/builtin/diff.c b/builtin/diff.c
index 895f92897..8c03ddaf5 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
const char *name = entry->name;
int flags = (obj->flags & UNINTERESTING);
if (!obj->parsed)
-   obj = parse_object(obj->oid.hash);
+   obj = parse_object(>oid);
obj = deref_tag(obj, NULL, 0);
if (!obj)
die(_("invalid object '%s' given."), name);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index ae36b14db..969550531 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
die ("Could not read blob %s", oid_to_hex(oid));
if (check_sha1_signature(oid->hash, buf, size, typename(type)) 
< 0)
die("sha1 mismatch in blob %s", oid_to_hex(oid));
-   object = parse_object_buffer(oid->hash, type, size, buf, 
);
+   object = parse_object_buffer(oid, type, size, buf, );
}
 
if (!object)
@@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry 
*e, char *full_name)
 
/* handle nested tags */
while (tag && tag->object.type == OBJ_TAG) {
-   parse_object(tag->object.oid.hash);
+   parse_object(>object.oid);
string_list_append(_refs, full_name)->util = tag;
tag = (struct tag *)tag->tagged;
}
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 91dd753dd..70137b0b7 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -341,7 +341,7 @@ static void shortlog(const char *name,
const struct object_id *oid = _data->oid;
int limit = opts->shortlog_len;
 
-   branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), 
GIT_SHA1_HEXSZ);
+   branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
if (!branch || 

[PATCH v3 51/53] sequencer: convert do_recursive_merge to struct object_id

2017-05-06 Thread brian m. carlson
This conversion is required to convert parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 sequencer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index dcc56a2b6..adcc0a953 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -426,7 +426,7 @@ void append_conflicts_hint(struct strbuf *msgbuf)
 
 static int do_recursive_merge(struct commit *base, struct commit *next,
  const char *base_label, const char *next_label,
- unsigned char *head, struct strbuf *msgbuf,
+ struct object_id *head, struct strbuf *msgbuf,
  struct replay_opts *opts)
 {
struct merge_options o;
@@ -446,7 +446,7 @@ static int do_recursive_merge(struct commit *base, struct 
commit *next,
if (is_rebase_i(opts))
o.buffer_output = 2;
 
-   head_tree = parse_tree_indirect(head);
+   head_tree = parse_tree_indirect(head->hash);
next_tree = next ? next->tree : empty_tree();
base_tree = base ? base->tree : empty_tree();
 
@@ -1081,7 +1081,7 @@ static int do_pick_commit(enum todo_command command, 
struct commit *commit,
res = -1;
else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || 
command == TODO_REVERT) {
res = do_recursive_merge(base, next, base_label, next_label,
-head.hash, , opts);
+, , opts);
if (res < 0)
return res;
res |= write_message(msgbuf.buf, msgbuf.len,


[PATCH v3 49/53] builtin/ls-tree: convert to struct object_id

2017-05-06 Thread brian m. carlson
This is a prerequisite to convert do_diff_cache, which is required to
convert parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 builtin/ls-tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index d7ebeb4ce..5baac3ef2 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -119,7 +119,7 @@ static int show_tree(const unsigned char *sha1, struct 
strbuf *base,
 
 int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct tree *tree;
int i, full_tree = 0;
const struct option ls_tree_options[] = {
@@ -164,7 +164,7 @@ int cmd_ls_tree(int argc, const char **argv, const char 
*prefix)
 
if (argc < 1)
usage_with_options(ls_tree_usage, ls_tree_options);
-   if (get_sha1(argv[0], sha1))
+   if (get_oid(argv[0], ))
die("Not a valid object name %s", argv[0]);
 
/*
@@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char 
*prefix)
for (i = 0; i < pathspec.nr; i++)
pathspec.items[i].nowildcard_len = pathspec.items[i].len;
pathspec.has_wildcard = 0;
-   tree = parse_tree_indirect(sha1);
+   tree = parse_tree_indirect(oid.hash);
if (!tree)
die("not a tree object");
return !!read_tree_recursive(tree, "", 0, 0, , show_tree, 
NULL);


[PATCH v3 44/53] sha1_name: convert internals of peel_onion to object_id

2017-05-06 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 sha1_name.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index b7e09ac13..72e72ab9a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -798,7 +798,7 @@ struct object *peel_to_type(const char *name, int namelen,
 static int peel_onion(const char *name, int len, unsigned char *sha1,
  unsigned lookup_flags)
 {
-   unsigned char outer[20];
+   struct object_id outer;
const char *sp;
unsigned int expected_type = 0;
struct object *o;
@@ -846,10 +846,10 @@ static int peel_onion(const char *name, int len, unsigned 
char *sha1,
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH;
 
-   if (get_sha1_1(name, sp - name - 2, outer, lookup_flags))
+   if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
return -1;
 
-   o = parse_object(outer);
+   o = parse_object(outer.hash);
if (!o)
return -1;
if (!expected_type) {


[PATCH v3 29/53] Convert lookup_blob to struct object_id

2017-05-06 Thread brian m. carlson
Convert lookup_blob to take a pointer to struct object_id.

The commit was created with manual changes to blob.c and blob.h, plus
the following semantic patch:

@@
expression E1;
@@
- lookup_blob(E1.hash)
+ lookup_blob()

@@
expression E1;
@@
- lookup_blob(E1->hash)
+ lookup_blob(E1)

Signed-off-by: brian m. carlson 
---
 blob.c   | 6 +++---
 blob.h   | 2 +-
 builtin/fast-export.c| 2 +-
 builtin/fsck.c   | 2 +-
 builtin/index-pack.c | 2 +-
 builtin/merge-tree.c | 2 +-
 builtin/unpack-objects.c | 2 +-
 fsck.c   | 2 +-
 http-push.c  | 2 +-
 list-objects.c   | 2 +-
 object.c | 4 ++--
 reachable.c  | 2 +-
 revision.c   | 4 ++--
 tag.c| 2 +-
 walker.c | 2 +-
 15 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/blob.c b/blob.c
index 1fcb8e44b..fa2ab4f7a 100644
--- a/blob.c
+++ b/blob.c
@@ -3,11 +3,11 @@
 
 const char *blob_type = "blob";
 
-struct blob *lookup_blob(const unsigned char *sha1)
+struct blob *lookup_blob(const struct object_id *oid)
 {
-   struct object *obj = lookup_object(sha1);
+   struct object *obj = lookup_object(oid->hash);
if (!obj)
-   return create_object(sha1, alloc_blob_node());
+   return create_object(oid->hash, alloc_blob_node());
return object_as_type(obj, OBJ_BLOB, 0);
 }
 
diff --git a/blob.h b/blob.h
index 59b394eea..446061683 100644
--- a/blob.h
+++ b/blob.h
@@ -9,7 +9,7 @@ struct blob {
struct object object;
 };
 
-struct blob *lookup_blob(const unsigned char *sha1);
+struct blob *lookup_blob(const struct object_id *oid);
 
 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
 
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index b4521cb62..ae36b14db 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -232,7 +232,7 @@ static void export_blob(const struct object_id *oid)
 
if (anonymize) {
buf = anonymize_blob();
-   object = (struct object *)lookup_blob(oid->hash);
+   object = (struct object *)lookup_blob(oid);
eaten = 0;
} else {
buf = read_sha1_file(oid->hash, , );
diff --git a/builtin/fsck.c b/builtin/fsck.c
index c40e14de6..2f67e8217 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -781,7 +781,7 @@ int cmd_fsck(int argc, const char **argv, const char 
*prefix)
mode = active_cache[i]->ce_mode;
if (S_ISGITLINK(mode))
continue;
-   blob = lookup_blob(active_cache[i]->oid.hash);
+   blob = lookup_blob(_cache[i]->oid);
if (!blob)
continue;
obj = >object;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2241ee68e..b75133f62 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -829,7 +829,7 @@ static void sha1_object(const void *data, struct 
object_entry *obj_entry,
if (strict) {
read_lock();
if (type == OBJ_BLOB) {
-   struct blob *blob = lookup_blob(oid->hash);
+   struct blob *blob = lookup_blob(oid);
if (blob)
blob->object.flags |= FLAG_CHECKED;
else
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index cdeb6562d..bad6735c7 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -168,7 +168,7 @@ static struct merge_list *create_entry(unsigned stage, 
unsigned mode, const stru
res->stage = stage;
res->path = path;
res->mode = mode;
-   res->blob = lookup_blob(oid->hash);
+   res->blob = lookup_blob(oid);
return res;
 }
 
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 3dc5e5691..7d5efa2b3 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -249,7 +249,7 @@ static void write_object(unsigned nr, enum object_type type,
added_object(nr, type, buf, size);
free(buf);
 
-   blob = lookup_blob(obj_list[nr].oid.hash);
+   blob = lookup_blob(_list[nr].oid);
if (blob)
blob->object.flags |= FLAG_WRITTEN;
else
diff --git a/fsck.c b/fsck.c
index e6152e4e6..ab3016c0e 100644
--- a/fsck.c
+++ b/fsck.c
@@ -365,7 +365,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, 
struct fsck_options *op
result = options->walk(obj, OBJ_TREE, data, options);
}
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
-   obj = _blob(entry.oid->hash)->object;
+   obj = _blob(entry.oid)->object;
if 

[PATCH v3 31/53] builtin/reflog: convert tree_is_complete to take struct object_id

2017-05-06 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 builtin/reflog.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 4831116ea..7866a0341 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -55,14 +55,14 @@ struct collect_reflog_cb {
 #define STUDYING   (1u<<11)
 #define REACHABLE  (1u<<12)
 
-static int tree_is_complete(const unsigned char *sha1)
+static int tree_is_complete(const struct object_id *oid)
 {
struct tree_desc desc;
struct name_entry entry;
int complete;
struct tree *tree;
 
-   tree = lookup_tree(sha1);
+   tree = lookup_tree(oid->hash);
if (!tree)
return 0;
if (tree->object.flags & SEEN)
@@ -73,7 +73,7 @@ static int tree_is_complete(const unsigned char *sha1)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
-   void *data = read_sha1_file(sha1, , );
+   void *data = read_sha1_file(oid->hash, , );
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
@@ -85,7 +85,7 @@ static int tree_is_complete(const unsigned char *sha1)
complete = 1;
while (tree_entry(, )) {
if (!has_sha1_file(entry.oid->hash) ||
-   (S_ISDIR(entry.mode) && 
!tree_is_complete(entry.oid->hash))) {
+   (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) {
tree->object.flags |= INCOMPLETE;
complete = 0;
}
@@ -152,7 +152,7 @@ static int commit_is_complete(struct commit *commit)
for (i = 0; i < found.nr; i++) {
struct commit *c =
(struct commit *)found.objects[i].item;
-   if (!tree_is_complete(c->tree->object.oid.hash)) {
+   if (!tree_is_complete(>tree->object.oid)) {
is_incomplete = 1;
c->object.flags |= INCOMPLETE;
}


[PATCH v3 40/53] http-push: convert process_ls_object and descendants to object_id

2017-05-06 Thread brian m. carlson
Rename one function to reflect that it now uses struct object_id.  This
conversion is a prerequisite for converting parse_object.

Note that while the use of a buffer that is exactly forty bytes long
looks questionable, get_oid_hex reads exactly the right number of bytes
and does not require the data to be NUL-terminated.

Signed-off-by: brian m. carlson 
---
 http-push.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/http-push.c b/http-push.c
index 7781f4078..4e7bd9e42 100644
--- a/http-push.c
+++ b/http-push.c
@@ -718,13 +718,13 @@ static int fetch_indices(void)
return ret;
 }
 
-static void one_remote_object(const unsigned char *sha1)
+static void one_remote_object(const struct object_id *oid)
 {
struct object *obj;
 
-   obj = lookup_object(sha1);
+   obj = lookup_object(oid->hash);
if (!obj)
-   obj = parse_object(sha1);
+   obj = parse_object(oid->hash);
 
/* Ignore remote objects that don't exist locally */
if (!obj)
@@ -1013,26 +1013,26 @@ static void remote_ls(const char *path, int flags,
  void *userData);
 
 /* extract hex from sharded "xx/x{40}" filename */
-static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1)
+static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
 {
-   char hex[40];
+   char hex[GIT_MAX_HEXSZ];
 
-   if (strlen(path) != 41)
+   if (strlen(path) != GIT_SHA1_HEXSZ + 1)
return -1;
 
memcpy(hex, path, 2);
path += 2;
path++; /* skip '/' */
-   memcpy(hex, path, 38);
+   memcpy(hex, path, GIT_SHA1_HEXSZ - 2);
 
-   return get_sha1_hex(hex, sha1);
+   return get_oid_hex(hex, oid);
 }
 
 static void process_ls_object(struct remote_ls_ctx *ls)
 {
unsigned int *parent = (unsigned int *)ls->userData;
const char *path = ls->dentry_name;
-   unsigned char sha1[20];
+   struct object_id oid;
 
if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) {
remote_dir_exists[*parent] = 1;
@@ -1040,10 +1040,10 @@ static void process_ls_object(struct remote_ls_ctx *ls)
}
 
if (!skip_prefix(path, "objects/", ) ||
-   get_sha1_hex_from_objpath(path, sha1))
+   get_oid_hex_from_objpath(path, ))
return;
 
-   one_remote_object(sha1);
+   one_remote_object();
 }
 
 static void process_ls_ref(struct remote_ls_ctx *ls)


[PATCH v3 30/53] tree: convert read_tree_1 to use struct object_id internally

2017-05-06 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 tree.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tree.c b/tree.c
index 33fa7ee71..21fd80b80 100644
--- a/tree.c
+++ b/tree.c
@@ -58,7 +58,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 {
struct tree_desc desc;
struct name_entry entry;
-   unsigned char sha1[20];
+   struct object_id oid;
int len, oldlen = base->len;
enum interesting retval = entry_not_interesting;
 
@@ -87,7 +87,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
}
 
if (S_ISDIR(entry.mode))
-   hashcpy(sha1, entry.oid->hash);
+   oidcpy(, entry.oid);
else if (S_ISGITLINK(entry.mode)) {
struct commit *commit;
 
@@ -102,7 +102,7 @@ static int read_tree_1(struct tree *tree, struct strbuf 
*base,
oid_to_hex(entry.oid),
base->buf, entry.path);
 
-   hashcpy(sha1, commit->tree->object.oid.hash);
+   oidcpy(, >tree->object.oid);
}
else
continue;
@@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf 
*base,
len = tree_entry_len();
strbuf_add(base, entry.path, len);
strbuf_addch(base, '/');
-   retval = read_tree_1(lookup_tree(sha1),
+   retval = read_tree_1(lookup_tree(oid.hash),
 base, stage, pathspec,
 fn, context);
strbuf_setlen(base, oldlen);


[PATCH v3 47/53] sequencer: convert fast_forward_to to struct object_id

2017-05-06 Thread brian m. carlson
fast_forward_to is required for checkout_fast_fowrard, which is required
for parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 sequencer.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 218895fde..9ca352ac7 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -374,7 +374,7 @@ static void update_abort_safety_file(void)
write_file(git_path_abort_safety_file(), "%s", "");
 }
 
-static int fast_forward_to(const unsigned char *to, const unsigned char *from,
+static int fast_forward_to(const struct object_id *to, const struct object_id 
*from,
int unborn, struct replay_opts *opts)
 {
struct ref_transaction *transaction;
@@ -382,7 +382,7 @@ static int fast_forward_to(const unsigned char *to, const 
unsigned char *from,
struct strbuf err = STRBUF_INIT;
 
read_cache();
-   if (checkout_fast_forward(from, to, 1))
+   if (checkout_fast_forward(from->hash, to->hash, 1))
return -1; /* the callee should have complained already */
 
strbuf_addf(, _("%s: fast-forward"), _(action_name(opts)));
@@ -390,7 +390,7 @@ static int fast_forward_to(const unsigned char *to, const 
unsigned char *from,
transaction = ref_transaction_begin();
if (!transaction ||
ref_transaction_update(transaction, "HEAD",
-  to, unborn ? null_sha1 : from,
+  to->hash, unborn ? null_sha1 : from->hash,
   0, sb.buf, ) ||
ref_transaction_commit(transaction, )) {
ref_transaction_free(transaction);
@@ -935,7 +935,7 @@ static int do_pick_commit(enum todo_command command, struct 
commit *commit,
 {
unsigned int flags = opts->edit ? EDIT_MSG : 0;
const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
-   unsigned char head[20];
+   struct object_id head;
struct commit *base, *next, *parent;
const char *base_label, *next_label;
struct commit_message msg = { NULL, NULL, NULL, NULL };
@@ -949,12 +949,12 @@ static int do_pick_commit(enum todo_command command, 
struct commit *commit,
 * that represents the "current" state for merge-recursive
 * to work on.
 */
-   if (write_cache_as_tree(head, 0, NULL))
+   if (write_cache_as_tree(head.hash, 0, NULL))
return error(_("your index file is unmerged."));
} else {
-   unborn = get_sha1("HEAD", head);
+   unborn = get_oid("HEAD", );
if (unborn)
-   hashcpy(head, EMPTY_TREE_SHA1_BIN);
+   oidcpy(, _tree_oid);
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 
0, 0))
return error_dirty_index(opts);
}
@@ -990,11 +990,11 @@ static int do_pick_commit(enum todo_command command, 
struct commit *commit,
oid_to_hex(>object.oid));
 
if (opts->allow_ff && !is_fixup(command) &&
-   ((parent && !hashcmp(parent->object.oid.hash, head)) ||
+   ((parent && !oidcmp(>object.oid, )) ||
 (!parent && unborn))) {
if (is_rebase_i(opts))
write_author_script(msg.message);
-   res = fast_forward_to(commit->object.oid.hash, head, unborn,
+   res = fast_forward_to(>object.oid, , unborn,
opts);
if (res || command != TODO_REWORD)
goto leave;
@@ -1081,7 +1081,7 @@ static int do_pick_commit(enum todo_command command, 
struct commit *commit,
res = -1;
else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || 
command == TODO_REVERT) {
res = do_recursive_merge(base, next, base_label, next_label,
-head, , opts);
+head.hash, , opts);
if (res < 0)
return res;
res |= write_message(msgbuf.buf, msgbuf.len,
@@ -1097,7 +1097,7 @@ static int do_pick_commit(enum todo_command command, 
struct commit *commit,
commit_list_insert(next, );
res |= try_merge_command(opts->strategy,
 opts->xopts_nr, (const char 
**)opts->xopts,
-   common, sha1_to_hex(head), remotes);
+   common, oid_to_hex(), remotes);
free_commit_list(common);
free_commit_list(remotes);
}


[PATCH v3 42/53] revision: convert remaining parse_object callers to object_id

2017-05-06 Thread brian m. carlson
Signed-off-by: brian m. carlson 
---
 revision.c | 44 ++--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/revision.c b/revision.c
index f82c56e1f..80f74bb7b 100644
--- a/revision.c
+++ b/revision.c
@@ -177,23 +177,23 @@ void add_pending_object(struct rev_info *revs,
 
 void add_head_to_pending(struct rev_info *revs)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct object *obj;
-   if (get_sha1("HEAD", sha1))
+   if (get_oid("HEAD", ))
return;
-   obj = parse_object(sha1);
+   obj = parse_object(oid.hash);
if (!obj)
return;
add_pending_object(revs, obj, "HEAD");
 }
 
 static struct object *get_reference(struct rev_info *revs, const char *name,
-   const unsigned char *sha1,
+   const struct object_id *oid,
unsigned int flags)
 {
struct object *object;
 
-   object = parse_object(sha1);
+   object = parse_object(oid->hash);
if (!object) {
if (revs->ignore_missing)
return object;
@@ -206,7 +206,7 @@ static struct object *get_reference(struct rev_info *revs, 
const char *name,
 void add_pending_oid(struct rev_info *revs, const char *name,
  const struct object_id *oid, unsigned int flags)
 {
-   struct object *object = get_reference(revs, name, oid->hash, flags);
+   struct object *object = get_reference(revs, name, oid, flags);
add_pending_object(revs, object, name);
 }
 
@@ -1157,7 +1157,7 @@ static int handle_one_ref(const char *path, const struct 
object_id *oid,
if (ref_excluded(cb->all_revs->ref_excludes, path))
return 0;
 
-   object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags);
+   object = get_reference(cb->all_revs, path, oid, cb->all_flags);
add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
add_pending_oid(cb->all_revs, path, oid, cb->all_flags);
return 0;
@@ -1292,7 +1292,7 @@ void add_index_objects_to_pending(struct rev_info *revs, 
unsigned flags)
 static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
int exclude_parent)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct object *it;
struct commit *commit;
struct commit_list *parents;
@@ -1303,17 +1303,17 @@ static int add_parents_only(struct rev_info *revs, 
const char *arg_, int flags,
flags ^= UNINTERESTING | BOTTOM;
arg++;
}
-   if (get_sha1_committish(arg, sha1))
+   if (get_sha1_committish(arg, oid.hash))
return 0;
while (1) {
-   it = get_reference(revs, arg, sha1, 0);
+   it = get_reference(revs, arg, , 0);
if (!it && revs->ignore_missing)
return 0;
if (it->type != OBJ_TAG)
break;
if (!((struct tag*)it)->tagged)
return 0;
-   hashcpy(sha1, ((struct tag*)it)->tagged->oid.hash);
+   oidcpy(, &((struct tag*)it)->tagged->oid);
}
if (it->type != OBJ_COMMIT)
return 0;
@@ -1434,7 +1434,7 @@ int handle_revision_arg(const char *arg_, struct rev_info 
*revs, int flags, unsi
struct object_context oc;
char *dotdot;
struct object *object;
-   unsigned char sha1[20];
+   struct object_id oid;
int local_flags;
const char *arg = arg_;
int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
@@ -1444,7 +1444,7 @@ int handle_revision_arg(const char *arg_, struct rev_info 
*revs, int flags, unsi
 
dotdot = strstr(arg, "..");
if (dotdot) {
-   unsigned char from_sha1[20];
+   struct object_id from_oid;
const char *next = dotdot + 2;
const char *this = arg;
int symmetric = *next == '.';
@@ -1470,8 +1470,8 @@ int handle_revision_arg(const char *arg_, struct rev_info 
*revs, int flags, unsi
return -1;
}
}
-   if (!get_sha1_committish(this, from_sha1) &&
-   !get_sha1_committish(next, sha1)) {
+   if (!get_sha1_committish(this, from_oid.hash) &&
+   !get_sha1_committish(next, oid.hash)) {
struct object *a_obj, *b_obj;
 
if (!cant_be_filename) {
@@ -1479,8 +1479,8 @@ int handle_revision_arg(const char *arg_, struct rev_info 
*revs, int flags, unsi
verify_non_filename(revs->prefix, arg);
}
 
-   a_obj = parse_object(from_sha1);
-

[PATCH v3 45/53] builtin/read-tree: convert to struct object_id

2017-05-06 Thread brian m. carlson
This is a caller of parse_tree_indirect, which must be converted in
order to convert parse_object.

Signed-off-by: brian m. carlson 
---
 builtin/read-tree.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 23e212ee8..92eff23e4 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -23,13 +23,13 @@ static int read_empty;
 static struct tree *trees[MAX_UNPACK_TREES];
 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 
-static int list_tree(unsigned char *sha1)
+static int list_tree(struct object_id *oid)
 {
struct tree *tree;
 
if (nr_trees >= MAX_UNPACK_TREES)
die("I cannot read more than %d trees", MAX_UNPACK_TREES);
-   tree = parse_tree_indirect(sha1);
+   tree = parse_tree_indirect(oid->hash);
if (!tree)
return -1;
trees[nr_trees++] = tree;
@@ -121,7 +121,7 @@ static struct lock_file lock_file;
 int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 {
int i, stage = 0;
-   unsigned char sha1[20];
+   struct object_id oid;
struct tree_desc t[MAX_UNPACK_TREES];
struct unpack_trees_options opts;
int prefix_set = 0;
@@ -204,9 +204,9 @@ int cmd_read_tree(int argc, const char **argv, const char 
*unused_prefix)
for (i = 0; i < argc; i++) {
const char *arg = argv[i];
 
-   if (get_sha1(arg, sha1))
+   if (get_oid(arg, ))
die("Not a valid object name %s", arg);
-   if (list_tree(sha1) < 0)
+   if (list_tree() < 0)
die("failed to unpack tree object %s", arg);
stage++;
}


[PATCH v3 48/53] merge: convert checkout_fast_forward to struct object_id

2017-05-06 Thread brian m. carlson
Converting checkout_fast_forward is required to convert
parse_tree_indirect.

Signed-off-by: brian m. carlson 
---
 builtin/merge.c | 4 ++--
 builtin/pull.c  | 4 ++--
 cache.h | 4 ++--
 merge.c | 8 
 sequencer.c | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index f11b5f3de..5ea7f7da9 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1372,8 +1372,8 @@ int cmd_merge(int argc, const char **argv, const char 
*prefix)
goto done;
}
 
-   if (checkout_fast_forward(head_commit->object.oid.hash,
- commit->object.oid.hash,
+   if (checkout_fast_forward(_commit->object.oid,
+ >object.oid,
  overwrite_ignore)) {
ret = 1;
goto done;
diff --git a/builtin/pull.c b/builtin/pull.c
index 2ffb6569a..318c273eb 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -523,7 +523,7 @@ static int pull_into_void(const struct object_id 
*merge_head,
 * index/worktree changes that the user already made on the unborn
 * branch.
 */
-   if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head->hash, 0))
+   if (checkout_fast_forward(_tree_oid, merge_head, 0))
return 1;
 
if (update_ref("initial pull", "HEAD", merge_head->hash, 
curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
@@ -839,7 +839,7 @@ int cmd_pull(int argc, const char **argv, const char 
*prefix)
"fast-forwarding your working tree from\n"
"commit %s."), oid_to_hex(_head));
 
-   if (checkout_fast_forward(orig_head.hash, curr_head.hash, 0))
+   if (checkout_fast_forward(_head, _head, 0))
die(_("Cannot fast-forward your working tree.\n"
"After making sure that you saved anything 
precious from\n"
"$ git diff %s\n"
diff --git a/cache.h b/cache.h
index e1f0e182a..8862510f9 100644
--- a/cache.h
+++ b/cache.h
@@ -2198,8 +2198,8 @@ struct commit_list;
 int try_merge_command(const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(const unsigned char *from,
- const unsigned char *to,
+int checkout_fast_forward(const struct object_id *from,
+ const struct object_id *to,
  int overwrite_ignore);
 
 
diff --git a/merge.c b/merge.c
index 04ee5fc91..b0cffe16f 100644
--- a/merge.c
+++ b/merge.c
@@ -44,8 +44,8 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
return ret;
 }
 
-int checkout_fast_forward(const unsigned char *head,
- const unsigned char *remote,
+int checkout_fast_forward(const struct object_id *head,
+ const struct object_id *remote,
  int overwrite_ignore)
 {
struct tree *trees[MAX_UNPACK_TREES];
@@ -79,10 +79,10 @@ int checkout_fast_forward(const unsigned char *head,
opts.fn = twoway_merge;
setup_unpack_trees_porcelain(, "merge");
 
-   trees[nr_trees] = parse_tree_indirect(head);
+   trees[nr_trees] = parse_tree_indirect(head->hash);
if (!trees[nr_trees++])
return -1;
-   trees[nr_trees] = parse_tree_indirect(remote);
+   trees[nr_trees] = parse_tree_indirect(remote->hash);
if (!trees[nr_trees++])
return -1;
for (i = 0; i < nr_trees; i++) {
diff --git a/sequencer.c b/sequencer.c
index 9ca352ac7..dcc56a2b6 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -382,7 +382,7 @@ static int fast_forward_to(const struct object_id *to, 
const struct object_id *f
struct strbuf err = STRBUF_INIT;
 
read_cache();
-   if (checkout_fast_forward(from->hash, to->hash, 1))
+   if (checkout_fast_forward(from, to, 1))
return -1; /* the callee should have complained already */
 
strbuf_addf(, _("%s: fast-forward"), _(action_name(opts)));


[PATCH v3 37/53] ref-filter: convert some static functions to struct object_id

2017-05-06 Thread brian m. carlson
Among the converted functions is a caller of parse_object_buffer, which
we will convert later.

Signed-off-by: brian m. carlson 
---
 ref-filter.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 77aee273f..56fc990a5 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -677,13 +677,13 @@ int verify_ref_format(const char *format)
  * by the "struct object" representation, set *eaten as well---it is a
  * signal from parse_object_buffer to us not to free the buffer.
  */
-static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned 
long *sz, int *eaten)
+static void *get_obj(const struct object_id *oid, struct object **obj, 
unsigned long *sz, int *eaten)
 {
enum object_type type;
-   void *buf = read_sha1_file(sha1, , sz);
+   void *buf = read_sha1_file(oid->hash, , sz);
 
if (buf)
-   *obj = parse_object_buffer(sha1, type, *sz, buf, eaten);
+   *obj = parse_object_buffer(oid->hash, type, *sz, buf, eaten);
else
*obj = NULL;
return buf;
@@ -1293,7 +1293,7 @@ static void populate_value(struct ref_array_item *ref)
struct object *obj;
int eaten, i;
unsigned long size;
-   const unsigned char *tagged;
+   const struct object_id *tagged;
 
ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
 
@@ -1370,10 +1370,10 @@ static void populate_value(struct ref_array_item *ref)
continue;
} else if (!strcmp(name, "HEAD")) {
const char *head;
-   unsigned char sha1[20];
+   struct object_id oid;
 
head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
- sha1, NULL);
+ oid.hash, NULL);
if (head && !strcmp(ref->refname, head))
v->s = "*";
else
@@ -1415,7 +1415,7 @@ static void populate_value(struct ref_array_item *ref)
return;
 
  need_obj:
-   buf = get_obj(ref->objectname.hash, , , );
+   buf = get_obj(>objectname, , , );
if (!buf)
die(_("missing object %s for %s"),
oid_to_hex(>objectname), ref->refname);
@@ -1438,7 +1438,7 @@ static void populate_value(struct ref_array_item *ref)
 * If it is a tag object, see if we use a value that derefs
 * the object, and if we do grab the object it refers to.
 */
-   tagged = ((struct tag *)obj)->tagged->oid.hash;
+   tagged = &((struct tag *)obj)->tagged->oid;
 
/*
 * NEEDSWORK: This derefs tag only once, which
@@ -1449,10 +1449,10 @@ static void populate_value(struct ref_array_item *ref)
buf = get_obj(tagged, , , );
if (!buf)
die(_("missing object %s for %s"),
-   sha1_to_hex(tagged), ref->refname);
+   oid_to_hex(tagged), ref->refname);
if (!obj)
die(_("parse_object_buffer failed on %s for %s"),
-   sha1_to_hex(tagged), ref->refname);
+   oid_to_hex(tagged), ref->refname);
grab_values(ref->value, 1, obj, buf, size);
if (!eaten)
free(buf);


[PATCH v3 32/53] Convert lookup_tree to struct object_id

2017-05-06 Thread brian m. carlson
Convert the lookup_tree function to take a pointer to struct object_id.

The commit was created with manual changes to tree.c, tree.h, and
object.c, plus the following semantic patch:

@@
@@
- lookup_tree(EMPTY_TREE_SHA1_BIN)
+ lookup_tree(_tree_oid)

@@
expression E1;
@@
- lookup_tree(E1.hash)
+ lookup_tree()

@@
expression E1;
@@
- lookup_tree(E1->hash)
+ lookup_tree(E1)

Signed-off-by: brian m. carlson 
---
 builtin/am.c| 4 ++--
 builtin/diff-tree.c | 2 +-
 builtin/diff.c  | 2 +-
 builtin/reflog.c| 2 +-
 cache-tree.c| 2 +-
 commit.c| 2 +-
 fsck.c  | 2 +-
 http-push.c | 2 +-
 list-objects.c  | 2 +-
 merge-recursive.c   | 6 +++---
 object.c| 2 +-
 reachable.c | 2 +-
 revision.c  | 4 ++--
 sequencer.c | 2 +-
 tag.c   | 2 +-
 tree.c  | 8 
 tree.h  | 2 +-
 walker.c| 2 +-
 18 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 650269ac5..7663f12e6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1453,9 +1453,9 @@ static void write_index_patch(const struct am_state 
*state)
FILE *fp;
 
if (!get_sha1_tree("HEAD", head.hash))
-   tree = lookup_tree(head.hash);
+   tree = lookup_tree();
else
-   tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+   tree = lookup_tree(_tree_oid);
 
fp = xfopen(am_path(state, "patch"), "w");
init_revisions(_info, NULL);
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e85a449df..95b8d1ba7 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
struct tree *tree2;
if (!isspace(*p++) || parse_oid_hex(p, , ) || *p)
return error("Need exactly two trees, separated by a space");
-   tree2 = lookup_tree(oid.hash);
+   tree2 = lookup_tree();
if (!tree2 || parse_tree(tree2))
return -1;
printf("%s %s\n", oid_to_hex(>object.oid),
diff --git a/builtin/diff.c b/builtin/diff.c
index a25b4e4ae..895f92897 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
add_head_to_pending();
if (!rev.pending.nr) {
struct tree *tree;
-   tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+   tree = lookup_tree(_tree_oid);
add_pending_object(, >object, 
"HEAD");
}
break;
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 7866a0341..7e89e84dc 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -62,7 +62,7 @@ static int tree_is_complete(const struct object_id *oid)
int complete;
struct tree *tree;
 
-   tree = lookup_tree(oid->hash);
+   tree = lookup_tree(oid);
if (!tree)
return 0;
if (tree->object.flags & SEEN)
diff --git a/cache-tree.c b/cache-tree.c
index 35d507ed7..489241021 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -672,7 +672,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, 
struct tree *tree)
cnt++;
else {
struct cache_tree_sub *sub;
-   struct tree *subtree = lookup_tree(entry.oid->hash);
+   struct tree *subtree = lookup_tree(entry.oid);
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, entry.path);
diff --git a/commit.c b/commit.c
index 0f6c9b6bf..8004008bc 100644
--- a/commit.c
+++ b/commit.c
@@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void 
*buffer, unsigned long s
if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
return error("bad tree pointer in commit %s",
 oid_to_hex(>object.oid));
-   item->tree = lookup_tree(parent.hash);
+   item->tree = lookup_tree();
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = >parents;
 
diff --git a/fsck.c b/fsck.c
index ab3016c0e..ee5224aea 100644
--- a/fsck.c
+++ b/fsck.c
@@ -358,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, 
struct fsck_options *op
continue;
 
if (S_ISDIR(entry.mode)) {
-   obj = _tree(entry.oid->hash)->object;
+   obj = _tree(entry.oid)->object;
if (name)
put_object_name(options, obj, "%s%s/", name,
entry.path);
diff --git a/http-push.c 

[PATCH v3 34/53] Convert lookup_tag to struct object_id

2017-05-06 Thread brian m. carlson
Convert lookup_tag to take a pointer to struct object_id.

Signed-off-by: brian m. carlson 
---
 builtin/describe.c | 6 +++---
 builtin/pack-objects.c | 2 +-
 builtin/replace.c  | 2 +-
 log-tree.c | 2 +-
 object.c   | 2 +-
 sha1_name.c| 2 +-
 tag.c  | 8 
 tag.h  | 2 +-
 8 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/builtin/describe.c b/builtin/describe.c
index f6032f593..893c8789f 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -79,13 +79,13 @@ static int replace_name(struct commit_name *e,
struct tag *t;
 
if (!e->tag) {
-   t = lookup_tag(e->oid.hash);
+   t = lookup_tag(>oid);
if (!t || parse_tag(t))
return 1;
e->tag = t;
}
 
-   t = lookup_tag(oid->hash);
+   t = lookup_tag(oid);
if (!t || parse_tag(t))
return 0;
*tag = t;
@@ -245,7 +245,7 @@ static unsigned long finish_depth_computation(
 static void display_name(struct commit_name *n)
 {
if (n->prio == 2 && !n->tag) {
-   n->tag = lookup_tag(n->oid.hash);
+   n->tag = lookup_tag(>oid);
if (!n->tag || parse_tag(n->tag))
die(_("annotated tag %s not available"), n->path);
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index d76ff0542..7cebb5a7f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2348,7 +2348,7 @@ static void add_tag_chain(const struct object_id *oid)
if (packlist_find(_pack, oid->hash, NULL))
return;
 
-   tag = lookup_tag(oid->hash);
+   tag = lookup_tag(oid);
while (1) {
if (!tag || parse_tag(tag) || !tag->tagged)
die("unable to pack objects reachable from tag %s",
diff --git a/builtin/replace.c b/builtin/replace.c
index 3c44ef750..c921bc976 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit,
int i;
 
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), 
tag_oid.hash);
-   tag = lookup_tag(tag_oid.hash);
+   tag = lookup_tag(_oid);
if (!tag)
die(_("bad mergetag in commit '%s'"), ref);
if (parse_tag_buffer(tag, extra->value, extra->len))
diff --git a/log-tree.c b/log-tree.c
index 169fd039f..6532c892c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -488,7 +488,7 @@ static void show_one_mergetag(struct commit *commit,
size_t payload_size, gpg_message_offset;
 
hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
-   tag = lookup_tag(oid.hash);
+   tag = lookup_tag();
if (!tag)
return; /* error message already given */
 
diff --git a/object.c b/object.c
index d23c5fad3..dd4d3a1ea 100644
--- a/object.c
+++ b/object.c
@@ -220,7 +220,7 @@ struct object *parse_object_buffer(const unsigned char 
*sha1, enum object_type t
obj = >object;
}
} else if (type == OBJ_TAG) {
-   struct tag *tag = lookup_tag(sha1);
+   struct tag *tag = lookup_tag();
if (tag) {
if (parse_tag_buffer(tag, buffer, size))
   return NULL;
diff --git a/sha1_name.c b/sha1_name.c
index 390a09c41..b7e09ac13 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -361,7 +361,7 @@ static int show_ambiguous_object(const struct object_id 
*oid, void *data)
format_commit_message(commit, " %ad - %s", , );
}
} else if (type == OBJ_TAG) {
-   struct tag *tag = lookup_tag(oid->hash);
+   struct tag *tag = lookup_tag(oid);
if (!parse_tag(tag) && tag->tag)
strbuf_addf(, " %s", tag->tag);
}
diff --git a/tag.c b/tag.c
index 062516b40..571798519 100644
--- a/tag.c
+++ b/tag.c
@@ -89,11 +89,11 @@ struct object *deref_tag_noverify(struct object *o)
return o;
 }
 
-struct tag *lookup_tag(const unsigned char *sha1)
+struct tag *lookup_tag(const struct object_id *oid)
 {
-   struct object *obj = lookup_object(sha1);
+   struct object *obj = lookup_object(oid->hash);
if (!obj)
-   return create_object(sha1, alloc_tag_node());
+   return create_object(oid->hash, alloc_tag_node());
return object_as_type(obj, OBJ_TAG, 0);
 }
 
@@ -148,7 +148,7 @@ int parse_tag_buffer(struct tag *item, const void *data, 
unsigned long size)
} else if (!strcmp(type, commit_type)) {
item->tagged = _commit()->object;
} else if (!strcmp(type, tag_type)) {
-   item->tagged = _tag(oid.hash)->object;
+   

[PATCH v3 43/53] upload-pack: convert remaining parse_object callers to object_id

2017-05-06 Thread brian m. carlson
Convert the remaining parse_object callers to struct object_id.  Use
named constants for several hard-coded values.  In addition, rename
got_sha1 to got_oid to reflect the new argument.

Signed-off-by: brian m. carlson 
---
 upload-pack.c | 50 +-
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/upload-pack.c b/upload-pack.c
index 20f87cd38..5b9d21089 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -286,19 +286,19 @@ static void create_pack_file(void)
die("git upload-pack: %s", abort_msg);
 }
 
-static int got_sha1(const char *hex, unsigned char *sha1)
+static int got_oid(const char *hex, struct object_id *oid)
 {
struct object *o;
int we_knew_they_have = 0;
 
-   if (get_sha1_hex(hex, sha1))
+   if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
-   if (!has_sha1_file(sha1))
+   if (!has_object_file(oid))
return -1;
 
-   o = parse_object(sha1);
+   o = parse_object(oid->hash);
if (!o)
-   die("oops (%s)", sha1_to_hex(sha1));
+   die("oops (%s)", oid_to_hex(oid));
if (o->type == OBJ_COMMIT) {
struct commit_list *parents;
struct commit *commit = (struct commit *)o;
@@ -382,8 +382,8 @@ static int ok_to_give_up(void)
 
 static int get_common_commits(void)
 {
-   unsigned char sha1[20];
-   char last_hex[41];
+   struct object_id oid;
+   char last_hex[GIT_MAX_HEXSZ + 1];
int got_common = 0;
int got_other = 0;
int sent_ready = 0;
@@ -416,11 +416,11 @@ static int get_common_commits(void)
continue;
}
if (skip_prefix(line, "have ", )) {
-   switch (got_sha1(arg, sha1)) {
+   switch (got_oid(arg, )) {
case -1: /* they have what we do not */
got_other = 1;
if (multi_ack && ok_to_give_up()) {
-   const char *hex = sha1_to_hex(sha1);
+   const char *hex = oid_to_hex();
if (multi_ack == 2) {
sent_ready = 1;
packet_write_fmt(1, "ACK %s 
ready\n", hex);
@@ -430,7 +430,7 @@ static int get_common_commits(void)
break;
default:
got_common = 1;
-   memcpy(last_hex, sha1_to_hex(sha1), 41);
+   memcpy(last_hex, oid_to_hex(), 41);
if (multi_ack == 2)
packet_write_fmt(1, "ACK %s common\n", 
last_hex);
else if (multi_ack)
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
goto error;
 
namebuf[0] = '^';
-   namebuf[41] = '\n';
+   namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
for (i = get_max_object_index(); 0 < i; ) {
o = get_indexed_object(--i);
if (!o)
@@ -502,10 +502,10 @@ static int do_reachable_revlist(struct child_process *cmd,
if (!is_our_ref(o))
continue;
memcpy(namebuf + 1, oid_to_hex(>oid), GIT_SHA1_HEXSZ);
-   if (write_in_full(cmd->in, namebuf, 42) < 0)
+   if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
goto error;
}
-   namebuf[40] = '\n';
+   namebuf[GIT_SHA1_HEXSZ] = '\n';
for (i = 0; i < src->nr; i++) {
o = src->objects[i].item;
if (is_our_ref(o)) {
@@ -516,7 +516,7 @@ static int do_reachable_revlist(struct child_process *cmd,
if (reachable && o->type == OBJ_COMMIT)
o->flags |= TMP_MARK;
memcpy(namebuf, oid_to_hex(>oid), GIT_SHA1_HEXSZ);
-   if (write_in_full(cmd->in, namebuf, 41) < 0)
+   if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
goto error;
}
close(cmd->in);
@@ -742,7 +742,7 @@ static void receive_needs(void)
for (;;) {
struct object *o;
const char *features;
-   unsigned char sha1_buf[20];
+   struct object_id oid_buf;
char *line = packet_read_line(0, NULL);
const char *arg;
 
@@ -751,15 +751,15 @@ static void receive_needs(void)
break;
 
if (skip_prefix(line, "shallow ", )) {
-   unsigned char sha1[20];
+   struct object_id oid;
struct object *object;
-   

[PATCH v3 35/53] Convert the verify_pack callback to struct object_id

2017-05-06 Thread brian m. carlson
Make the verify_pack_callback take a pointer to struct object_id.
Change the pack checksum to use GIT_MAX_RAWSZ, even though it is not
strictly an object ID.  Doing so ensures resilience against future hash
size changes, and allows us to remove hard-coded assumptions about how
big the buffer needs to be.

Also, use a union to convert the pointer from nth_packed_object_sha1 to
to a pointer to struct object_id.  This behavior is compatible with GCC
and clang and explicitly sanctioned by C11.  The alternatives are to
just perform a cast, which would run afoul of strict aliasing rules, but
should just work, and changing the pointer into an instance of struct
object_id and copying the value.  The latter operation could seriously
bloat memory usage on fsck, which already uses a lot of memory on some
repositories.

Signed-off-by: brian m. carlson 
---
 builtin/fsck.c |  6 +++---
 pack-check.c   | 25 ++---
 pack.h |  2 +-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 2f67e8217..a187054da 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -377,7 +377,7 @@ static int fsck_obj(struct object *obj)
return 0;
 }
 
-static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
+static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
   unsigned long size, void *buffer, int *eaten)
 {
/*
@@ -385,10 +385,10 @@ static int fsck_obj_buffer(const unsigned char *sha1, 
enum object_type type,
 * verify_packfile(), data_valid variable for details.
 */
struct object *obj;
-   obj = parse_object_buffer(sha1, type, size, buffer, eaten);
+   obj = parse_object_buffer(oid->hash, type, size, buffer, eaten);
if (!obj) {
errors_found |= ERROR_OBJECT;
-   return error("%s: object corrupt or missing", 
sha1_to_hex(sha1));
+   return error("%s: object corrupt or missing", oid_to_hex(oid));
}
obj->flags = HAS_OBJ;
return fsck_obj(obj);
diff --git a/pack-check.c b/pack-check.c
index 27f70d345..e1fcb228f 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -5,7 +5,10 @@
 
 struct idx_entry {
off_toffset;
-   const unsigned char *sha1;
+   union idx_entry_object {
+   const unsigned char *hash;
+   struct object_id *oid;
+   } oid;
unsigned int nr;
 };
 
@@ -51,7 +54,7 @@ static int verify_packfile(struct packed_git *p,
off_t index_size = p->index_size;
const unsigned char *index_base = p->index_data;
git_SHA_CTX ctx;
-   unsigned char sha1[20], *pack_sig;
+   unsigned char hash[GIT_MAX_RAWSZ], *pack_sig;
off_t offset = 0, pack_sig_ofs = 0;
uint32_t nr_objects, i;
int err = 0;
@@ -71,9 +74,9 @@ static int verify_packfile(struct packed_git *p,
remaining -= (unsigned int)(offset - pack_sig_ofs);
git_SHA1_Update(, in, remaining);
} while (offset < pack_sig_ofs);
-   git_SHA1_Final(sha1, );
+   git_SHA1_Final(hash, );
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
-   if (hashcmp(sha1, pack_sig))
+   if (hashcmp(hash, pack_sig))
err = error("%s SHA1 checksum mismatch",
p->pack_name);
if (hashcmp(index_base + index_size - 40, pack_sig))
@@ -90,8 +93,8 @@ static int verify_packfile(struct packed_git *p,
entries[nr_objects].offset = pack_sig_ofs;
/* first sort entries by pack offset, since unpacking them is more 
efficient that way */
for (i = 0; i < nr_objects; i++) {
-   entries[i].sha1 = nth_packed_object_sha1(p, i);
-   if (!entries[i].sha1)
+   entries[i].oid.hash = nth_packed_object_sha1(p, i);
+   if (!entries[i].oid.hash)
die("internal error pack-check nth-packed-object");
entries[i].offset = nth_packed_object_offset(p, i);
entries[i].nr = i;
@@ -112,7 +115,7 @@ static int verify_packfile(struct packed_git *p,
if (check_pack_crc(p, w_curs, offset, len, nr))
err = error("index CRC mismatch for object %s "
"from %s at offset %"PRIuMAX"",
-   sha1_to_hex(entries[i].sha1),
+   oid_to_hex(entries[i].oid.oid),
p->pack_name, (uintmax_t)offset);
}
 
@@ -135,14 +138,14 @@ static int verify_packfile(struct packed_git *p,
 
if (data_valid && !data)
err = error("cannot unpack %s from %s at offset 
%"PRIuMAX"",
-   sha1_to_hex(entries[i].sha1), p->pack_name,
+ 

[PATCH v3 41/53] revision: rename add_pending_sha1 to add_pending_oid

2017-05-06 Thread brian m. carlson
Rename this function and convert it to take a pointer to struct
object_id.

This is a prerequisite for converting get_reference, which is needed to
convert parse_object.

Signed-off-by: brian m. carlson 
---
 builtin/am.c   | 2 +-
 builtin/checkout.c | 4 ++--
 revision.c | 8 
 revision.h | 6 +++---
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 7663f12e6..642d7047d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1618,7 +1618,7 @@ static int fall_back_threeway(const struct am_state 
*state, const char *index_pa
init_revisions(_info, NULL);
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
diff_opt_parse(_info.diffopt, _filter_str, 1, 
rev_info.prefix);
-   add_pending_sha1(_info, "HEAD", our_tree.hash, 0);
+   add_pending_oid(_info, "HEAD", _tree, 0);
diff_setup_done(_info.diffopt);
run_diff_index(_info, 1);
}
diff --git a/builtin/checkout.c b/builtin/checkout.c
index afa99fb8a..7f1eeea94 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -721,7 +721,7 @@ static int add_pending_uninteresting_ref(const char 
*refname,
 const struct object_id *oid,
 int flags, void *cb_data)
 {
-   add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING);
+   add_pending_oid(cb_data, refname, oid, UNINTERESTING);
return 0;
 }
 
@@ -807,7 +807,7 @@ static void orphaned_commit_warning(struct commit *old, 
struct commit *new)
add_pending_object(, object, oid_to_hex(>oid));
 
for_each_ref(add_pending_uninteresting_ref, );
-   add_pending_sha1(, "HEAD", new->object.oid.hash, UNINTERESTING);
+   add_pending_oid(, "HEAD", >object.oid, UNINTERESTING);
 
refs = revs.pending;
revs.leak_pending = 1;
diff --git a/revision.c b/revision.c
index c2091b6de..f82c56e1f 100644
--- a/revision.c
+++ b/revision.c
@@ -203,10 +203,10 @@ static struct object *get_reference(struct rev_info 
*revs, const char *name,
return object;
 }
 
-void add_pending_sha1(struct rev_info *revs, const char *name,
- const unsigned char *sha1, unsigned int flags)
+void add_pending_oid(struct rev_info *revs, const char *name,
+ const struct object_id *oid, unsigned int flags)
 {
-   struct object *object = get_reference(revs, name, sha1, flags);
+   struct object *object = get_reference(revs, name, oid->hash, flags);
add_pending_object(revs, object, name);
 }
 
@@ -1159,7 +1159,7 @@ static int handle_one_ref(const char *path, const struct 
object_id *oid,
 
object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags);
add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
-   add_pending_sha1(cb->all_revs, path, oid->hash, cb->all_flags);
+   add_pending_oid(cb->all_revs, path, oid, cb->all_flags);
return 0;
 }
 
diff --git a/revision.h b/revision.h
index 14886ec92..728425a02 100644
--- a/revision.h
+++ b/revision.h
@@ -263,9 +263,9 @@ extern void show_object_with_name(FILE *, struct object *, 
const char *);
 
 extern void add_pending_object(struct rev_info *revs,
   struct object *obj, const char *name);
-extern void add_pending_sha1(struct rev_info *revs,
-const char *name, const unsigned char *sha1,
-unsigned int flags);
+extern void add_pending_oid(struct rev_info *revs,
+   const char *name, const struct object_id *oid,
+   unsigned int flags);
 
 extern void add_head_to_pending(struct rev_info *);
 extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags);


[PATCH v3 36/53] Convert struct ref_array_item to struct object_id

2017-05-06 Thread brian m. carlson
Convert struct ref_array_item to use struct object_id by changing the
definition and applying the following semantic patch, plus the standard
object_id transforms:

@@
struct ref_array_item E1;
@@
- E1.objectname
+ E1.objectname.hash

@@
struct ref_array_item *E1;
@@
- E1->objectname
+ E1->objectname.hash

This transformation allows us to convert get_obj, which is needed to
convert parse_object_buffer.

Signed-off-by: brian m. carlson 
---
 ref-filter.c | 10 +-
 ref-filter.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index e1d18ac0d..77aee273f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1366,7 +1366,7 @@ static void populate_value(struct ref_array_item *ref)
v->s = xstrdup(buf + 1);
}
continue;
-   } else if (!deref && grab_objectname(name, ref->objectname, v, 
atom)) {
+   } else if (!deref && grab_objectname(name, 
ref->objectname.hash, v, atom)) {
continue;
} else if (!strcmp(name, "HEAD")) {
const char *head;
@@ -1415,13 +1415,13 @@ static void populate_value(struct ref_array_item *ref)
return;
 
  need_obj:
-   buf = get_obj(ref->objectname, , , );
+   buf = get_obj(ref->objectname.hash, , , );
if (!buf)
die(_("missing object %s for %s"),
-   sha1_to_hex(ref->objectname), ref->refname);
+   oid_to_hex(>objectname), ref->refname);
if (!obj)
die(_("parse_object_buffer failed on %s for %s"),
-   sha1_to_hex(ref->objectname), ref->refname);
+   oid_to_hex(>objectname), ref->refname);
 
grab_values(ref->value, 0, obj, buf, size);
if (!eaten)
@@ -1704,7 +1704,7 @@ static struct ref_array_item *new_ref_array_item(const 
char *refname,
 {
struct ref_array_item *ref;
FLEX_ALLOC_STR(ref, refname, refname);
-   hashcpy(ref->objectname, objectname);
+   hashcpy(ref->objectname.hash, objectname);
ref->flag = flag;
 
return ref;
diff --git a/ref-filter.h b/ref-filter.h
index c20167aa3..6552024f0 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -34,7 +34,7 @@ struct ref_sorting {
 };
 
 struct ref_array_item {
-   unsigned char objectname[20];
+   struct object_id objectname;
int flag;
unsigned int kind;
const char *symref;


[PATCH v3 39/53] refs/files-backend: convert many internals to struct object_id

2017-05-06 Thread brian m. carlson
Convert many of the internals of the files backend to use struct
object_id.  Avoid converting public APIs (except one change to
refs/ref-cache.c) to limit the scope of the changes.

Convert one use of get_sha1_hex to parse_oid_hex, and rely on the fact
that a strbuf will be NUL-terminated and that parse_oid_hex will fail on
truncated input to avoid the need to check the length.

This is a requirement to convert parse_object later on.

Signed-off-by: brian m. carlson 
---
 refs/files-backend.c | 128 +++
 refs/ref-cache.c |   4 +-
 refs/ref-cache.h |   2 +-
 3 files changed, 61 insertions(+), 73 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 413505ff0..2c360a410 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -195,27 +195,15 @@ 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;
 
-   /*
-* 42: the answer to everything.
-*
-* In this case, it happens to be the answer to
-*  40 (length of sha1 hex representation)
-*  +1 (space in between hex and name)
-*  +1 (newline at the end of the line)
-*/
-   if (line->len <= 42)
+   if (parse_oid_hex(line->buf, oid, ) < 0)
+   return NULL;
+   if (!isspace(*ref++))
return NULL;
 
-   if (get_sha1_hex(line->buf, sha1) < 0)
-   return NULL;
-   if (!isspace(line->buf[40]))
-   return NULL;
-
-   ref = line->buf + 41;
if (isspace(*ref))
return NULL;
 
@@ -260,7 +248,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(, f, '\n') != EOF) {
-   unsigned char sha1[20];
+   struct object_id oid;
const char *refname;
const char *traits;
 
@@ -273,17 +261,17 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
continue;
}
 
-   refname = parse_ref_line(, sha1);
+   refname = parse_ref_line(, );
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();
flag |= REF_BAD_NAME | REF_ISBROKEN;
}
-   last = create_ref_entry(refname, sha1, flag, 0);
+   last = create_ref_entry(refname, , flag, 0);
if (peeled == PEELED_FULLY ||
(peeled == PEELED_TAGS && starts_with(refname, 
"refs/tags/")))
last->flag |= REF_KNOWS_PEELED;
@@ -294,8 +282,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, )) {
+   oidcpy(>u.value.peeled, );
/*
 * Regardless of what the file header said,
 * we definitely know the value of *this*
@@ -404,14 +392,14 @@ static struct ref_dir *get_packed_refs(struct 
files_ref_store *refs)
  * commit_packed_refs().
  */
 static void add_packed_ref(struct files_ref_store *refs,
-  const char *refname, const unsigned char *sha1)
+  const char *refname, const struct object_id *oid)
 {
struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs);
 
if (!packed_ref_cache->lock)
die("internal error: packed refs not locked");
add_ref_entry(get_packed_ref_dir(packed_ref_cache),
- create_ref_entry(refname, sha1, REF_ISPACKED, 1));
+ create_ref_entry(refname, oid, REF_ISPACKED, 1));
 }
 
 /*
@@ -444,7 +432,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
strbuf_add(, dirname, dirnamelen);
 
while ((de = readdir(d)) != NULL) {
-   unsigned char sha1[20];
+   struct object_id oid;
struct stat st;
int 

[PATCH v3 38/53] refs: convert struct ref_update to use struct object_id

2017-05-06 Thread brian m. carlson
Convert struct ref_array_item to use struct object_id by changing the
definition and applying the following semantic patch, plus the standard
object_id transforms:

@@
struct ref_update E1;
@@
- E1.new_sha1
+ E1.new_oid.hash

@@
struct ref_update *E1;
@@
- E1->new_sha1
+ E1->new_oid.hash

@@
struct ref_update E1;
@@
- E1.old_sha1
+ E1.old_oid.hash

@@
struct ref_update *E1;
@@
- E1->old_sha1
+ E1->old_oid.hash

This transformation allows us to convert write_ref_to_lockfile, which is
required to convert parse_object.

Signed-off-by: brian m. carlson 
---
 refs.c   |  4 ++--
 refs/files-backend.c | 29 +++--
 refs/refs-internal.h |  4 ++--
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/refs.c b/refs.c
index df75f8e0d..c738f5911 100644
--- a/refs.c
+++ b/refs.c
@@ -882,9 +882,9 @@ struct ref_update *ref_transaction_add_update(
update->flags = flags;
 
if (flags & REF_HAVE_NEW)
-   hashcpy(update->new_sha1, new_sha1);
+   hashcpy(update->new_oid.hash, new_sha1);
if (flags & REF_HAVE_OLD)
-   hashcpy(update->old_sha1, old_sha1);
+   hashcpy(update->old_oid.hash, old_sha1);
update->msg = xstrdup_or_null(msg);
return update;
 }
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 298a838c5..413505ff0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2633,7 +2633,7 @@ static int split_head_update(struct ref_update *update,
new_update = ref_transaction_add_update(
transaction, "HEAD",
update->flags | REF_LOG_ONLY | REF_NODEREF,
-   update->new_sha1, update->old_sha1,
+   update->new_oid.hash, update->old_oid.hash,
update->msg);
 
item->util = new_update;
@@ -2690,7 +2690,7 @@ static int split_symref_update(struct files_ref_store 
*refs,
 
new_update = ref_transaction_add_update(
transaction, referent, new_flags,
-   update->new_sha1, update->old_sha1,
+   update->new_oid.hash, update->old_oid.hash,
update->msg);
 
new_update->parent_update = update;
@@ -2729,10 +2729,10 @@ static int check_old_oid(struct ref_update *update, 
struct object_id *oid,
 struct strbuf *err)
 {
if (!(update->flags & REF_HAVE_OLD) ||
-  !hashcmp(oid->hash, update->old_sha1))
+  !oidcmp(oid, >old_oid))
return 0;
 
-   if (is_null_sha1(update->old_sha1))
+   if (is_null_oid(>old_oid))
strbuf_addf(err, "cannot lock ref '%s': "
"reference already exists",
original_update_refname(update));
@@ -2740,13 +2740,13 @@ static int check_old_oid(struct ref_update *update, 
struct object_id *oid,
strbuf_addf(err, "cannot lock ref '%s': "
"reference is missing but expected %s",
original_update_refname(update),
-   sha1_to_hex(update->old_sha1));
+   oid_to_hex(>old_oid));
else
strbuf_addf(err, "cannot lock ref '%s': "
"is at %s but expected %s",
original_update_refname(update),
oid_to_hex(oid),
-   sha1_to_hex(update->old_sha1));
+   oid_to_hex(>old_oid));
 
return -1;
 }
@@ -2773,13 +2773,13 @@ static int lock_ref_for_update(struct files_ref_store 
*refs,
 {
struct strbuf referent = STRBUF_INIT;
int mustexist = (update->flags & REF_HAVE_OLD) &&
-   !is_null_sha1(update->old_sha1);
+   !is_null_oid(>old_oid);
int ret;
struct ref_lock *lock;
 
files_assert_main_repository(refs, "lock_ref_for_update");
 
-   if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
+   if ((update->flags & REF_HAVE_NEW) && is_null_oid(>new_oid))
update->flags |= REF_DELETING;
 
if (head_ref) {
@@ -2861,12 +2861,12 @@ static int lock_ref_for_update(struct files_ref_store 
*refs,
!(update->flags & REF_DELETING) &&
!(update->flags & REF_LOG_ONLY)) {
if (!(update->type & REF_ISSYMREF) &&
-   !hashcmp(lock->old_oid.hash, update->new_sha1)) {
+   !oidcmp(>old_oid, >new_oid)) {
/*
 * The reference already has the desired
 * value, so we don't need to write it.
 */
-   } else if (write_ref_to_lockfile(lock, update->new_sha1,
+   } else if (write_ref_to_lockfile(lock, update->new_oid.hash,
  

[PATCH v3 33/53] log-tree: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert the remaining functions to take pointers to struct object_id
instead of pointers to unsigned char, and update the internals of these
functions as well.  Among these functions is a caller of lookup_tag,
which we will convert shortly.

Signed-off-by: brian m. carlson 
---
 log-tree.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 7fb1a85d2..169fd039f 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -184,7 +184,7 @@ static const struct name_decoration 
*current_pointed_by_HEAD(const struct name_d
 {
const struct name_decoration *list, *head = NULL;
const char *branch_name = NULL;
-   unsigned char unused[20];
+   struct object_id unused;
int rru_flags;
 
/* First find HEAD */
@@ -197,7 +197,7 @@ static const struct name_decoration 
*current_pointed_by_HEAD(const struct name_d
return NULL;
 
/* Now resolve and find the matching current branch */
-   branch_name = resolve_ref_unsafe("HEAD", 0, unused, _flags);
+   branch_name = resolve_ref_unsafe("HEAD", 0, unused.hash, _flags);
if (!(rru_flags & REF_ISSYMREF))
return NULL;
 
@@ -456,13 +456,13 @@ static void show_signature(struct rev_info *opt, struct 
commit *commit)
strbuf_release();
 }
 
-static int which_parent(const unsigned char *sha1, const struct commit *commit)
+static int which_parent(const struct object_id *oid, const struct commit 
*commit)
 {
int nth;
const struct commit_list *parent;
 
for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
-   if (!hashcmp(parent->item->object.oid.hash, sha1))
+   if (!oidcmp(>item->object.oid, oid))
return nth;
nth++;
}
@@ -481,14 +481,14 @@ static void show_one_mergetag(struct commit *commit,
  void *data)
 {
struct rev_info *opt = (struct rev_info *)data;
-   unsigned char sha1[20];
+   struct object_id oid;
struct tag *tag;
struct strbuf verify_message;
int status, nth;
size_t payload_size, gpg_message_offset;
 
-   hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1);
-   tag = lookup_tag(sha1);
+   hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash);
+   tag = lookup_tag(oid.hash);
if (!tag)
return; /* error message already given */
 
@@ -500,7 +500,7 @@ static void show_one_mergetag(struct commit *commit,
  >parents->next->item->object.oid))
strbuf_addf(_message,
"merged tag '%s'\n", tag->tag);
-   else if ((nth = which_parent(tag->tagged->oid.hash, commit)) < 0)
+   else if ((nth = which_parent(>tagged->oid, commit)) < 0)
strbuf_addf(_message, "tag %s names a non-parent %s\n",
tag->tag, tag->tagged->oid.hash);
else
@@ -536,7 +536,7 @@ void show_log(struct rev_info *opt)
struct strbuf msgbuf = STRBUF_INIT;
struct log_info *log = opt->loginfo;
struct commit *commit = log->commit, *parent = log->parent;
-   int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
+   int abbrev_commit = opt->abbrev_commit ? opt->abbrev : GIT_SHA1_HEXSZ;
const char *extra_headers = opt->extra_headers;
struct pretty_print_context ctx = {0};
 


[PATCH v3 21/53] shallow: convert shallow registration functions to object_id

2017-05-06 Thread brian m. carlson
Convert register_shallow and unregister_shallow to take struct
object_id.  register_shallow is a caller of lookup_commit, which we will
convert later.  It doesn't make sense for the registration and
unregistration functions to have incompatible interfaces, so convert
them both.

Signed-off-by: brian m. carlson 
---
 builtin/pack-objects.c |  6 +++---
 builtin/receive-pack.c |  2 +-
 commit.c   |  4 ++--
 commit.h   |  4 ++--
 fetch-pack.c   |  4 ++--
 shallow.c  | 12 ++--
 upload-pack.c  |  8 
 7 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 0fe35d1b5..477070806 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2777,10 +2777,10 @@ static void get_object_list(int ac, const char **av)
continue;
}
if (starts_with(line, "--shallow ")) {
-   unsigned char sha1[20];
-   if (get_sha1_hex(line + 10, sha1))
+   struct object_id oid;
+   if (get_oid_hex(line + 10, ))
die("not an SHA-1 '%s'", line + 10);
-   register_shallow(sha1);
+   register_shallow();
use_bitmap_index = 0;
continue;
}
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f96834f42..6f0f788b0 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -858,7 +858,7 @@ static int update_shallow_ref(struct command *cmd, struct 
shallow_info *si)
 * not lose these new roots..
 */
for (i = 0; i < extra.nr; i++)
-   register_shallow(extra.oid[i].hash);
+   register_shallow([i]);
 
si->shallow_ref[cmd->index] = 0;
oid_array_clear();
diff --git a/commit.c b/commit.c
index 73c78c2b8..ec41ba5e0 100644
--- a/commit.c
+++ b/commit.c
@@ -216,9 +216,9 @@ int for_each_commit_graft(each_commit_graft_fn fn, void 
*cb_data)
return ret;
 }
 
-int unregister_shallow(const unsigned char *sha1)
+int unregister_shallow(const struct object_id *oid)
 {
-   int pos = commit_graft_pos(sha1);
+   int pos = commit_graft_pos(oid->hash);
if (pos < 0)
return -1;
if (pos + 1 < commit_graft_nr)
diff --git a/commit.h b/commit.h
index 7b1986d5c..884177b8f 100644
--- a/commit.h
+++ b/commit.h
@@ -263,8 +263,8 @@ extern struct commit_list 
*get_merge_bases_many_dirty(struct commit *one, int n,
 
 struct oid_array;
 struct ref;
-extern int register_shallow(const unsigned char *sha1);
-extern int unregister_shallow(const unsigned char *sha1);
+extern int register_shallow(const struct object_id *oid);
+extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
 extern int is_repository_shallow(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
diff --git a/fetch-pack.c b/fetch-pack.c
index b42d01f42..d455ef97a 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -417,7 +417,7 @@ static int find_common(struct fetch_pack_args *args,
if (skip_prefix(line, "shallow ", )) {
if (get_oid_hex(arg, ))
die(_("invalid shallow line: %s"), 
line);
-   register_shallow(oid.hash);
+   register_shallow();
continue;
}
if (skip_prefix(line, "unshallow ", )) {
@@ -428,7 +428,7 @@ static int find_common(struct fetch_pack_args *args,
/* make sure that it is parsed as shallow */
if (!parse_object(oid.hash))
die(_("error in object: %s"), line);
-   if (unregister_shallow(oid.hash))
+   if (unregister_shallow())
die(_("no shallow found: %s"), line);
continue;
}
diff --git a/shallow.c b/shallow.c
index 25b6db989..c520ae3ae 100644
--- a/shallow.c
+++ b/shallow.c
@@ -27,13 +27,13 @@ void set_alternate_shallow_file(const char *path, int 
override)
alternate_shallow_file = xstrdup_or_null(path);
 }
 
-int register_shallow(const unsigned char *sha1)
+int register_shallow(const struct object_id *oid)
 {
struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft));
-   struct commit *commit = lookup_commit(sha1);
+   struct commit *commit = lookup_commit(oid->hash);
 
-   hashcpy(graft->oid.hash, sha1);
+   

[PATCH v3 24/53] Convert remaining callers of lookup_commit_reference* to object_id

2017-05-06 Thread brian m. carlson
There are a small number of remaining callers of lookup_commit_reference
and lookup_commit_reference_gently that still need to be converted to
struct object_id.  Convert these.

Signed-off-by: brian m. carlson 
---
 notes-merge.c | 26 +-
 ref-filter.c  |  6 +++---
 sequencer.c   | 20 ++--
 sha1_name.c   | 12 ++--
 shallow.c |  6 +++---
 submodule.c   |  8 
 6 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/notes-merge.c b/notes-merge.c
index 32caaaff7..06d8be9cb 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -535,7 +535,7 @@ int notes_merge(struct notes_merge_options *o,
struct notes_tree *local_tree,
unsigned char *result_sha1)
 {
-   unsigned char local_sha1[20], remote_sha1[20];
+   struct object_id local_oid, remote_oid;
struct commit *local, *remote;
struct commit_list *bases = NULL;
const unsigned char *base_sha1, *base_tree_sha1;
@@ -549,46 +549,46 @@ int notes_merge(struct notes_merge_options *o,
   o->local_ref, o->remote_ref);
 
/* Dereference o->local_ref into local_sha1 */
-   if (read_ref_full(o->local_ref, 0, local_sha1, NULL))
+   if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL))
die("Failed to resolve local notes ref '%s'", o->local_ref);
else if (!check_refname_format(o->local_ref, 0) &&
-   is_null_sha1(local_sha1))
+   is_null_oid(_oid))
local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */
-   else if (!(local = lookup_commit_reference(local_sha1)))
+   else if (!(local = lookup_commit_reference(local_oid.hash)))
die("Could not parse local commit %s (%s)",
-   sha1_to_hex(local_sha1), o->local_ref);
-   trace_printf("\tlocal commit: %.7s\n", sha1_to_hex(local_sha1));
+   oid_to_hex(_oid), o->local_ref);
+   trace_printf("\tlocal commit: %.7s\n", oid_to_hex(_oid));
 
/* Dereference o->remote_ref into remote_sha1 */
-   if (get_sha1(o->remote_ref, remote_sha1)) {
+   if (get_oid(o->remote_ref, _oid)) {
/*
 * Failed to get remote_sha1. If o->remote_ref looks like an
 * unborn ref, perform the merge using an empty notes tree.
 */
if (!check_refname_format(o->remote_ref, 0)) {
-   hashclr(remote_sha1);
+   oidclr(_oid);
remote = NULL;
} else {
die("Failed to resolve remote notes ref '%s'",
o->remote_ref);
}
-   } else if (!(remote = lookup_commit_reference(remote_sha1))) {
+   } else if (!(remote = lookup_commit_reference(remote_oid.hash))) {
die("Could not parse remote commit %s (%s)",
-   sha1_to_hex(remote_sha1), o->remote_ref);
+   oid_to_hex(_oid), o->remote_ref);
}
-   trace_printf("\tremote commit: %.7s\n", sha1_to_hex(remote_sha1));
+   trace_printf("\tremote commit: %.7s\n", oid_to_hex(_oid));
 
if (!local && !remote)
die("Cannot merge empty notes ref (%s) into empty notes ref "
"(%s)", o->remote_ref, o->local_ref);
if (!local) {
/* result == remote commit */
-   hashcpy(result_sha1, remote_sha1);
+   hashcpy(result_sha1, remote_oid.hash);
goto found_result;
}
if (!remote) {
/* result == local commit */
-   hashcpy(result_sha1, local_sha1);
+   hashcpy(result_sha1, local_oid.hash);
goto found_result;
}
assert(local && remote);
diff --git a/ref-filter.c b/ref-filter.c
index 3a640448f..47cce0a18 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2090,7 +2090,7 @@ int parse_opt_ref_sorting(const struct option *opt, const 
char *arg, int unset)
 int parse_opt_merge_filter(const struct option *opt, const char *arg, int 
unset)
 {
struct ref_filter *rf = opt->value;
-   unsigned char sha1[20];
+   struct object_id oid;
int no_merged = starts_with(opt->long_name, "no");
 
if (rf->merge) {
@@ -2105,10 +2105,10 @@ int parse_opt_merge_filter(const struct option *opt, 
const char *arg, int unset)
? REF_FILTER_MERGED_OMIT
: REF_FILTER_MERGED_INCLUDE;
 
-   if (get_sha1(arg, sha1))
+   if (get_oid(arg, ))
die(_("malformed object name %s"), arg);
 
-   rf->merge_commit = lookup_commit_reference_gently(sha1, 0);
+   rf->merge_commit = lookup_commit_reference_gently(oid.hash, 0);
if (!rf->merge_commit)
return opterror(opt, "must point to a commit", 0);
 
diff --git a/sequencer.c b/sequencer.c
index b94830cf9..e44c015b2 100644
--- 

[PATCH v3 28/53] Convert remaining callers of lookup_blob to object_id

2017-05-06 Thread brian m. carlson
All but a few callers of lookup_blob have been converted to struct
object_id.  Introduce a temporary, which will be removed later, into
parse_object to ease the transition, and convert the remaining callers
so that we can update lookup_blob to take struct object_id *.

Signed-off-by: brian m. carlson 
---
 builtin/index-pack.c | 28 ++--
 builtin/merge-tree.c | 10 +-
 object.c |  9 ++---
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fef0025e4..2241ee68e 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry)
 
 static void sha1_object(const void *data, struct object_entry *obj_entry,
unsigned long size, enum object_type type,
-   const unsigned char *sha1)
+   const struct object_id *oid)
 {
void *new_data = NULL;
int collision_test_needed = 0;
@@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct 
object_entry *obj_entry,
 
if (startup_info->have_repository) {
read_lock();
-   collision_test_needed = has_sha1_file_with_flags(sha1, 
HAS_SHA1_QUICK);
+   collision_test_needed = has_sha1_file_with_flags(oid->hash, 
HAS_SHA1_QUICK);
read_unlock();
}
 
@@ -809,31 +809,31 @@ static void sha1_object(const void *data, struct 
object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
-   has_type = sha1_object_info(sha1, _size);
+   has_type = sha1_object_info(oid->hash, _size);
if (has_type < 0)
-   die(_("cannot read existing object info %s"), 
sha1_to_hex(sha1));
+   die(_("cannot read existing object info %s"), 
oid_to_hex(oid));
if (has_type != type || has_size != size)
-   die(_("SHA1 COLLISION FOUND WITH %s !"), 
sha1_to_hex(sha1));
-   has_data = read_sha1_file(sha1, _type, _size);
+   die(_("SHA1 COLLISION FOUND WITH %s !"), 
oid_to_hex(oid));
+   has_data = read_sha1_file(oid->hash, _type, _size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
if (!has_data)
-   die(_("cannot read existing object %s"), 
sha1_to_hex(sha1));
+   die(_("cannot read existing object %s"), 
oid_to_hex(oid));
if (size != has_size || type != has_type ||
memcmp(data, has_data, size) != 0)
-   die(_("SHA1 COLLISION FOUND WITH %s !"), 
sha1_to_hex(sha1));
+   die(_("SHA1 COLLISION FOUND WITH %s !"), 
oid_to_hex(oid));
free(has_data);
}
 
if (strict) {
read_lock();
if (type == OBJ_BLOB) {
-   struct blob *blob = lookup_blob(sha1);
+   struct blob *blob = lookup_blob(oid->hash);
if (blob)
blob->object.flags |= FLAG_CHECKED;
else
-   die(_("invalid blob object %s"), 
sha1_to_hex(sha1));
+   die(_("invalid blob object %s"), 
oid_to_hex(oid));
} else {
struct object *obj;
int eaten;
@@ -845,7 +845,7 @@ static void sha1_object(const void *data, struct 
object_entry *obj_entry,
 * we do not need to free the memory here, as the
 * buf is deleted by the caller.
 */
-   obj = parse_object_buffer(sha1, type, size, buf, 
);
+   obj = parse_object_buffer(oid->hash, type, size, buf, 
);
if (!obj)
die(_("invalid %s"), typename(type));
if (do_fsck_object &&
@@ -960,7 +960,7 @@ static void resolve_delta(struct object_entry *delta_obj,
   typename(delta_obj->real_type),
   delta_obj->idx.oid.hash);
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
-   delta_obj->idx.oid.hash);
+   _obj->idx.oid);
counter_lock();
nr_resolved_deltas++;
counter_unlock();
@@ -1149,7 +1149,7 @@ static void parse_pack_objects(unsigned char *sha1)
nr_delays++;
} else
sha1_object(data, NULL, obj->size, obj->type,
-   obj->idx.oid.hash);
+   >idx.oid);
free(data);

[PATCH v3 16/53] builtin/verify-commit: convert to struct object_id

2017-05-06 Thread brian m. carlson
This is a prerequisite to convert to lookup_commit, which we will
convert later.

Signed-off-by: brian m. carlson 
---
 builtin/verify-commit.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 38bedf8f9..a5db1c427 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -18,14 +18,14 @@ static const char * const verify_commit_usage[] = {
NULL
 };
 
-static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned 
long size, unsigned flags)
+static int run_gpg_verify(const struct object_id *oid, const char *buf, 
unsigned long size, unsigned flags)
 {
struct signature_check signature_check;
int ret;
 
memset(_check, 0, sizeof(signature_check));
 
-   ret = check_commit_signature(lookup_commit(sha1), _check);
+   ret = check_commit_signature(lookup_commit(oid->hash), 
_check);
print_signature_buffer(_check, flags);
 
signature_check_clear(_check);
@@ -35,22 +35,22 @@ static int run_gpg_verify(const unsigned char *sha1, const 
char *buf, unsigned l
 static int verify_commit(const char *name, unsigned flags)
 {
enum object_type type;
-   unsigned char sha1[20];
+   struct object_id oid;
char *buf;
unsigned long size;
int ret;
 
-   if (get_sha1(name, sha1))
+   if (get_oid(name, ))
return error("commit '%s' not found.", name);
 
-   buf = read_sha1_file(sha1, , );
+   buf = read_sha1_file(oid.hash, , );
if (!buf)
return error("%s: unable to read file.", name);
if (type != OBJ_COMMIT)
return error("%s: cannot verify a non-commit object of type 
%s.",
name, typename(type));
 
-   ret = run_gpg_verify(sha1, buf, size, flags);
+   ret = run_gpg_verify(, buf, size, flags);
 
free(buf);
return ret;


[PATCH v3 26/53] pack: convert struct pack_idx_entry to struct object_id

2017-05-06 Thread brian m. carlson
Convert struct pack_idx_entry to use struct object_id by changing the
definition and applying the following semantic patch, plus the standard
object_id transforms:

@@
struct pack_idx_entry E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct pack_idx_entry *E1;
@@
- E1->sha1
+ E1->oid.hash

Signed-off-by: brian m. carlson 
---
 builtin/index-pack.c   | 33 +++---
 builtin/pack-objects.c | 63 +-
 bulk-checkin.c |  4 ++--
 fast-import.c  | 30 
 pack-bitmap-write.c|  8 ---
 pack-objects.c |  8 ---
 pack-write.c   | 10 
 pack.h |  2 +-
 8 files changed, 89 insertions(+), 69 deletions(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 4ff567db4..fef0025e4 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -747,13 +747,13 @@ static int compare_objects(const unsigned char *buf, 
unsigned long size,
ssize_t len = read_istream(data->st, data->buf, size);
if (len == 0)
die(_("SHA1 COLLISION FOUND WITH %s !"),
-   sha1_to_hex(data->entry->idx.sha1));
+   oid_to_hex(>entry->idx.oid));
if (len < 0)
die(_("unable to read %s"),
-   sha1_to_hex(data->entry->idx.sha1));
+   oid_to_hex(>entry->idx.oid));
if (memcmp(buf, data->buf, len))
die(_("SHA1 COLLISION FOUND WITH %s !"),
-   sha1_to_hex(data->entry->idx.sha1));
+   oid_to_hex(>entry->idx.oid));
size -= len;
buf += len;
}
@@ -771,12 +771,12 @@ static int check_collison(struct object_entry *entry)
 
memset(, 0, sizeof(data));
data.entry = entry;
-   data.st = open_istream(entry->idx.sha1, , , NULL);
+   data.st = open_istream(entry->idx.oid.hash, , , NULL);
if (!data.st)
return -1;
if (size != entry->size || type != entry->type)
die(_("SHA1 COLLISION FOUND WITH %s !"),
-   sha1_to_hex(entry->idx.sha1));
+   oid_to_hex(>idx.oid));
unpack_data(entry, compare_objects, );
close_istream(data.st);
free(data.buf);
@@ -957,9 +957,10 @@ static void resolve_delta(struct object_entry *delta_obj,
if (!result->data)
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
hash_sha1_file(result->data, result->size,
-  typename(delta_obj->real_type), delta_obj->idx.sha1);
+  typename(delta_obj->real_type),
+  delta_obj->idx.oid.hash);
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
-   delta_obj->idx.sha1);
+   delta_obj->idx.oid.hash);
counter_lock();
nr_resolved_deltas++;
counter_unlock();
@@ -989,7 +990,7 @@ static struct base_data *find_unresolved_deltas_1(struct 
base_data *base,
  struct base_data *prev_base)
 {
if (base->ref_last == -1 && base->ofs_last == -1) {
-   find_ref_delta_children(base->obj->idx.sha1,
+   find_ref_delta_children(base->obj->idx.oid.hash,
>ref_first, >ref_last,
OBJ_REF_DELTA);
 
@@ -1130,7 +1131,8 @@ static void parse_pack_objects(unsigned char *sha1)
for (i = 0; i < nr_objects; i++) {
struct object_entry *obj = [i];
void *data = unpack_raw_entry(obj, _delta->offset,
- ref_delta_sha1, obj->idx.sha1);
+ ref_delta_sha1,
+ obj->idx.oid.hash);
obj->real_type = obj->type;
if (obj->type == OBJ_OFS_DELTA) {
nr_ofs_deltas++;
@@ -1146,7 +1148,8 @@ static void parse_pack_objects(unsigned char *sha1)
obj->real_type = OBJ_BAD;
nr_delays++;
} else
-   sha1_object(data, NULL, obj->size, obj->type, 
obj->idx.sha1);
+   sha1_object(data, NULL, obj->size, obj->type,
+   obj->idx.oid.hash);
free(data);
display_progress(progress, i+1);
}
@@ -1172,7 +1175,8 @@ static void parse_pack_objects(unsigned char *sha1)
if (obj->real_type != OBJ_BAD)
continue;
obj->real_type = obj->type;
-   sha1_object(NULL, obj, obj->size, obj->type, obj->idx.sha1);
+   sha1_object(NULL, obj, obj->size, obj->type,
+   

[PATCH v3 20/53] revision: convert prepare_show_merge to struct object_id

2017-05-06 Thread brian m. carlson
This is a caller of lookup_commit_or_die, which we will convert later
on.

Signed-off-by: brian m. carlson 
---
 revision.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/revision.c b/revision.c
index 2b56c3baf..945367034 100644
--- a/revision.c
+++ b/revision.c
@@ -1389,16 +1389,16 @@ static void prepare_show_merge(struct rev_info *revs)
 {
struct commit_list *bases;
struct commit *head, *other;
-   unsigned char sha1[20];
+   struct object_id oid;
const char **prune = NULL;
int i, prune_num = 1; /* counting terminating NULL */
 
-   if (get_sha1("HEAD", sha1))
+   if (get_oid("HEAD", ))
die("--merge without HEAD?");
-   head = lookup_commit_or_die(sha1, "HEAD");
-   if (get_sha1("MERGE_HEAD", sha1))
+   head = lookup_commit_or_die(oid.hash, "HEAD");
+   if (get_oid("MERGE_HEAD", ))
die("--merge without MERGE_HEAD?");
-   other = lookup_commit_or_die(sha1, "MERGE_HEAD");
+   other = lookup_commit_or_die(oid.hash, "MERGE_HEAD");
add_pending_object(revs, >object, "HEAD");
add_pending_object(revs, >object, "MERGE_HEAD");
bases = get_merge_bases(head, other);


[PATCH v3 22/53] sequencer: convert some functions to struct object_id

2017-05-06 Thread brian m. carlson
Convert update_squash_messages and is_index_unchanged to struct
object_id.  These are callers of lookup_commit and
lookup_commit_reference, which we want to convert.

Signed-off-by: brian m. carlson 
---
 sequencer.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index b0f862b7b..b94830cf9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -482,13 +482,13 @@ static int do_recursive_merge(struct commit *base, struct 
commit *next,
 
 static int is_index_unchanged(void)
 {
-   unsigned char head_sha1[20];
+   struct object_id head_oid;
struct commit *head_commit;
 
-   if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
+   if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, 
NULL))
return error(_("could not resolve HEAD commit\n"));
 
-   head_commit = lookup_commit(head_sha1);
+   head_commit = lookup_commit(head_oid.hash);
 
/*
 * If head_commit is NULL, check_commit, called from
@@ -835,13 +835,13 @@ static int update_squash_messages(enum todo_command 
command,
strbuf_splice(, 0, eol - buf.buf, header.buf, header.len);
strbuf_release();
} else {
-   unsigned char head[20];
+   struct object_id head;
struct commit *head_commit;
const char *head_message, *body;
 
-   if (get_sha1("HEAD", head))
+   if (get_oid("HEAD", ))
return error(_("need a HEAD to fixup"));
-   if (!(head_commit = lookup_commit_reference(head)))
+   if (!(head_commit = lookup_commit_reference(head.hash)))
return error(_("could not read HEAD"));
if (!(head_message = get_commit_buffer(head_commit, NULL)))
return error(_("could not read HEAD's commit message"));


[PATCH v3 25/53] Convert lookup_commit* to struct object_id

2017-05-06 Thread brian m. carlson
Convert lookup_commit, lookup_commit_or_die,
lookup_commit_reference, and lookup_commit_reference_gently to take
struct object_id arguments.

Introduce a temporary in parse_object buffer in order to convert this
function.  This is required since in order to convert parse_object and
parse_object_buffer, lookup_commit_reference_gently and
lookup_commit_or_die would need to be converted.  Not introducing a
temporary would therefore require that lookup_commit_or_die take a
struct object_id *, but lookup_commit would take unsigned char *,
leaving a confusing and hard-to-use interface.

parse_object_buffer will lose this temporary in a later patch.

This commit was created with manual changes to commit.c, commit.h, and
object.c, plus the following semantic patch:

@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1.hash, E2)
+ lookup_commit_reference_gently(, E2)

@@
expression E1, E2;
@@
- lookup_commit_reference_gently(E1->hash, E2)
+ lookup_commit_reference_gently(E1, E2)

@@
expression E1;
@@
- lookup_commit_reference(E1.hash)
+ lookup_commit_reference()

@@
expression E1;
@@
- lookup_commit_reference(E1->hash)
+ lookup_commit_reference(E1)

@@
expression E1;
@@
- lookup_commit(E1.hash)
+ lookup_commit()

@@
expression E1;
@@
- lookup_commit(E1->hash)
+ lookup_commit(E1)

@@
expression E1, E2;
@@
- lookup_commit_or_die(E1.hash, E2)
+ lookup_commit_or_die(, E2)

@@
expression E1, E2;
@@
- lookup_commit_or_die(E1->hash, E2)
+ lookup_commit_or_die(E1, E2)

Signed-off-by: brian m. carlson 
---
 archive.c   |  2 +-
 bisect.c|  2 +-
 branch.c|  2 +-
 builtin/am.c|  4 ++--
 builtin/blame.c |  4 ++--
 builtin/branch.c|  6 +++---
 builtin/checkout.c  |  6 +++---
 builtin/clone.c |  2 +-
 builtin/commit-tree.c   |  2 +-
 builtin/commit.c|  4 ++--
 builtin/describe.c  |  4 ++--
 builtin/diff-tree.c |  4 ++--
 builtin/fast-export.c   |  2 +-
 builtin/fetch.c |  7 ---
 builtin/fmt-merge-msg.c |  4 ++--
 builtin/log.c   |  8 
 builtin/merge-base.c|  6 +++---
 builtin/merge.c |  2 +-
 builtin/notes.c |  2 +-
 builtin/pull.c  | 10 +-
 builtin/reflog.c|  8 
 builtin/replace.c   |  4 ++--
 builtin/reset.c |  4 ++--
 builtin/rev-parse.c |  6 +++---
 builtin/show-branch.c   |  4 ++--
 builtin/tag.c   |  2 +-
 builtin/verify-commit.c |  2 +-
 bundle.c|  2 +-
 commit.c| 30 +++---
 commit.h| 12 ++--
 fast-import.c   |  4 ++--
 fetch-pack.c|  2 +-
 http-push.c |  5 +++--
 log-tree.c  |  2 +-
 notes-cache.c   |  2 +-
 notes-merge.c   |  4 ++--
 notes-utils.c   |  2 +-
 object.c|  5 -
 parse-options-cb.c  |  2 +-
 ref-filter.c|  4 ++--
 remote.c| 13 +++--
 revision.c  |  8 
 sequencer.c |  8 
 sha1_name.c | 10 +-
 shallow.c   | 20 ++--
 submodule.c | 14 +++---
 tag.c   |  2 +-
 tree.c  |  2 +-
 walker.c|  2 +-
 wt-status.c |  2 +-
 50 files changed, 138 insertions(+), 132 deletions(-)

diff --git a/archive.c b/archive.c
index 60b889198..54701e8bb 100644
--- a/archive.c
+++ b/archive.c
@@ -360,7 +360,7 @@ static void parse_treeish_arg(const char **argv,
if (get_sha1(name, oid.hash))
die("Not a valid object name");
 
-   commit = lookup_commit_reference_gently(oid.hash, 1);
+   commit = lookup_commit_reference_gently(, 1);
if (commit) {
commit_sha1 = commit->object.oid.hash;
archive_time = commit->date;
diff --git a/bisect.c b/bisect.c
index 08c9fb726..bb5af3ea3 100644
--- a/bisect.c
+++ b/bisect.c
@@ -705,7 +705,7 @@ static int bisect_checkout(const unsigned char *bisect_rev, 
int no_checkout)
 
 static struct commit *get_commit_reference(const struct object_id *oid)
 {
-   struct commit *r = lookup_commit_reference(oid->hash);
+   struct commit *r = lookup_commit_reference(oid);
if (!r)
die(_("Not a valid commit name %s"), oid_to_hex(oid));
return r;
diff --git a/branch.c b/branch.c
index 1758c9708..4899144f5 100644
--- a/branch.c
+++ b/branch.c
@@ -286,7 +286,7 @@ void create_branch(const char *name, const char *start_name,
break;
}
 
-   if ((commit = lookup_commit_reference(oid.hash)) == NULL)
+   if ((commit = lookup_commit_reference()) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
oidcpy(, >object.oid);
 
diff --git a/builtin/am.c b/builtin/am.c
index a95dd8b4e..650269ac5 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1488,7 +1488,7 @@ 

[PATCH v3 27/53] builtin/unpack-objects: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert struct delta_info and struct object_info, as well as the various
functions, to use struct object_id.  Convert several hard-coded 20
values to GIT_SHA1_RAWSZ.  Among the functions converted is a caller of
lookup_blob, which we will convert shortly.

Signed-off-by: brian m. carlson 
---
 builtin/unpack-objects.c | 64 
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4532aa083..3dc5e5691 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -127,7 +127,7 @@ static void *get_data(unsigned long size)
 }
 
 struct delta_info {
-   unsigned char base_sha1[20];
+   struct object_id base_oid;
unsigned nr;
off_t base_offset;
unsigned long size;
@@ -137,13 +137,13 @@ struct delta_info {
 
 static struct delta_info *delta_list;
 
-static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
+static void add_delta_to_list(unsigned nr, const struct object_id *base_oid,
  off_t base_offset,
  void *delta, unsigned long size)
 {
struct delta_info *info = xmalloc(sizeof(*info));
 
-   hashcpy(info->base_sha1, base_sha1);
+   oidcpy(>base_oid, base_oid);
info->base_offset = base_offset;
info->size = size;
info->delta = delta;
@@ -154,7 +154,7 @@ static void add_delta_to_list(unsigned nr, unsigned const 
char *base_sha1,
 
 struct obj_info {
off_t offset;
-   unsigned char sha1[20];
+   struct object_id oid;
struct object *obj;
 };
 
@@ -170,9 +170,9 @@ static unsigned nr_objects;
  */
 static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
 
-   if (write_sha1_file(obj_buf->buffer, obj_buf->size, 
typename(obj->type), sha1) < 0)
+   if (write_sha1_file(obj_buf->buffer, obj_buf->size, 
typename(obj->type), oid.hash) < 0)
die("failed to write object %s", oid_to_hex(>oid));
obj->flags |= FLAG_WRITTEN;
 }
@@ -237,19 +237,19 @@ static void write_object(unsigned nr, enum object_type 
type,
 void *buf, unsigned long size)
 {
if (!strict) {
-   if (write_sha1_file(buf, size, typename(type), 
obj_list[nr].sha1) < 0)
+   if (write_sha1_file(buf, size, typename(type), 
obj_list[nr].oid.hash) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);
obj_list[nr].obj = NULL;
} else if (type == OBJ_BLOB) {
struct blob *blob;
-   if (write_sha1_file(buf, size, typename(type), 
obj_list[nr].sha1) < 0)
+   if (write_sha1_file(buf, size, typename(type), 
obj_list[nr].oid.hash) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);
 
-   blob = lookup_blob(obj_list[nr].sha1);
+   blob = lookup_blob(obj_list[nr].oid.hash);
if (blob)
blob->object.flags |= FLAG_WRITTEN;
else
@@ -258,9 +258,9 @@ static void write_object(unsigned nr, enum object_type type,
} else {
struct object *obj;
int eaten;
-   hash_sha1_file(buf, size, typename(type), obj_list[nr].sha1);
+   hash_sha1_file(buf, size, typename(type), 
obj_list[nr].oid.hash);
added_object(nr, type, buf, size);
-   obj = parse_object_buffer(obj_list[nr].sha1, type, size, buf, 
);
+   obj = parse_object_buffer(obj_list[nr].oid.hash, type, size, 
buf, );
if (!obj)
die("invalid %s", typename(type));
add_object_buffer(obj, buf, size);
@@ -296,7 +296,7 @@ static void added_object(unsigned nr, enum object_type type,
struct delta_info *info;
 
while ((info = *p) != NULL) {
-   if (!hashcmp(info->base_sha1, obj_list[nr].sha1) ||
+   if (!oidcmp(>base_oid, _list[nr].oid) ||
info->base_offset == obj_list[nr].offset) {
*p = info->next;
p = _list;
@@ -320,12 +320,12 @@ static void unpack_non_delta_entry(enum object_type type, 
unsigned long size,
free(buf);
 }
 
-static int resolve_against_held(unsigned nr, const unsigned char *base,
+static int resolve_against_held(unsigned nr, const struct object_id *base,
void *delta_data, unsigned long delta_size)
 {
struct object *obj;
struct obj_buffer *obj_buffer;
-   obj = lookup_object(base);
+   obj = lookup_object(base->hash);
if (!obj)
return 0;
obj_buffer = 

[PATCH v3 23/53] builtin/tag: convert to struct object_id

2017-05-06 Thread brian m. carlson
Parts of this module call lookup_commit_reference, which we want to
convert.  The module is small and mostly self-contained, so convert the
rest of it while we're at it.

Signed-off-by: brian m. carlson 
---
 builtin/tag.c | 66 +--
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 222404522..597c925e3 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -66,7 +66,7 @@ static int list_tags(struct ref_filter *filter, struct 
ref_sorting *sorting, con
 }
 
 typedef int (*each_tag_name_fn)(const char *name, const char *ref,
-   const unsigned char *sha1, const void *cb_data);
+   const struct object_id *oid, const void 
*cb_data);
 
 static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
 const void *cb_data)
@@ -74,17 +74,17 @@ static int for_each_tag_name(const char **argv, 
each_tag_name_fn fn,
const char **p;
struct strbuf ref = STRBUF_INIT;
int had_error = 0;
-   unsigned char sha1[20];
+   struct object_id oid;
 
for (p = argv; *p; p++) {
strbuf_reset();
strbuf_addf(, "refs/tags/%s", *p);
-   if (read_ref(ref.buf, sha1)) {
+   if (read_ref(ref.buf, oid.hash)) {
error(_("tag '%s' not found."), *p);
had_error = 1;
continue;
}
-   if (fn(*p, ref.buf, sha1, cb_data))
+   if (fn(*p, ref.buf, , cb_data))
had_error = 1;
}
strbuf_release();
@@ -92,16 +92,16 @@ static int for_each_tag_name(const char **argv, 
each_tag_name_fn fn,
 }
 
 static int delete_tag(const char *name, const char *ref,
- const unsigned char *sha1, const void *cb_data)
+ const struct object_id *oid, const void *cb_data)
 {
-   if (delete_ref(NULL, ref, sha1, 0))
+   if (delete_ref(NULL, ref, oid->hash, 0))
return 1;
-   printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, 
DEFAULT_ABBREV));
+   printf(_("Deleted tag '%s' (was %s)\n"), name, 
find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
return 0;
 }
 
 static int verify_tag(const char *name, const char *ref,
- const unsigned char *sha1, const void *cb_data)
+ const struct object_id *oid, const void *cb_data)
 {
int flags;
const char *fmt_pretty = cb_data;
@@ -110,11 +110,11 @@ static int verify_tag(const char *name, const char *ref,
if (fmt_pretty)
flags = GPG_VERIFY_OMIT_STATUS;
 
-   if (gpg_verify_tag(sha1, name, flags))
+   if (gpg_verify_tag(oid->hash, name, flags))
return -1;
 
if (fmt_pretty)
-   pretty_print_ref(name, sha1, fmt_pretty);
+   pretty_print_ref(name, oid->hash, fmt_pretty);
 
return 0;
 }
@@ -182,13 +182,13 @@ static int git_tag_config(const char *var, const char 
*value, void *cb)
return git_default_config(var, value, cb);
 }
 
-static void write_tag_body(int fd, const unsigned char *sha1)
+static void write_tag_body(int fd, const struct object_id *oid)
 {
unsigned long size;
enum object_type type;
char *buf, *sp;
 
-   buf = read_sha1_file(sha1, , );
+   buf = read_sha1_file(oid->hash, , );
if (!buf)
return;
/* skip header */
@@ -204,11 +204,11 @@ static void write_tag_body(int fd, const unsigned char 
*sha1)
free(buf);
 }
 
-static int build_tag_object(struct strbuf *buf, int sign, unsigned char 
*result)
+static int build_tag_object(struct strbuf *buf, int sign, struct object_id 
*result)
 {
if (sign && do_sign(buf) < 0)
return error(_("unable to sign the tag"));
-   if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)
+   if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0)
return error(_("unable to write tag file"));
return 0;
 }
@@ -223,15 +223,15 @@ struct create_tag_options {
} cleanup_mode;
 };
 
-static void create_tag(const unsigned char *object, const char *tag,
+static void create_tag(const struct object_id *object, const char *tag,
   struct strbuf *buf, struct create_tag_options *opt,
-  unsigned char *prev, unsigned char *result)
+  struct object_id *prev, struct object_id *result)
 {
enum object_type type;
struct strbuf header = STRBUF_INIT;
char *path = NULL;
 
-   type = sha1_object_info(object, NULL);
+   type = sha1_object_info(object->hash, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
 
@@ -240,7 +240,7 @@ static void create_tag(const unsigned char 

[PATCH v3 15/53] reflog_expire: convert to struct object_id

2017-05-06 Thread brian m. carlson
Adjust the callback functions to take struct object_id * instead of
unsigned char *, and modify related static functions accordingly.

Introduce a temporary object_id instance into files_reflog_expire and
copy the SHA-1 value passed in.  This is necessary because the sha1
parameter can come indirectly from get_sha1.  Without the temporary, it
would require much more refactoring to be able to convert this function.

Signed-off-by: brian m. carlson 
---
 builtin/reflog.c | 22 +++---
 refs.h   |  6 +++---
 refs/files-backend.c |  7 +--
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 747277577..d6718d326 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -186,13 +186,13 @@ static int commit_is_complete(struct commit *commit)
return !is_incomplete;
 }
 
-static int keep_entry(struct commit **it, unsigned char *sha1)
+static int keep_entry(struct commit **it, struct object_id *oid)
 {
struct commit *commit;
 
-   if (is_null_sha1(sha1))
+   if (is_null_oid(oid))
return 1;
-   commit = lookup_commit_reference_gently(sha1, 1);
+   commit = lookup_commit_reference_gently(oid->hash, 1);
if (!commit)
return 0;
 
@@ -251,17 +251,17 @@ static void mark_reachable(struct expire_reflog_policy_cb 
*cb)
cb->mark_list = leftover;
 }
 
-static int unreachable(struct expire_reflog_policy_cb *cb, struct commit 
*commit, unsigned char *sha1)
+static int unreachable(struct expire_reflog_policy_cb *cb, struct commit 
*commit, struct object_id *oid)
 {
/*
 * We may or may not have the commit yet - if not, look it
 * up using the supplied sha1.
 */
if (!commit) {
-   if (is_null_sha1(sha1))
+   if (is_null_oid(oid))
return 0;
 
-   commit = lookup_commit_reference_gently(sha1, 1);
+   commit = lookup_commit_reference_gently(oid->hash, 1);
 
/* Not a commit -- keep it */
if (!commit)
@@ -283,7 +283,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, 
struct commit *commit
 /*
  * Return true iff the specified reflog entry should be expired.
  */
-static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
+static int should_expire_reflog_ent(struct object_id *ooid, struct object_id 
*noid,
const char *email, unsigned long timestamp, 
int tz,
const char *message, void *cb_data)
 {
@@ -295,13 +295,13 @@ static int should_expire_reflog_ent(unsigned char *osha1, 
unsigned char *nsha1,
 
old = new = NULL;
if (cb->cmd.stalefix &&
-   (!keep_entry(, osha1) || !keep_entry(, nsha1)))
+   (!keep_entry(, ooid) || !keep_entry(, noid)))
return 1;
 
if (timestamp < cb->cmd.expire_unreachable) {
if (cb->unreachable_expire_kind == UE_ALWAYS)
return 1;
-   if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
+   if (unreachable(cb, old, ooid) || unreachable(cb, new, noid))
return 1;
}
 
@@ -326,7 +326,7 @@ static int push_tip_to_list(const char *refname, const 
struct object_id *oid,
 }
 
 static void reflog_expiry_prepare(const char *refname,
- const unsigned char *sha1,
+ const struct object_id *oid,
  void *cb_data)
 {
struct expire_reflog_policy_cb *cb = cb_data;
@@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname,
cb->tip_commit = NULL;
cb->unreachable_expire_kind = UE_HEAD;
} else {
-   cb->tip_commit = lookup_commit_reference_gently(sha1, 1);
+   cb->tip_commit = lookup_commit_reference_gently(oid->hash, 1);
if (!cb->tip_commit)
cb->unreachable_expire_kind = UE_ALWAYS;
else
diff --git a/refs.h b/refs.h
index 07cf4cd41..a22f696dd 100644
--- a/refs.h
+++ b/refs.h
@@ -611,10 +611,10 @@ enum expire_reflog_flags {
  * unlocked again.
  */
 typedef void reflog_expiry_prepare_fn(const char *refname,
- const unsigned char *sha1,
+ const struct object_id *oid,
  void *cb_data);
-typedef int reflog_expiry_should_prune_fn(unsigned char *osha1,
- unsigned char *nsha1,
+typedef int reflog_expiry_should_prune_fn(struct object_id *ooid,
+ struct object_id *noid,
  const char *email,
  unsigned long timestamp, int tz,
   

[PATCH v3 17/53] tag: convert parse_tag_buffer to struct object_id

2017-05-06 Thread brian m. carlson
Specify some constants in terms of GIT_SHA1_HEXSZ, and convert a
get_sha1_hex into parse_oid_hex to avoid needing to specify additional
constants.

Signed-off-by: brian m. carlson 
---
 tag.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/tag.c b/tag.c
index 243d1fdbb..625f5cd71 100644
--- a/tag.c
+++ b/tag.c
@@ -116,7 +116,7 @@ static unsigned long parse_tag_date(const char *buf, const 
char *tail)
 
 int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
char type[20];
const char *bufptr = data;
const char *tail = bufptr + size;
@@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, 
unsigned long size)
return 0;
item->object.parsed = 1;
 
-   if (size < 64)
+   if (size < GIT_SHA1_HEXSZ + 24)
return -1;
-   if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || 
bufptr[47] != '\n')
+   if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, , 
) || *bufptr++ != '\n')
return -1;
-   bufptr += 48; /* "object " + sha1 + "\n" */
 
if (!starts_with(bufptr, "type "))
return -1;
@@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, 
unsigned long size)
bufptr = nl + 1;
 
if (!strcmp(type, blob_type)) {
-   item->tagged = _blob(sha1)->object;
+   item->tagged = _blob(oid.hash)->object;
} else if (!strcmp(type, tree_type)) {
-   item->tagged = _tree(sha1)->object;
+   item->tagged = _tree(oid.hash)->object;
} else if (!strcmp(type, commit_type)) {
-   item->tagged = _commit(sha1)->object;
+   item->tagged = _commit(oid.hash)->object;
} else if (!strcmp(type, tag_type)) {
-   item->tagged = _tag(sha1)->object;
+   item->tagged = _tag(oid.hash)->object;
} else {
error("Unknown type %s", type);
item->tagged = NULL;


[PATCH v3 18/53] http-push: convert some static functions to struct object_id

2017-05-06 Thread brian m. carlson
Among the functions converted is a caller of lookup_commit_or_die, which
we will convert later on.

Signed-off-by: brian m. carlson 
---
 http-push.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/http-push.c b/http-push.c
index f0e3108f7..f3dd0a560 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1536,7 +1536,7 @@ static int remote_exists(const char *path)
return ret;
 }
 
-static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
+static void fetch_symref(const char *path, char **symref, struct object_id 
*oid)
 {
char *url = xstrfmt("%s%s", repo->url, path);
struct strbuf buffer = STRBUF_INIT;
@@ -1549,7 +1549,7 @@ static void fetch_symref(const char *path, char **symref, 
unsigned char *sha1)
 
free(*symref);
*symref = NULL;
-   hashclr(sha1);
+   oidclr(oid);
 
if (buffer.len == 0)
return;
@@ -1561,15 +1561,15 @@ static void fetch_symref(const char *path, char 
**symref, unsigned char *sha1)
if (skip_prefix(buffer.buf, "ref: ", )) {
*symref = xmemdupz(name, buffer.len - (name - buffer.buf));
} else {
-   get_sha1_hex(buffer.buf, sha1);
+   get_oid_hex(buffer.buf, oid);
}
 
strbuf_release();
 }
 
-static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
+static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
 {
-   struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
+   struct commit *head = lookup_commit_or_die(head_oid->hash, "HEAD");
struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, 
remote->name);
 
return in_merge_bases(branch, head);
@@ -1579,7 +1579,7 @@ static int delete_remote_branch(const char *pattern, int 
force)
 {
struct ref *refs = remote_refs;
struct ref *remote_ref = NULL;
-   unsigned char head_sha1[20];
+   struct object_id head_oid;
char *symref = NULL;
int match;
int patlen = strlen(pattern);
@@ -1610,7 +1610,7 @@ static int delete_remote_branch(const char *pattern, int 
force)
 * Remote HEAD must be a symref (not exactly foolproof; a remote
 * symlink to a symref will look like a symref)
 */
-   fetch_symref("HEAD", , head_sha1);
+   fetch_symref("HEAD", , _oid);
if (!symref)
return error("Remote HEAD is not a symref");
 
@@ -1619,7 +1619,7 @@ static int delete_remote_branch(const char *pattern, int 
force)
if (!strcmp(remote_ref->name, symref))
return error("Remote branch %s is the current HEAD",
 remote_ref->name);
-   fetch_symref(symref, , head_sha1);
+   fetch_symref(symref, , _oid);
}
 
/* Run extra sanity checks if delete is not forced */
@@ -1627,10 +1627,10 @@ static int delete_remote_branch(const char *pattern, 
int force)
/* Remote HEAD must resolve to a known object */
if (symref)
return error("Remote HEAD symrefs too deep");
-   if (is_null_sha1(head_sha1))
+   if (is_null_oid(_oid))
return error("Unable to resolve remote HEAD");
-   if (!has_sha1_file(head_sha1))
-   return error("Remote HEAD resolves to object %s\nwhich 
does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1));
+   if (!has_object_file(_oid))
+   return error("Remote HEAD resolves to object %s\nwhich 
does not exist locally, perhaps you need to fetch?", oid_to_hex(_oid));
 
/* Remote branch must resolve to a known object */
if (is_null_oid(_ref->old_oid))
@@ -1640,7 +1640,7 @@ static int delete_remote_branch(const char *pattern, int 
force)
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(_ref->old_oid));
 
/* Remote branch must be an ancestor of remote HEAD */
-   if (!verify_merge_base(head_sha1, remote_ref)) {
+   if (!verify_merge_base(_oid, remote_ref)) {
return error("The branch '%s' is not an ancestor "
 "of your current HEAD.\n"
 "If you are sure you want to delete it,"


[PATCH v3 19/53] notes-utils: convert internals to struct object_id

2017-05-06 Thread brian m. carlson
Convert the internals of create_notes_comit and commit_notes to use
struct object_id.

Signed-off-by: brian m. carlson 
---
 notes-utils.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/notes-utils.c b/notes-utils.c
index 24a33616a..36c1490aa 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -7,18 +7,18 @@ void create_notes_commit(struct notes_tree *t, struct 
commit_list *parents,
 const char *msg, size_t msg_len,
 unsigned char *result_sha1)
 {
-   unsigned char tree_sha1[20];
+   struct object_id tree_oid;
 
assert(t->initialized);
 
-   if (write_notes_tree(t, tree_sha1))
+   if (write_notes_tree(t, tree_oid.hash))
die("Failed to write notes tree to database");
 
if (!parents) {
/* Deduce parent commit from t->ref */
-   unsigned char parent_sha1[20];
-   if (!read_ref(t->ref, parent_sha1)) {
-   struct commit *parent = lookup_commit(parent_sha1);
+   struct object_id parent_oid;
+   if (!read_ref(t->ref, parent_oid.hash)) {
+   struct commit *parent = lookup_commit(parent_oid.hash);
if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, );
@@ -26,14 +26,14 @@ void create_notes_commit(struct notes_tree *t, struct 
commit_list *parents,
/* else: t->ref points to nothing, assume root/orphan commit */
}
 
-   if (commit_tree(msg, msg_len, tree_sha1, parents, result_sha1, NULL, 
NULL))
+   if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, 
NULL, NULL))
die("Failed to commit notes tree to database");
 }
 
 void commit_notes(struct notes_tree *t, const char *msg)
 {
struct strbuf buf = STRBUF_INIT;
-   unsigned char commit_sha1[20];
+   struct object_id commit_oid;
 
if (!t)
t = _notes_tree;
@@ -46,9 +46,9 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_addstr(, msg);
strbuf_complete_line();
 
-   create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1);
+   create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
strbuf_insert(, 0, "notes: ", 7); /* commit message starts at index 
7 */
-   update_ref(buf.buf, t->update_ref, commit_sha1, NULL, 0,
+   update_ref(buf.buf, t->update_ref, commit_oid.hash, NULL, 0,
   UPDATE_REFS_DIE_ON_ERR);
 
strbuf_release();


[PATCH v3 06/53] bundle: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert the bundle code, plus the sole external user of struct
ref_list_entry, to use struct object_id.  Include cache.h from within
bundle.h to provide the definition.  Convert some of the hash parsing
code to use parse_oid_hex to avoid needing to hard-code constant values.

Signed-off-by: brian m. carlson 
---
 bundle.c| 33 +
 bundle.h|  4 +++-
 transport.c |  2 +-
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/bundle.c b/bundle.c
index bbf4efa0a..6e181bb3d 100644
--- a/bundle.c
+++ b/bundle.c
@@ -12,11 +12,11 @@
 
 static const char bundle_signature[] = "# v2 git bundle\n";
 
-static void add_to_ref_list(const unsigned char *sha1, const char *name,
+static void add_to_ref_list(const struct object_id *oid, const char *name,
struct ref_list *list)
 {
ALLOC_GROW(list->list, list->nr + 1, list->alloc);
-   hashcpy(list->list[list->nr].sha1, sha1);
+   oidcpy(>list[list->nr].oid, oid);
list->list[list->nr].name = xstrdup(name);
list->nr++;
 }
@@ -40,8 +40,9 @@ static int parse_bundle_header(int fd, struct bundle_header 
*header,
/* The bundle header ends with an empty line */
while (!strbuf_getwholeline_fd(, fd, '\n') &&
   buf.len && buf.buf[0] != '\n') {
-   unsigned char sha1[20];
+   struct object_id oid;
int is_prereq = 0;
+   const char *p;
 
if (*buf.buf == '-') {
is_prereq = 1;
@@ -54,9 +55,9 @@ static int parse_bundle_header(int fd, struct bundle_header 
*header,
 * Prerequisites have object name that is optionally
 * followed by SP and subject line.
 */
-   if (get_sha1_hex(buf.buf, sha1) ||
-   (buf.len > 40 && !isspace(buf.buf[40])) ||
-   (!is_prereq && buf.len <= 40)) {
+   if (parse_oid_hex(buf.buf, , ) ||
+   (*p && !isspace(*p)) ||
+   (!is_prereq && !*p)) {
if (report_path)
error(_("unrecognized header: %s%s (%d)"),
  (is_prereq ? "-" : ""), buf.buf, 
(int)buf.len);
@@ -64,9 +65,9 @@ static int parse_bundle_header(int fd, struct bundle_header 
*header,
break;
} else {
if (is_prereq)
-   add_to_ref_list(sha1, "", 
>prerequisites);
+   add_to_ref_list(, "", 
>prerequisites);
else
-   add_to_ref_list(sha1, buf.buf + 41, 
>references);
+   add_to_ref_list(, p + 1, 
>references);
}
}
 
@@ -115,7 +116,7 @@ static int list_refs(struct ref_list *r, int argc, const 
char **argv)
if (j == argc)
continue;
}
-   printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
+   printf("%s %s\n", oid_to_hex(>list[i].oid),
r->list[i].name);
}
return 0;
@@ -141,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
init_revisions(, NULL);
for (i = 0; i < p->nr; i++) {
struct ref_list_entry *e = p->list + i;
-   struct object *o = parse_object(e->sha1);
+   struct object *o = parse_object(e->oid.hash);
if (o) {
o->flags |= PREREQ_MARK;
add_pending_object(, o, e->name);
@@ -149,7 +150,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
}
if (++ret == 1)
error("%s", message);
-   error("%s %s", sha1_to_hex(e->sha1), e->name);
+   error("%s %s", oid_to_hex(>oid), e->name);
}
if (revs.pending.nr != p->nr)
return ret;
@@ -285,16 +286,16 @@ static int compute_and_write_prerequisites(int bundle_fd,
return -1;
rls_fout = xfdopen(rls.out, "r");
while (strbuf_getwholeline(, rls_fout, '\n') != EOF) {
-   unsigned char sha1[20];
+   struct object_id oid;
if (buf.len > 0 && buf.buf[0] == '-') {
write_or_die(bundle_fd, buf.buf, buf.len);
-   if (!get_sha1_hex(buf.buf + 1, sha1)) {
-   struct object *object = 
parse_object_or_die(sha1, buf.buf);
+   if (!get_oid_hex(buf.buf + 1, )) {
+   struct object *object = 
parse_object_or_die(oid.hash, buf.buf);
object->flags |= UNINTERESTING;
add_pending_object(revs, object, buf.buf);
}
-   } else if 

[PATCH v3 11/53] fast-import: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert the remaining parts of fast-import.c to use struct object_id.
Convert several instances of get_sha1_hex to parse_oid_hex to avoid
needing to specify constants.  Convert other hardcoded values to named
constants.  Finally, use the is_empty_tree_oid function instead of a
direct comparison against a fixed string.

Note that the odd computation with GIT_MAX_HEXSZ is due to the insertion
of a slash between every two hex digits in the path, plus one for the
terminating NUL.

Signed-off-by: brian m. carlson 
---
 fast-import.c | 317 +-
 1 file changed, 159 insertions(+), 158 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 0212635dd..ba886c9e7 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -557,7 +557,7 @@ static void alloc_objects(unsigned int cnt)
alloc_count += cnt;
 }
 
-static struct object_entry *new_object(unsigned char *sha1)
+static struct object_entry *new_object(struct object_id *oid)
 {
struct object_entry *e;
 
@@ -565,32 +565,32 @@ static struct object_entry *new_object(unsigned char 
*sha1)
alloc_objects(object_entry_alloc);
 
e = blocks->next_free++;
-   hashcpy(e->idx.sha1, sha1);
+   hashcpy(e->idx.sha1, oid->hash);
return e;
 }
 
-static struct object_entry *find_object(unsigned char *sha1)
+static struct object_entry *find_object(struct object_id *oid)
 {
-   unsigned int h = sha1[0] << 8 | sha1[1];
+   unsigned int h = oid->hash[0] << 8 | oid->hash[1];
struct object_entry *e;
for (e = object_table[h]; e; e = e->next)
-   if (!hashcmp(sha1, e->idx.sha1))
+   if (!hashcmp(oid->hash, e->idx.sha1))
return e;
return NULL;
 }
 
-static struct object_entry *insert_object(unsigned char *sha1)
+static struct object_entry *insert_object(struct object_id *oid)
 {
-   unsigned int h = sha1[0] << 8 | sha1[1];
+   unsigned int h = oid->hash[0] << 8 | oid->hash[1];
struct object_entry *e = object_table[h];
 
while (e) {
-   if (!hashcmp(sha1, e->idx.sha1))
+   if (!hashcmp(oid->hash, e->idx.sha1))
return e;
e = e->next;
}
 
-   e = new_object(sha1);
+   e = new_object(oid);
e->next = object_table[h];
e->idx.offset = 0;
object_table[h] = e;
@@ -1007,17 +1007,17 @@ static void end_packfile(void)
clear_delta_base_cache();
if (object_count) {
struct packed_git *new_p;
-   unsigned char cur_pack_sha1[20];
+   struct object_id cur_pack_oid;
char *idx_name;
int i;
struct branch *b;
struct tag *t;
 
close_pack_windows(pack_data);
-   sha1close(pack_file, cur_pack_sha1, 0);
+   sha1close(pack_file, cur_pack_oid.hash, 0);
fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
pack_data->pack_name, object_count,
-   cur_pack_sha1, pack_size);
+   cur_pack_oid.hash, pack_size);
 
if (object_count <= unpack_limit) {
if (!loosen_small_pack(pack_data)) {
@@ -1083,13 +1083,13 @@ static int store_object(
enum object_type type,
struct strbuf *dat,
struct last_object *last,
-   unsigned char *sha1out,
+   struct object_id *oidout,
uintmax_t mark)
 {
void *out, *delta;
struct object_entry *e;
unsigned char hdr[96];
-   unsigned char sha1[20];
+   struct object_id oid;
unsigned long hdrlen, deltalen;
git_SHA_CTX c;
git_zstream s;
@@ -1099,17 +1099,17 @@ static int store_object(
git_SHA1_Init();
git_SHA1_Update(, hdr, hdrlen);
git_SHA1_Update(, dat->buf, dat->len);
-   git_SHA1_Final(sha1, );
-   if (sha1out)
-   hashcpy(sha1out, sha1);
+   git_SHA1_Final(oid.hash, );
+   if (oidout)
+   oidcpy(oidout, );
 
-   e = insert_object(sha1);
+   e = insert_object();
if (mark)
insert_mark(mark, e);
if (e->idx.offset) {
duplicate_count_by_type[type]++;
return 1;
-   } else if (find_sha1_pack(sha1, packed_git)) {
+   } else if (find_sha1_pack(oid.hash, packed_git)) {
e->type = type;
e->pack_id = MAX_PACK_ID;
e->idx.offset = 1; /* just not zero! */
@@ -1222,13 +1222,13 @@ static void truncate_pack(struct sha1file_checkpoint 
*checkpoint)
pack_size = checkpoint->offset;
 }
 
-static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
+static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t 
mark)
 {
size_t in_sz = 64 

[PATCH v3 13/53] notes-cache: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert as many instances of unsigned char [20] as possible.  Update the
callers of notes_cache_get and notes_cache_put to use the new interface.
Among the functions updated are callers of
lookup_commit_reference_gently, which we will soon convert.

Signed-off-by: brian m. carlson 
---
 diff.c|  4 ++--
 notes-cache.c | 29 ++---
 notes-cache.h |  4 ++--
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/diff.c b/diff.c
index 11eef1c85..3bd23ae4c 100644
--- a/diff.c
+++ b/diff.c
@@ -5244,7 +5244,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
 
if (driver->textconv_cache && df->oid_valid) {
*outbuf = notes_cache_get(driver->textconv_cache,
- df->oid.hash,
+ >oid,
  );
if (*outbuf)
return size;
@@ -5256,7 +5256,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
 
if (driver->textconv_cache && df->oid_valid) {
/* ignore errors, as we might be in a readonly repository */
-   notes_cache_put(driver->textconv_cache, df->oid.hash, *outbuf,
+   notes_cache_put(driver->textconv_cache, >oid, *outbuf,
size);
/*
 * we could save up changes and flush them all at the end,
diff --git a/notes-cache.c b/notes-cache.c
index 5dfc5cbd0..1cdd4984a 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -5,16 +5,16 @@
 
 static int notes_cache_match_validity(const char *ref, const char *validity)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct commit *commit;
struct pretty_print_context pretty_ctx;
struct strbuf msg = STRBUF_INIT;
int ret;
 
-   if (read_ref(ref, sha1) < 0)
+   if (read_ref(ref, oid.hash) < 0)
return 0;
 
-   commit = lookup_commit_reference_gently(sha1, 1);
+   commit = lookup_commit_reference_gently(oid.hash, 1);
if (!commit)
return 0;
 
@@ -46,8 +46,7 @@ void notes_cache_init(struct notes_cache *c, const char *name,
 
 int notes_cache_write(struct notes_cache *c)
 {
-   unsigned char tree_sha1[20];
-   unsigned char commit_sha1[20];
+   struct object_id tree_oid, commit_oid;
 
if (!c || !c->tree.initialized || !c->tree.update_ref ||
!*c->tree.update_ref)
@@ -55,19 +54,19 @@ int notes_cache_write(struct notes_cache *c)
if (!c->tree.dirty)
return 0;
 
-   if (write_notes_tree(>tree, tree_sha1))
+   if (write_notes_tree(>tree, tree_oid.hash))
return -1;
-   if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL,
-   commit_sha1, NULL, NULL) < 0)
+   if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
+   commit_oid.hash, NULL, NULL) < 0)
return -1;
-   if (update_ref("update notes cache", c->tree.update_ref, commit_sha1,
+   if (update_ref("update notes cache", c->tree.update_ref, 
commit_oid.hash,
   NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
return -1;
 
return 0;
 }
 
-char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20],
+char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
  size_t *outsize)
 {
const unsigned char *value_sha1;
@@ -75,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, unsigned char 
key_sha1[20],
char *value;
unsigned long size;
 
-   value_sha1 = get_note(>tree, key_sha1);
+   value_sha1 = get_note(>tree, key_oid->hash);
if (!value_sha1)
return NULL;
value = read_sha1_file(value_sha1, , );
@@ -84,12 +83,12 @@ char *notes_cache_get(struct notes_cache *c, unsigned char 
key_sha1[20],
return value;
 }
 
-int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20],
+int notes_cache_put(struct notes_cache *c, struct object_id *key_oid,
const char *data, size_t size)
 {
-   unsigned char value_sha1[20];
+   struct object_id value_oid;
 
-   if (write_sha1_file(data, size, "blob", value_sha1) < 0)
+   if (write_sha1_file(data, size, "blob", value_oid.hash) < 0)
return -1;
-   return add_note(>tree, key_sha1, value_sha1, NULL);
+   return add_note(>tree, key_oid->hash, value_oid.hash, NULL);
 }
diff --git a/notes-cache.h b/notes-cache.h
index 356f88fb3..a8409 100644
--- a/notes-cache.h
+++ b/notes-cache.h
@@ -12,9 +12,9 @@ void notes_cache_init(struct notes_cache *c, const char *name,
 const char *validity);
 int notes_cache_write(struct notes_cache *c);
 
-char *notes_cache_get(struct notes_cache *c, unsigned char sha1[20], size_t
+char *notes_cache_get(struct 

[PATCH v3 14/53] parse-options-cb: convert to struct object_id

2017-05-06 Thread brian m. carlson
This is a caller of lookup_commit_reference, which we will soon convert.

Signed-off-by: brian m. carlson 
---
 parse-options-cb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/parse-options-cb.c b/parse-options-cb.c
index 7419780a9..35a941fdd 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -80,14 +80,14 @@ int parse_opt_verbosity_cb(const struct option *opt, const 
char *arg,
 
 int parse_opt_commits(const struct option *opt, const char *arg, int unset)
 {
-   unsigned char sha1[20];
+   struct object_id oid;
struct commit *commit;
 
if (!arg)
return -1;
-   if (get_sha1(arg, sha1))
+   if (get_oid(arg, ))
return error("malformed object name %s", arg);
-   commit = lookup_commit_reference(sha1);
+   commit = lookup_commit_reference(oid.hash);
if (!commit)
return error("no such commit %s", arg);
commit_list_insert(commit, opt->value);


[PATCH v3 04/53] builtin/name-rev: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert all the uses of unsigned char [20] to struct object_id.  Also,
convert some hard-coded integers into constants.

name_rev_line accepts a wide variety of free-form input and only
interprets 40-character hex values, passing through everything else.
Consequently, it is not a good candidate for parse_oid_hex, which is
much stricter.

This change is a prerequisite for converting parse_object.

Signed-off-by: brian m. carlson 
---
 builtin/name-rev.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 92a5d8a5d..00760ecc6 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -114,7 +114,7 @@ struct name_ref_data {
 
 static struct tip_table {
struct tip_table_entry {
-   unsigned char sha1[20];
+   struct object_id oid;
const char *refname;
} *table;
int nr;
@@ -122,13 +122,13 @@ static struct tip_table {
int sorted;
 } tip_table;
 
-static void add_to_tip_table(const unsigned char *sha1, const char *refname,
+static void add_to_tip_table(const struct object_id *oid, const char *refname,
 int shorten_unambiguous)
 {
refname = name_ref_abbrev(refname, shorten_unambiguous);
 
ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
-   hashcpy(tip_table.table[tip_table.nr].sha1, sha1);
+   oidcpy(_table.table[tip_table.nr].oid, oid);
tip_table.table[tip_table.nr].refname = xstrdup(refname);
tip_table.nr++;
tip_table.sorted = 0;
@@ -137,7 +137,7 @@ static void add_to_tip_table(const unsigned char *sha1, 
const char *refname,
 static int tipcmp(const void *a_, const void *b_)
 {
const struct tip_table_entry *a = a_, *b = b_;
-   return hashcmp(a->sha1, b->sha1);
+   return oidcmp(>oid, >oid);
 }
 
 static int name_ref(const char *path, const struct object_id *oid, int flags, 
void *cb_data)
@@ -194,7 +194,7 @@ static int name_ref(const char *path, const struct 
object_id *oid, int flags, vo
return 0;
}
 
-   add_to_tip_table(oid->hash, path, can_abbreviate_output);
+   add_to_tip_table(oid, path, can_abbreviate_output);
 
while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o;
@@ -216,7 +216,7 @@ static int name_ref(const char *path, const struct 
object_id *oid, int flags, vo
 static const unsigned char *nth_tip_table_ent(size_t ix, void *table_)
 {
struct tip_table_entry *table = table_;
-   return table[ix].sha1;
+   return table[ix].oid.hash;
 }
 
 static const char *get_exact_ref_match(const struct object *o)
@@ -301,9 +301,9 @@ static void name_rev_line(char *p, struct name_ref_data 
*data)
 #define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
if (!ishex(*p))
forty = 0;
-   else if (++forty == 40 &&
+   else if (++forty == GIT_SHA1_HEXSZ &&
 !ishex(*(p+1))) {
-   unsigned char sha1[40];
+   struct object_id oid;
const char *name = NULL;
char c = *(p+1);
int p_len = p - p_start + 1;
@@ -311,9 +311,9 @@ static void name_rev_line(char *p, struct name_ref_data 
*data)
forty = 0;
 
*(p+1) = 0;
-   if (!get_sha1(p - 39, sha1)) {
+   if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), )) {
struct object *o =
-   lookup_object(sha1);
+   lookup_object(oid.hash);
if (o)
name = get_rev_name(o, );
}
@@ -323,7 +323,7 @@ static void name_rev_line(char *p, struct name_ref_data 
*data)
continue;
 
if (data->name_only)
-   printf("%.*s%s", p_len - 40, p_start, name);
+   printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, 
p_start, name);
else
printf("%.*s (%s)", p_len, p_start, name);
p_start = p + 1;
@@ -374,18 +374,18 @@ int cmd_name_rev(int argc, const char **argv, const char 
*prefix)
cutoff = 0;
 
for (; argc; argc--, argv++) {
-   unsigned char sha1[20];
+   struct object_id oid;
struct object *object;
struct commit *commit;
 
-   if (get_sha1(*argv, sha1)) {
+   if (get_oid(*argv, )) {
fprintf(stderr, "Could not get sha1 for %s. 
Skipping.\n",
*argv);
continue;
}
 

[PATCH v3 10/53] fast-import: convert internal structs to struct object_id

2017-05-06 Thread brian m. carlson
Convert struct tree_entry_ms, struct branch, struct tag, and struct
hash_list to use struct object_id by changing the definition and
applying the following semantic patch, plus the standard object_id
transforms:

@@
struct tree_entry_ms E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct tree_entry_ms *E1;
@@
- E1->sha1
+ E1->oid.hash

@@
struct branch E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct branch *E1;
@@
- E1->sha1
+ E1->oid.hash

@@
struct tag E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct tag *E1;
@@
- E1->sha1
+ E1->oid.hash

@@
struct hash_list E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct hash_list *E1;
@@
- E1->sha1
+ E1->oid.hash

Signed-off-by: brian m. carlson 
---
 fast-import.c | 182 +++---
 1 file changed, 96 insertions(+), 86 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index cf58f875b..0212635dd 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -226,7 +226,7 @@ struct tree_entry {
struct atom_str *name;
struct tree_entry_ms {
uint16_t mode;
-   unsigned char sha1[20];
+   struct object_id oid;
} versions[2];
 };
 
@@ -252,19 +252,19 @@ struct branch {
unsigned active : 1;
unsigned delete : 1;
unsigned pack_id : PACK_ID_BITS;
-   unsigned char sha1[20];
+   struct object_id oid;
 };
 
 struct tag {
struct tag *next_tag;
const char *name;
unsigned int pack_id;
-   unsigned char sha1[20];
+   struct object_id oid;
 };
 
 struct hash_list {
struct hash_list *next;
-   unsigned char sha1[20];
+   struct object_id oid;
 };
 
 typedef enum {
@@ -386,13 +386,15 @@ static void write_branch_report(FILE *rpt, struct branch 
*b)
fputs(" active", rpt);
if (b->branch_tree.tree)
fputs(" loaded", rpt);
-   if (is_null_sha1(b->branch_tree.versions[1].sha1))
+   if (is_null_oid(>branch_tree.versions[1].oid))
fputs(" dirty", rpt);
fputc('\n', rpt);
 
-   fprintf(rpt, "  tip commit  : %s\n", sha1_to_hex(b->sha1));
-   fprintf(rpt, "  old tree: %s\n", 
sha1_to_hex(b->branch_tree.versions[0].sha1));
-   fprintf(rpt, "  cur tree: %s\n", 
sha1_to_hex(b->branch_tree.versions[1].sha1));
+   fprintf(rpt, "  tip commit  : %s\n", oid_to_hex(>oid));
+   fprintf(rpt, "  old tree: %s\n",
+   oid_to_hex(>branch_tree.versions[0].oid));
+   fprintf(rpt, "  cur tree: %s\n",
+   oid_to_hex(>branch_tree.versions[1].oid));
fprintf(rpt, "  commit clock: %" PRIuMAX "\n", b->last_commit);
 
fputs("  last pack   : ", rpt);
@@ -470,7 +472,7 @@ static void write_crash_report(const char *err)
fputs("Annotated Tags\n", rpt);
fputs("--\n", rpt);
for (tg = first_tag; tg; tg = tg->next_tag) {
-   fputs(sha1_to_hex(tg->sha1), rpt);
+   fputs(oid_to_hex(>oid), rpt);
fputc(' ', rpt);
fputs(tg->name, rpt);
fputc('\n', rpt);
@@ -876,7 +878,7 @@ static struct tree_content *dup_tree_content(struct 
tree_content *s)
a = s->entries[i];
b = new_tree_entry();
memcpy(b, a, sizeof(*a));
-   if (a->tree && is_null_sha1(b->versions[1].sha1))
+   if (a->tree && is_null_oid(>versions[1].oid))
b->tree = dup_tree_content(a->tree);
else
b->tree = NULL;
@@ -1041,12 +1043,14 @@ static void end_packfile(void)
for (i = 0; i < branch_table_sz; i++) {
for (b = branch_table[i]; b; b = 
b->table_next_branch) {
if (b->pack_id == pack_id)
-   fprintf(pack_edges, " %s", 
sha1_to_hex(b->sha1));
+   fprintf(pack_edges, " %s",
+   oid_to_hex(>oid));
}
}
for (t = first_tag; t; t = t->next_tag) {
if (t->pack_id == pack_id)
-   fprintf(pack_edges, " %s", 
sha1_to_hex(t->sha1));
+   fprintf(pack_edges, " %s",
+   oid_to_hex(>oid));
}
fputc('\n', pack_edges);
fflush(pack_edges);
@@ -1385,7 +1389,7 @@ static const char *get_mode(const char *str, uint16_t 
*modep)
 
 static void load_tree(struct tree_entry *root)
 {
-   unsigned char *sha1 = root->versions[1].sha1;
+   unsigned char *sha1 = root->versions[1].oid.hash;
struct object_entry *myoe;
struct 

[PATCH v3 05/53] builtin/prune: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert the sole instance of unsigned char [20] to struct object_id.
cmd_prune is a caller of parse_object, which we will convert later.

Signed-off-by: brian m. carlson 
---
 builtin/prune.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/prune.c b/builtin/prune.c
index 42633e0c6..96dca7d58 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -123,11 +123,11 @@ int cmd_prune(int argc, const char **argv, const char 
*prefix)
die(_("cannot prune in a precious-objects repo"));
 
while (argc--) {
-   unsigned char sha1[20];
+   struct object_id oid;
const char *name = *argv++;
 
-   if (!get_sha1(name, sha1)) {
-   struct object *object = parse_object_or_die(sha1, name);
+   if (!get_oid(name, )) {
+   struct object *object = parse_object_or_die(oid.hash, 
name);
add_pending_object(, object, "");
}
else


[PATCH v3 09/53] builtin/rev-parse: convert to struct object_id

2017-05-06 Thread brian m. carlson
Some of the functions converted are callers of lookup_commit_reference.
However, the changes involved in converting the entire thing are not too
large, so we might as well convert it all.

Signed-off-by: brian m. carlson 
---
 builtin/rev-parse.c | 56 ++---
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 051333091..4af122264 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -121,7 +121,7 @@ static void show_with_type(int type, const char *arg)
 }
 
 /* Output a revision, only if filter allows it */
-static void show_rev(int type, const unsigned char *sha1, const char *name)
+static void show_rev(int type, const struct object_id *oid, const char *name)
 {
if (!(filter & DO_REVS))
return;
@@ -129,10 +129,10 @@ static void show_rev(int type, const unsigned char *sha1, 
const char *name)
 
if ((symbolic || abbrev_ref) && name) {
if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
-   unsigned char discard[20];
+   struct object_id discard;
char *full;
 
-   switch (dwim_ref(name, strlen(name), discard, )) {
+   switch (dwim_ref(name, strlen(name), discard.hash, 
)) {
case 0:
/*
 * Not found -- not a ref.  We could
@@ -158,9 +158,9 @@ static void show_rev(int type, const unsigned char *sha1, 
const char *name)
}
}
else if (abbrev)
-   show_with_type(type, find_unique_abbrev(sha1, abbrev));
+   show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
else
-   show_with_type(type, sha1_to_hex(sha1));
+   show_with_type(type, oid_to_hex(oid));
 }
 
 /* Output a flag, only if filter allows it. */
@@ -180,11 +180,11 @@ static int show_default(void)
const char *s = def;
 
if (s) {
-   unsigned char sha1[20];
+   struct object_id oid;
 
def = NULL;
-   if (!get_sha1(s, sha1)) {
-   show_rev(NORMAL, sha1, s);
+   if (!get_oid(s, )) {
+   show_rev(NORMAL, , s);
return 1;
}
}
@@ -195,19 +195,19 @@ static int show_reference(const char *refname, const 
struct object_id *oid, int
 {
if (ref_excluded(ref_excludes, refname))
return 0;
-   show_rev(NORMAL, oid->hash, refname);
+   show_rev(NORMAL, oid, refname);
return 0;
 }
 
 static int anti_reference(const char *refname, const struct object_id *oid, 
int flag, void *cb_data)
 {
-   show_rev(REVERSED, oid->hash, refname);
+   show_rev(REVERSED, oid, refname);
return 0;
 }
 
 static int show_abbrev(const struct object_id *oid, void *cb_data)
 {
-   show_rev(NORMAL, oid->hash, NULL);
+   show_rev(NORMAL, oid, NULL);
return 0;
 }
 
@@ -242,8 +242,8 @@ static int show_file(const char *arg, int output_prefix)
 static int try_difference(const char *arg)
 {
char *dotdot;
-   unsigned char sha1[20];
-   unsigned char end[20];
+   struct object_id oid;
+   struct object_id end;
const char *next;
const char *this;
int symmetric;
@@ -273,18 +273,18 @@ static int try_difference(const char *arg)
return 0;
}
 
-   if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, 
end)) {
-   show_rev(NORMAL, end, next);
-   show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
+   if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, 
end.hash)) {
+   show_rev(NORMAL, , next);
+   show_rev(symmetric ? NORMAL : REVERSED, , this);
if (symmetric) {
struct commit_list *exclude;
struct commit *a, *b;
-   a = lookup_commit_reference(sha1);
-   b = lookup_commit_reference(end);
+   a = lookup_commit_reference(oid.hash);
+   b = lookup_commit_reference(end.hash);
exclude = get_merge_bases(a, b);
while (exclude) {
struct commit *commit = pop_commit();
-   show_rev(REVERSED, commit->object.oid.hash, 
NULL);
+   show_rev(REVERSED, >object.oid, NULL);
}
}
*dotdot = '.';
@@ -297,7 +297,7 @@ static int try_difference(const char *arg)
 static int try_parent_shorthands(const char *arg)
 {
char *dotdot;
-   unsigned char sha1[20];
+   struct object_id oid;
struct commit *commit;
struct 

[PATCH v3 12/53] submodule: convert merge_submodule to use struct object_id

2017-05-06 Thread brian m. carlson
This is a caller of lookup_commit_reference, which we will convert
later.

Signed-off-by: brian m. carlson 
---
 merge-recursive.c |  8 
 submodule.c   | 24 
 submodule.h   |  8 
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 9d6fd577e..1315a45b9 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -994,11 +994,11 @@ static int merge_file_1(struct merge_options *o,
return ret;
result->clean = (merge_status == 0);
} else if (S_ISGITLINK(a->mode)) {
-   result->clean = merge_submodule(result->oid.hash,
+   result->clean = merge_submodule(>oid,
   one->path,
-  one->oid.hash,
-  a->oid.hash,
-  b->oid.hash,
+  >oid,
+  >oid,
+  >oid,
   !o->call_depth);
} else if (S_ISLNK(a->mode)) {
oidcpy(>oid, >oid);
diff --git a/submodule.c b/submodule.c
index d3299e29c..9bdd5f605 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1566,9 +1566,9 @@ static void print_commit(struct commit *commit)
 #define MERGE_WARNING(path, msg) \
warning("Failed to merge submodule %s (%s)", path, msg);
 
-int merge_submodule(unsigned char result[20], const char *path,
-   const unsigned char base[20], const unsigned char a[20],
-   const unsigned char b[20], int search)
+int merge_submodule(struct object_id *result, const char *path,
+   const struct object_id *base, const struct object_id *a,
+   const struct object_id *b, int search)
 {
struct commit *commit_base, *commit_a, *commit_b;
int parent_count;
@@ -1577,14 +1577,14 @@ int merge_submodule(unsigned char result[20], const 
char *path,
int i;
 
/* store a in result in case we fail */
-   hashcpy(result, a);
+   oidcpy(result, a);
 
/* we can not handle deletion conflicts */
-   if (is_null_sha1(base))
+   if (is_null_oid(base))
return 0;
-   if (is_null_sha1(a))
+   if (is_null_oid(a))
return 0;
-   if (is_null_sha1(b))
+   if (is_null_oid(b))
return 0;
 
if (add_submodule_odb(path)) {
@@ -1592,9 +1592,9 @@ int merge_submodule(unsigned char result[20], const char 
*path,
return 0;
}
 
-   if (!(commit_base = lookup_commit_reference(base)) ||
-   !(commit_a = lookup_commit_reference(a)) ||
-   !(commit_b = lookup_commit_reference(b))) {
+   if (!(commit_base = lookup_commit_reference(base->hash)) ||
+   !(commit_a = lookup_commit_reference(a->hash)) ||
+   !(commit_b = lookup_commit_reference(b->hash))) {
MERGE_WARNING(path, "commits not present");
return 0;
}
@@ -1608,11 +1608,11 @@ int merge_submodule(unsigned char result[20], const 
char *path,
 
/* Case #1: a is contained in b or vice versa */
if (in_merge_bases(commit_a, commit_b)) {
-   hashcpy(result, b);
+   oidcpy(result, b);
return 1;
}
if (in_merge_bases(commit_b, commit_a)) {
-   hashcpy(result, a);
+   oidcpy(result, a);
return 1;
}
 
diff --git a/submodule.h b/submodule.h
index 1277480ad..89c2ed219 100644
--- a/submodule.h
+++ b/submodule.h
@@ -84,10 +84,10 @@ extern int submodule_uses_gitfile(const char *path);
 #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1)
 #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
 extern int bad_to_remove_submodule(const char *path, unsigned flags);
-extern int merge_submodule(unsigned char result[20], const char *path,
-  const unsigned char base[20],
-  const unsigned char a[20],
-  const unsigned char b[20], int search);
+extern int merge_submodule(struct object_id *result, const char *path,
+  const struct object_id *base,
+  const struct object_id *a,
+  const struct object_id *b, int search);
 extern int find_unpushed_submodules(struct oid_array *commits,
const char *remotes_name,
struct string_list *needs_pushing);


[PATCH v3 08/53] builtin/blame: convert static function to struct object_id

2017-05-06 Thread brian m. carlson
This function is a caller of lookup_commit_reference_gently, which we
will convert later.

Signed-off-by: brian m. carlson 
---
 builtin/blame.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 07506a3e4..7d644d092 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2461,7 +2461,7 @@ static const char *dwim_reverse_initial(struct scoreboard 
*sb)
 */
struct object *obj;
struct commit *head_commit;
-   unsigned char head_sha1[20];
+   struct object_id head_oid;
 
if (sb->revs->pending.nr != 1)
return NULL;
@@ -2473,9 +2473,9 @@ static const char *dwim_reverse_initial(struct scoreboard 
*sb)
return NULL;
 
/* Do we have HEAD? */
-   if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
+   if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, 
NULL))
return NULL;
-   head_commit = lookup_commit_reference_gently(head_sha1, 1);
+   head_commit = lookup_commit_reference_gently(head_oid.hash, 1);
if (!head_commit)
return NULL;
 


[PATCH v3 07/53] branch: convert to struct object_id

2017-05-06 Thread brian m. carlson
This change is required to convert lookup_commit_reference later.

Signed-off-by: brian m. carlson 
---
 branch.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/branch.c b/branch.c
index ad5a2299b..1758c9708 100644
--- a/branch.c
+++ b/branch.c
@@ -191,9 +191,9 @@ int validate_new_branchname(const char *name, struct strbuf 
*ref,
 
if (!attr_only) {
const char *head;
-   unsigned char sha1[20];
+   struct object_id oid;
 
-   head = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
+   head = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL);
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
die(_("Cannot force update the current branch."));
}
@@ -233,7 +233,7 @@ void create_branch(const char *name, const char *start_name,
   int quiet, enum branch_track track)
 {
struct commit *commit;
-   unsigned char sha1[20];
+   struct object_id oid;
char *real_ref;
struct strbuf ref = STRBUF_INIT;
int forcing = 0;
@@ -253,7 +253,7 @@ void create_branch(const char *name, const char *start_name,
}
 
real_ref = NULL;
-   if (get_sha1(start_name, sha1)) {
+   if (get_oid(start_name, )) {
if (explicit_tracking) {
if (advice_set_upstream_failure) {
error(_(upstream_missing), start_name);
@@ -265,7 +265,7 @@ void create_branch(const char *name, const char *start_name,
die(_("Not a valid object name: '%s'."), start_name);
}
 
-   switch (dwim_ref(start_name, strlen(start_name), sha1, _ref)) {
+   switch (dwim_ref(start_name, strlen(start_name), oid.hash, _ref)) {
case 0:
/* Not branching from any existing branch */
if (explicit_tracking)
@@ -286,9 +286,9 @@ void create_branch(const char *name, const char *start_name,
break;
}
 
-   if ((commit = lookup_commit_reference(sha1)) == NULL)
+   if ((commit = lookup_commit_reference(oid.hash)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
-   hashcpy(sha1, commit->object.oid.hash);
+   oidcpy(, >object.oid);
 
if (reflog)
log_all_ref_updates = LOG_REFS_NORMAL;
@@ -306,7 +306,7 @@ void create_branch(const char *name, const char *start_name,
transaction = ref_transaction_begin();
if (!transaction ||
ref_transaction_update(transaction, ref.buf,
-  sha1, forcing ? NULL : null_sha1,
+  oid.hash, forcing ? NULL : null_sha1,
   0, msg, ) ||
ref_transaction_commit(transaction, ))
die("%s", err.buf);


[PATCH v3 03/53] Convert struct cache_tree to use struct object_id

2017-05-06 Thread brian m. carlson
Convert the sha1 member of struct cache_tree to struct object_id by
changing the definition and applying the following semantic patch, plus
the standard object_id transforms:

@@
struct cache_tree E1;
@@
- E1.sha1
+ E1.oid.hash

@@
struct cache_tree *E1;
@@
- E1->sha1
+ E1->oid.hash

Fix up one reference to active_cache_tree which was not automatically
caught by Coccinelle.  These changes are prerequisites for converting
parse_object.

Signed-off-by: brian m. carlson 
---
 builtin/commit.c|  2 +-
 builtin/fsck.c  |  4 ++--
 cache-tree.c| 31 ---
 cache-tree.h|  3 ++-
 merge-recursive.c   |  2 +-
 revision.c  |  2 +-
 sequencer.c |  3 ++-
 t/helper/test-dump-cache-tree.c |  4 ++--
 8 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 1d805f5da..8685c888f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1758,7 +1758,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
append_merge_tag_headers(parents, );
}
 
-   if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
+   if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
 parents, oid.hash, author_ident.buf, sign_commit, 
extra)) {
rollback_index_files();
die(_("failed to write commit object"));
diff --git a/builtin/fsck.c b/builtin/fsck.c
index b5e13a455..c40e14de6 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -599,10 +599,10 @@ static int fsck_cache_tree(struct cache_tree *it)
fprintf(stderr, "Checking cache tree\n");
 
if (0 <= it->entry_count) {
-   struct object *obj = parse_object(it->sha1);
+   struct object *obj = parse_object(it->oid.hash);
if (!obj) {
error("%s: invalid sha1 pointer in cache-tree",
- sha1_to_hex(it->sha1));
+ oid_to_hex(>oid));
errors_found |= ERROR_REFS;
return 1;
}
diff --git a/cache-tree.c b/cache-tree.c
index 345ea3596..35d507ed7 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
int i;
if (!it)
return 0;
-   if (it->entry_count < 0 || !has_sha1_file(it->sha1))
+   if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
 
*skip_count = 0;
 
-   if (0 <= it->entry_count && has_sha1_file(it->sha1))
+   if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
return it->entry_count;
 
/*
@@ -340,7 +340,7 @@ static int update_one(struct cache_tree *it,
die("cache-tree.c: '%.*s' in '%s' not found",
entlen, path + baselen, path);
i += sub->count;
-   sha1 = sub->cache_tree->sha1;
+   sha1 = sub->cache_tree->oid.hash;
mode = S_IFDIR;
contains_ita = sub->cache_tree->entry_count < 0;
if (contains_ita) {
@@ -402,12 +402,13 @@ static int update_one(struct cache_tree *it,
unsigned char sha1[20];
hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1);
if (has_sha1_file(sha1))
-   hashcpy(it->sha1, sha1);
+   hashcpy(it->oid.hash, sha1);
else
to_invalidate = 1;
} else if (dryrun)
-   hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1);
-   else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) {
+   hash_sha1_file(buffer.buf, buffer.len, tree_type,
+  it->oid.hash);
+   else if (write_sha1_file(buffer.buf, buffer.len, tree_type, 
it->oid.hash)) {
strbuf_release();
return -1;
}
@@ -417,7 +418,7 @@ static int update_one(struct cache_tree *it,
 #if DEBUG
fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
it->entry_count, it->subtree_nr,
-   sha1_to_hex(it->sha1));
+   oid_to_hex(>oid));
 #endif
return i;
 }
@@ -457,14 +458,14 @@ static void write_one(struct strbuf *buffer, struct 
cache_tree *it,
if (0 <= it->entry_count)
fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
pathlen, path, it->entry_count, it->subtree_nr,
- 

[PATCH v3 02/53] Clean up outstanding object_id transforms.

2017-05-06 Thread brian m. carlson
The semantic patch for standard object_id transforms found two
outstanding places where we could make a transformation automatically.
Apply these changes.

Signed-off-by: brian m. carlson 
---
 builtin/diff.c | 2 +-
 reflog-walk.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/diff.c b/builtin/diff.c
index d184aafab..a25b4e4ae 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -408,7 +408,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
} else if (obj->type == OBJ_BLOB) {
if (2 <= blobs)
die(_("more than two blobs given: '%s'"), name);
-   hashcpy(blob[blobs].oid.hash, obj->oid.hash);
+   oidcpy([blobs].oid, >oid);
blob[blobs].name = name;
blob[blobs].mode = entry->mode;
blobs++;
diff --git a/reflog-walk.c b/reflog-walk.c
index 99679f582..c8fdf051d 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -241,7 +241,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, 
struct commit *commit)
logobj = parse_object(reflog->ooid.hash);
} while (commit_reflog->recno && (logobj && logobj->type != 
OBJ_COMMIT));
 
-   if (!logobj && commit_reflog->recno >= 0 && 
is_null_sha1(reflog->ooid.hash)) {
+   if (!logobj && commit_reflog->recno >= 0 && is_null_oid(>ooid)) 
{
/* a root commit, but there are still more entries to show */
reflog = _reflog->reflogs->items[commit_reflog->recno];
logobj = parse_object(reflog->noid.hash);


[PATCH v3 01/53] fetch-pack: convert to struct object_id

2017-05-06 Thread brian m. carlson
Convert all uses of unsigned char [20] to struct object_id.  Switch one
use of get_sha1_hex to parse_oid_hex to avoid the need for a constant.
This change is necessary in order to convert parse_object.

Signed-off-by: brian m. carlson 
---
 fetch-pack.c | 89 ++--
 1 file changed, 45 insertions(+), 44 deletions(-)

diff --git a/fetch-pack.c b/fetch-pack.c
index afb8b0502..b42d01f42 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -118,9 +118,9 @@ static void rev_list_push(struct commit *commit, int mark)
}
 }
 
-static int rev_list_insert_ref(const char *refname, const unsigned char *sha1)
+static int rev_list_insert_ref(const char *refname, const struct object_id 
*oid)
 {
-   struct object *o = deref_tag(parse_object(sha1), refname, 0);
+   struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
 
if (o && o->type == OBJ_COMMIT)
rev_list_push((struct commit *)o, SEEN);
@@ -131,7 +131,7 @@ static int rev_list_insert_ref(const char *refname, const 
unsigned char *sha1)
 static int rev_list_insert_ref_oid(const char *refname, const struct object_id 
*oid,
   int flag, void *cb_data)
 {
-   return rev_list_insert_ref(refname, oid->hash);
+   return rev_list_insert_ref(refname, oid);
 }
 
 static int clear_marks(const char *refname, const struct object_id *oid,
@@ -183,7 +183,7 @@ static void mark_common(struct commit *commit,
   Get the next rev to send, ignoring the common.
 */
 
-static const unsigned char *get_rev(void)
+static const struct object_id *get_rev(void)
 {
struct commit *commit = NULL;
 
@@ -222,7 +222,7 @@ static const unsigned char *get_rev(void)
}
}
 
-   return commit->object.oid.hash;
+   return >object.oid;
 }
 
 enum ack_type {
@@ -251,7 +251,7 @@ static void consume_shallow_list(struct fetch_pack_args 
*args, int fd)
}
 }
 
-static enum ack_type get_ack(int fd, unsigned char *result_sha1)
+static enum ack_type get_ack(int fd, struct object_id *result_oid)
 {
int len;
char *line = packet_read_line(fd, );
@@ -262,7 +262,7 @@ static enum ack_type get_ack(int fd, unsigned char 
*result_sha1)
if (!strcmp(line, "NAK"))
return NAK;
if (skip_prefix(line, "ACK ", )) {
-   if (!get_sha1_hex(arg, result_sha1)) {
+   if (!get_oid_hex(arg, result_oid)) {
arg += 40;
len -= arg - line;
if (len < 1)
@@ -293,7 +293,7 @@ static void send_request(struct fetch_pack_args *args,
 
 static void insert_one_alternate_object(struct object *obj)
 {
-   rev_list_insert_ref(NULL, obj->oid.hash);
+   rev_list_insert_ref(NULL, >oid);
 }
 
 #define INITIAL_FLUSH 16
@@ -317,12 +317,12 @@ static int next_flush(struct fetch_pack_args *args, int 
count)
 }
 
 static int find_common(struct fetch_pack_args *args,
-  int fd[2], unsigned char *result_sha1,
+  int fd[2], struct object_id *result_oid,
   struct ref *refs)
 {
int fetching;
int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
-   const unsigned char *sha1;
+   const struct object_id *oid;
unsigned in_vain = 0;
int got_continue = 0;
int got_ready = 0;
@@ -340,7 +340,7 @@ static int find_common(struct fetch_pack_args *args,
 
fetching = 0;
for ( ; refs ; refs = refs->next) {
-   unsigned char *remote = refs->old_oid.hash;
+   struct object_id *remote = >old_oid;
const char *remote_hex;
struct object *o;
 
@@ -354,12 +354,12 @@ static int find_common(struct fetch_pack_args *args,
 * interested in the case we *know* the object is
 * reachable and we have already scanned it.
 */
-   if (((o = lookup_object(remote)) != NULL) &&
+   if (((o = lookup_object(remote->hash)) != NULL) &&
(o->flags & COMPLETE)) {
continue;
}
 
-   remote_hex = sha1_to_hex(remote);
+   remote_hex = oid_to_hex(remote);
if (!fetching) {
struct strbuf c = STRBUF_INIT;
if (multi_ack == 2) strbuf_addstr(, " 
multi_ack_detailed");
@@ -410,25 +410,25 @@ static int find_common(struct fetch_pack_args *args,
if (args->deepen) {
char *line;
const char *arg;
-   unsigned char sha1[20];
+   struct object_id oid;
 
send_request(args, fd[1], _buf);
while ((line = packet_read_line(fd[0], NULL))) {
if (skip_prefix(line, "shallow ", )) {
-   if (get_sha1_hex(arg, sha1))
+ 

[PATCH v3 00/53] object_id part 8

2017-05-06 Thread brian m. carlson
This is the eighth series of patches to convert unsigned char [20] to
struct object_id.  This series converts lookup_commit, lookup_blob,
lookup_tree, lookup_tag, and finally parse_object to struct object_id.

A small number of functions have temporaries inserted during the
conversion in order to allow conversion of functions that still need to
take unsigned char *; they are removed either later in the series or
will be in a future series.

This series can be fetched from the object-id-part8 branch from either
of the follwing:

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

Changes from v2:
* Remove spurious space after ampersand.
* Undo more needless line rewrapping.
* Expand computation for notes path.
* Remove check for line->len with parse_oid_hex.

Changes from v1:
* Rebase on master.  This led to a conflict with the ref-cache changes in patch
  39.  Extra-careful review here would be welcome.
* Undo the needless line rewrapping.
* Fix the commit message typo.
* Use GIT_MAX_RAWSZ instead of struct object_id for the pack checksum.

brian m. carlson (53):
  fetch-pack: convert to struct object_id
  Clean up outstanding object_id transforms.
  Convert struct cache_tree to use struct object_id
  builtin/name-rev: convert to struct object_id
  builtin/prune: convert to struct object_id
  bundle: convert to struct object_id
  branch: convert to struct object_id
  builtin/blame: convert static function to struct object_id
  builtin/rev-parse: convert to struct object_id
  fast-import: convert internal structs to struct object_id
  fast-import: convert to struct object_id
  submodule: convert merge_submodule to use struct object_id
  notes-cache: convert to struct object_id
  parse-options-cb: convert to struct object_id
  reflog_expire: convert to struct object_id
  builtin/verify-commit: convert to struct object_id
  tag: convert parse_tag_buffer to struct object_id
  http-push: convert some static functions to struct object_id
  notes-utils: convert internals to struct object_id
  revision: convert prepare_show_merge to struct object_id
  shallow: convert shallow registration functions to object_id
  sequencer: convert some functions to struct object_id
  builtin/tag: convert to struct object_id
  Convert remaining callers of lookup_commit_reference* to object_id
  Convert lookup_commit* to struct object_id
  pack: convert struct pack_idx_entry to struct object_id
  builtin/unpack-objects: convert to struct object_id
  Convert remaining callers of lookup_blob to object_id
  Convert lookup_blob to struct object_id
  tree: convert read_tree_1 to use struct object_id internally
  builtin/reflog: convert tree_is_complete to take struct object_id
  Convert lookup_tree to struct object_id
  log-tree: convert to struct object_id
  Convert lookup_tag to struct object_id
  Convert the verify_pack callback to struct object_id
  Convert struct ref_array_item to struct object_id
  ref-filter: convert some static functions to struct object_id
  refs: convert struct ref_update to use struct object_id
  refs/files-backend: convert many internals to struct object_id
  http-push: convert process_ls_object and descendants to object_id
  revision: rename add_pending_sha1 to add_pending_oid
  revision: convert remaining parse_object callers to object_id
  upload-pack: convert remaining parse_object callers to object_id
  sha1_name: convert internals of peel_onion to object_id
  builtin/read-tree: convert to struct object_id
  builtin/ls-files: convert overlay_tree_on_cache to object_id
  sequencer: convert fast_forward_to to struct object_id
  merge: convert checkout_fast_forward to struct object_id
  builtin/ls-tree: convert to struct object_id
  diff-lib: convert do_diff_cache to struct object_id
  sequencer: convert do_recursive_merge to struct object_id
  tree: convert parse_tree_indirect to struct object_id
  object: convert parse_object* to take struct object_id

 archive.c   |   6 +-
 bisect.c|   2 +-
 blob.c  |   6 +-
 blob.h  |   2 +-
 branch.c|  16 +-
 builtin/am.c|  18 +-
 builtin/blame.c |  14 +-
 builtin/branch.c|   6 +-
 builtin/checkout.c  |  18 +-
 builtin/clone.c |   4 +-
 builtin/commit-tree.c   |   2 +-
 builtin/commit.c|   8 +-
 builtin/describe.c  |  10 +-
 builtin/diff-tree.c |   8 +-
 builtin/diff.c  |   6 +-
 builtin/fast-export.c   |   8 +-
 builtin/fetch.c |   7 +-
 builtin/fmt-merge-msg.c |   8 +-
 builtin/fsck.c  |  16 +-
 builtin/grep.c  |   2 +-
 builtin/index-pack.c|  56 ++---
 builtin/log.c   |  10 +-
 builtin/ls-files.c  |   6 +-
 builtin/ls-tree.c   |   6 +-
 builtin/merge-base.c

Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Eric Wong
Ævar Arnfjörð Bjarmason  wrote:
> Thanks a lot for public-inbox, my only problem with it is that it
> doesn't cover every single mailing list I'm on, just git :)

Yes, I'm hoping more folks can start running their own
instances.  I notice you're on p5p where I started to
occasionally lurk a few years back.  Is that something you'd be
interesting in mirroring? :)

Some lists I'm involved in tend to be centralized
(reply-to-list, not reply-to-all); so UI changes will be needed
in public-inbox...

> Are you or someone else maintaining some ancillary scripts for it? I
> probably need to fix my patch workflow but my usual mode is browsing
> in GMail & then manually 'git am'-ing some file I find with git-log
> commands.

Not really.  I started out ssoma(*) just for archival/mirroring,
but it's mostly forgotten at this point.  I would rather people
build on existing protocols like NNTP.

> I have one to git am a patch from a msgid, thought I should write
> something to handle a series in some DWIM fashion (e.g. apply the
> latest continuous sequence of patches matching --author) but figured
> that someone's probably wrote this already & I don't need to hack it
> up myself...

I've been meaning to wire up the web search to allow downloading
an entire mbox worth of search results.  But it could be a bit
expensive for some queries and there needs to be a limit.  The
current limit for web display is too small; so maybe 1000
messages per-mbox at a time to avoid DoS-ing the server.

(*) some-sort-of-mail archiver: git clone git://80x24.org/ssoma


Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Samuel Lijin
On Sat, May 6, 2017 at 3:50 PM, Eric Wong  wrote:
> (I have no idea what Jonathan Tirado wrote; it was encrypted (but
>  sent to a public list).
>
> Samuel Lijin  wrote:
>> Yep, I see these on public-inbox.org/git/ but not in my gmail inbox:
>
> Hi Samuel, check your Spam box (and move it to a normal inbox so
> they can train it).  Gmail filters are known to trigger happy
> and incorrectly flag messages.  It's been a problem on LKML,
> too.

Sorry, should've been clearer - I did check my spambox in my original
message. Some old patches from Brandon were in there, but the ones I
mentioned in my original message just seem to have been dropped.


Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Ævar Arnfjörð Bjarmason
On Sat, May 6, 2017 at 10:50 PM, Eric Wong  wrote:
> (I have no idea what Jonathan Tirado wrote; it was encrypted (but
>  sent to a public list).
>
> Samuel Lijin  wrote:
>> Yep, I see these on public-inbox.org/git/ but not in my gmail inbox:
>
> Hi Samuel, check your Spam box (and move it to a normal inbox so
> they can train it).  Gmail filters are known to trigger happy
> and incorrectly flag messages.  It's been a problem on LKML,
> too.
>
>> - Brandon [RFC 01/14] through [RFC 14/14] convert dir.c to take an
>> index parameter
>
> Ironically, Brandon is a Google employee and Gmail seems to not
> like his messages.  The only flag I see from SpamAssassin in
> public-inbox is HEADER_FROM_DIFFERENT_DOMAINS which happens to
> every message because it's relayed via kernel.org
>
> Maybe Brandon can escalate this internally in Google...
>
> (OTOH, I noticed a thread/mbox download bug in public-inbox,
> https://public-inbox.org/git/xmqqmvaq702u@gitster.mtv.corp.google.com/t.mbox.gz
> only shows two messages out of many.   Will need to fix that...)
>
>> - Johanne's Coverity patch series
>
> Likewise, but he also uses freemail domain (nothing wrong with
> that, but it raises one flag on SA).  I noticed at least one
> of his did trigger the RCVD_IN_SORBS_SPAM in SpamAssassin, but that's
> a common problem with all freemail providers (including Gmail).
>
>
> Anyways, I'm glad the SpamAssassin seems to be working well on
> public-inbox and would be grateful to know if there's false
> positives and missing messages.
>
> One of the major reasons I started public-inbox was because I
> lack faith in my ability to run my little list server (with
> mlmmj or mailman) and be able to successfully relay to the big
> providers.  Anyways, I'm glad it's helping readers of git@vger,
> too :)

Thanks a lot for public-inbox, my only problem with it is that it
doesn't cover every single mailing list I'm on, just git :)

Are you or someone else maintaining some ancillary scripts for it? I
probably need to fix my patch workflow but my usual mode is browsing
in GMail & then manually 'git am'-ing some file I find with git-log
commands.

I have one to git am a patch from a msgid, thought I should write
something to handle a series in some DWIM fashion (e.g. apply the
latest continuous sequence of patches matching --author) but figured
that someone's probably wrote this already & I don't need to hack it
up myself...


Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Eric Wong
(I have no idea what Jonathan Tirado wrote; it was encrypted (but
 sent to a public list).

Samuel Lijin  wrote:
> Yep, I see these on public-inbox.org/git/ but not in my gmail inbox:

Hi Samuel, check your Spam box (and move it to a normal inbox so
they can train it).  Gmail filters are known to trigger happy
and incorrectly flag messages.  It's been a problem on LKML,
too.

> - Brandon [RFC 01/14] through [RFC 14/14] convert dir.c to take an
> index parameter

Ironically, Brandon is a Google employee and Gmail seems to not
like his messages.  The only flag I see from SpamAssassin in
public-inbox is HEADER_FROM_DIFFERENT_DOMAINS which happens to
every message because it's relayed via kernel.org

Maybe Brandon can escalate this internally in Google...

(OTOH, I noticed a thread/mbox download bug in public-inbox,
https://public-inbox.org/git/xmqqmvaq702u@gitster.mtv.corp.google.com/t.mbox.gz
only shows two messages out of many.   Will need to fix that...)

> - Johanne's Coverity patch series

Likewise, but he also uses freemail domain (nothing wrong with
that, but it raises one flag on SA).  I noticed at least one
of his did trigger the RCVD_IN_SORBS_SPAM in SpamAssassin, but that's
a common problem with all freemail providers (including Gmail).


Anyways, I'm glad the SpamAssassin seems to be working well on
public-inbox and would be grateful to know if there's false
positives and missing messages.

One of the major reasons I started public-inbox was because I
lack faith in my ability to run my little list server (with
mlmmj or mailman) and be able to successfully relay to the big
providers.  Anyways, I'm glad it's helping readers of git@vger,
too :)


Re: Git smart http: parsing commit messages in git-receive-pack

2017-05-06 Thread Bryan Turner
On Sat, May 6, 2017 at 5:30 AM, akos tajti  wrote:
> Dear All,
>
> we implemented a java servlet around the git-http-backend. This servlet 
> intercepts the requests sent by the git client when pushing. One thing I want 
> to achieve is parsing the commit messages in the pre push phase (request 
> param service==git-receive-pack) and after checking if the commit messages 
> contain a given string reject/accept the request. The problem is that I 
> couldn't find a way of parsing the commit messages in git-receive-pack (I can 
> do this in the post  push phase but in that case I cannot reject the push 
> because the changes are already on the server). Is there a way of getting the 
> commit messages before they're actually on the server so that I can reject 
> the push?

The protocol isn't really intended for use to try and parse pack data
before it's spooled to disk. It might be possible, but it's likely to
be brittle (due to things like delta compression, for example).

I believe what you're looking for is a pre-receive hook[1] on your
server. This is how Bitbucket Server (which is also written in Java)
works. It opens a socket on localhost and installs a pre-receive hook
into each repository which uses a Perl script to pipe all of its input
to the listening socket and then read any response from the server
back. After the push has written all of its objects to disk, Git
invokes any pre-receive hooks and passes in all the ref changes. The
Perl script pipes those to the server, which applies whatever checks
are desired and writes any errors or info back to the hook, which then
prints it for Git to use before exiting with the correct status code
(0 to accept the push, 1 to reject it).

This means the objects are on the server, but in Git 2.11 Peff added
"quarantine" functionality which writes those new objects into an
"incoming" directory[2]. That means, while they're on disk, they're
_not_ in the repository itself. If the pre-receive hook rejects the
push, those objects are immediately deleted from disk.

That means if you pair a pre-receive hook with Git 2.11 or newer on
the server, you should be able to achieve what you're looking for.
Once the objects have been written to the quarantine directory, you
can use normal Git commands, like cat-file, rev-list or log, to review
them. If they don't meet your requirements, just reject the push and
Git will delete the objects automatically

Hope this helps!
Bryan Turner

>
> Thanks in advance,
> Ákos Tajti
>

[1]: https://git-scm.com/docs/githooks includes documentation for
pre-receive inputs and outputs
[2]: 
https://github.com/git/git/blob/master/Documentation/git-receive-pack.txt#L219-L243
includes some additional documentation about the quarantine
environment


[PATCH v2 5/9] dir: hide untracked contents of untracked dirs

2017-05-06 Thread Samuel Lijin
When we taught read_directory_recursive() to recurse into untracked
directories in search of ignored files given DIR_SHOW_IGNORED_TOO, that
had the side effect of teaching it to collect the untracked contents of
untracked directories. It does not make sense to return these, so we
teach read_directory() to strip dir->entries of any such untracked
contents.

Signed-off-by: Samuel Lijin 
---
 dir.c | 44 
 1 file changed, 44 insertions(+)

diff --git a/dir.c b/dir.c
index 4739087f4..fd445ee9e 100644
--- a/dir.c
+++ b/dir.c
@@ -2075,6 +2075,50 @@ int read_directory(struct dir_struct *dir, const char 
*path,
read_directory_recursive(dir, path, len, untracked, 0, 
pathspec);
QSORT(dir->entries, dir->nr, cmp_name);
QSORT(dir->ignored, dir->ignored_nr, cmp_name);
+
+   // if collecting ignored files, never consider a directory containing
+   // ignored files to be untracked
+   if (dir->flags & DIR_SHOW_IGNORED_TOO) {
+   int i, j, nr_removed = 0;
+
+   // remove from dir->entries untracked contents of untracked dirs
+   for (i = 0; i < dir->nr; i++) {
+   if (!dir->entries[i])
+   continue;
+
+   for (j = i + 1; j < dir->nr; j++) {
+   if (!dir->entries[j])
+   continue;
+   if (check_contains(dir->entries[i], 
dir->entries[j])) {
+   nr_removed++;
+   free(dir->entries[j]);
+   dir->entries[j] = NULL;
+   }
+   else {
+   break;
+   }
+   }
+   }
+
+   // strip dir->entries of NULLs
+   if (nr_removed) {
+   for (i = 0;;) {
+   while (i < dir->nr && dir->entries[i])
+   i++;
+   if (i == dir->nr)
+   break;
+   j = i;
+   while (j < dir->nr && !dir->entries[j])
+   j++;
+   if (j == dir->nr)
+   break;
+   dir->entries[i] = dir->entries[j];
+   dir->entries[j] = NULL;
+   }
+   dir->nr -= nr_removed;
+   }
+   }
+
if (dir->untracked) {
static struct trace_key trace_untracked_stats = 
TRACE_KEY_INIT(UNTRACKED_STATS);
trace_printf_key(_untracked_stats,
-- 
2.12.2



[PATCH v2 8/9] t7300: clean -d now skips untracked dirs containing ignored files

2017-05-06 Thread Samuel Lijin
This was previously broken (and likely never worked); this concludes the
patch series fixing the behavior of clean -d.

Signed-off-by: Samuel Lijin 
---
 t/t7300-clean.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 252c75b40..948a455e8 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -653,7 +653,7 @@ test_expect_success 'git clean -d respects pathspecs 
(pathspec is prefix of dir)
test_path_is_dir foobar
 '
 
-test_expect_failure 'git clean -d skips untracked dirs containing ignored 
files' '
+test_expect_success 'git clean -d skips untracked dirs containing ignored 
files' '
echo /foo/bar >.gitignore &&
rm -rf foo &&
mkdir -p foo &&
-- 
2.12.2



[PATCH v2 9/9] t7061: expect ignored files in untracked dirs

2017-05-06 Thread Samuel Lijin
We now expect `status --ignored` to list ignored files even if they are
in an untracked directory.

Signed-off-by: Samuel Lijin 
---
 t/t7061-wtstatus-ignore.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index dc3be92a2..fc6013ba3 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -9,9 +9,10 @@ cat >expected <<\EOF
 ?? actual
 ?? expected
 ?? untracked/
+!! untracked/ignored
 EOF
 
-test_expect_failure 'status untracked directory with --ignored' '
+test_expect_success 'status untracked directory with --ignored' '
echo "ignored" >.gitignore &&
mkdir untracked &&
: >untracked/ignored &&
@@ -20,7 +21,7 @@ test_expect_failure 'status untracked directory with 
--ignored' '
test_cmp expected actual
 '
 
-test_expect_failure 'same with gitignore starting with BOM' '
+test_expect_success 'same with gitignore starting with BOM' '
printf "\357\273\277ignored\n" >.gitignore &&
mkdir -p untracked &&
: >untracked/ignored &&
-- 
2.12.2



[PATCH v2 7/9] builtin/clean: teach clean -d to skip dirs containing ignored files

2017-05-06 Thread Samuel Lijin
There is an implicit assumption that a directory containing only
untracked and ignored files should itself be considered untracked. This
makes sense in use cases where we're asking if a directory should be
added to the git database, but not when we're asking if a directory can
be safely removed from the working tree; as a result, clean -d would
assume that an "untracked" directory containing ignored files could be
deleted.

To get around this, we teach clean -d to collect ignored files and skip
over so-called "untracked" directories if they contain any ignored
files.

Signed-off-by: Samuel Lijin 
---
 builtin/clean.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/builtin/clean.c b/builtin/clean.c
index d861f836a..368e19427 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -859,7 +859,7 @@ static void interactive_main_loop(void)
 
 int cmd_clean(int argc, const char **argv, const char *prefix)
 {
-   int i, res;
+   int i, j, res;
int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, config_set = 0, errors = 0, gone = 1;
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
@@ -911,6 +911,9 @@ int cmd_clean(int argc, const char **argv, const char 
*prefix)
  " refusing to clean"));
}
 
+   if (remove_directories)
+   dir.flags |= DIR_SHOW_IGNORED_TOO;
+
if (force > 1)
rm_flags = 0;
 
@@ -932,7 +935,7 @@ int cmd_clean(int argc, const char **argv, const char 
*prefix)
 
fill_directory(, );
 
-   for (i = 0; i < dir.nr; i++) {
+   for (j = i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
int matches = 0;
struct stat st;
@@ -954,10 +957,27 @@ int cmd_clean(int argc, const char **argv, const char 
*prefix)
matches != MATCHED_EXACTLY)
continue;
 
+   // skip any dir.entries which contains a dir.ignored
+   for (; j < dir.ignored_nr; j++) {
+   if (cmp_name([i],
+   [j]) < 0)
+   break;
+   }
+   if ((j < dir.ignored_nr) &&
+   check_contains(dir.entries[i], dir.ignored[j])) 
{
+   continue;
+   }
+
rel = relative_path(ent->name, prefix, );
string_list_append(_list, rel);
}
 
+   for (i = 0; i < dir.nr; i++)
+   free(dir.entries[i]);
+
+   for (i = 0; i < dir.ignored_nr; i++)
+   free(dir.ignored[i]);
+
if (interactive && del_list.nr > 0)
interactive_main_loop();
 
-- 
2.12.2



[PATCH v2 6/9] dir: change linkage of cmp_name() and check_contains()

2017-05-06 Thread Samuel Lijin
Signed-off-by: Samuel Lijin 
---
 dir.c | 4 ++--
 dir.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index fd445ee9e..6a71683df 100644
--- a/dir.c
+++ b/dir.c
@@ -1844,7 +1844,7 @@ static enum path_treatment 
read_directory_recursive(struct dir_struct *dir,
return dir_state;
 }
 
-static int cmp_name(const void *p1, const void *p2)
+int cmp_name(const void *p1, const void *p2)
 {
const struct dir_entry *e1 = *(const struct dir_entry **)p1;
const struct dir_entry *e2 = *(const struct dir_entry **)p2;
@@ -1853,7 +1853,7 @@ static int cmp_name(const void *p1, const void *p2)
 }
 
 /* check if *out lexically contains *in */
-static int check_contains(const struct dir_entry *out, const struct dir_entry 
*in)
+int check_contains(const struct dir_entry *out, const struct dir_entry *in)
 {
return (out->len < in->len) &&
(out->name[out->len - 1] == '/') &&
diff --git a/dir.h b/dir.h
index bf23a470a..1ddd8b611 100644
--- a/dir.h
+++ b/dir.h
@@ -326,6 +326,9 @@ static inline int dir_path_match(const struct dir_entry 
*ent,
  has_trailing_dir);
 }
 
+int cmp_name(const void *p1, const void *p2);
+int check_contains(const struct dir_entry *out, const struct dir_entry *in);
+
 void untracked_cache_invalidate_path(struct index_state *, const char *);
 void untracked_cache_remove_from_index(struct index_state *, const char *);
 void untracked_cache_add_to_index(struct index_state *, const char *);
-- 
2.12.2



[PATCH v2 4/9] dir: add method to check if a dir_entry lexically contains another

2017-05-06 Thread Samuel Lijin
Introduce a method that allows us to check if one dir_entry corresponds
to a path which contains the path corresponding to another dir_entry.

Signed-off-by: Samuel Lijin 
---
 dir.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/dir.c b/dir.c
index 6bd0350e9..4739087f4 100644
--- a/dir.c
+++ b/dir.c
@@ -1852,6 +1852,14 @@ static int cmp_name(const void *p1, const void *p2)
return name_compare(e1->name, e1->len, e2->name, e2->len);
 }
 
+/* check if *out lexically contains *in */
+static int check_contains(const struct dir_entry *out, const struct dir_entry 
*in)
+{
+   return (out->len < in->len) &&
+   (out->name[out->len - 1] == '/') &&
+   !memcmp(out->name, in->name, out->len);
+}
+
 static int treat_leading_path(struct dir_struct *dir,
  const char *path, int len,
  const struct pathspec *pathspec)
-- 
2.12.2



[PATCH v2 3/9] dir: recurse into untracked dirs for ignored files

2017-05-06 Thread Samuel Lijin
We consider directories containing only untracked and ignored files to
be themselves untracked, which in the usual case means we don't have to
search these directories. This is problematic when we want to collect
ignored files with DIR_SHOW_IGNORED_TOO, though, so we teach
read_directory_recursive() to recurse into untracked directories to find
the ignored files they contain when DIR_SHOW_IGNORED_TOO is set. This
has the side effect of also collecting all untracked files in untracked
directories as well.

Signed-off-by: Samuel Lijin 
---
 dir.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dir.c b/dir.c
index f451bfa48..6bd0350e9 100644
--- a/dir.c
+++ b/dir.c
@@ -1784,7 +1784,12 @@ static enum path_treatment 
read_directory_recursive(struct dir_struct *dir,
dir_state = state;
 
/* recurse into subdir if instructed by treat_path */
-   if (state == path_recurse) {
+   if ((state == path_recurse) ||
+   ((get_dtype(cdir.de, path.buf, path.len) == 
DT_DIR) &&
+(state == path_untracked) &&
+(dir->flags & DIR_SHOW_IGNORED_TOO))
+   )
+   {
struct untracked_cache_dir *ud;
ud = lookup_untracked(dir->untracked, untracked,
  path.buf + baselen,
-- 
2.12.2



[PATCH v2 2/9] t7061: expect failure where expected behavior will change

2017-05-06 Thread Samuel Lijin
This changes tests for `status --ignored` from test_expect_success to
test_expect_failure in preparation for a change in its expected behavior
(namely, that ignored files in untracked dirs will be reported).

Signed-off-by: Samuel Lijin 
---
 t/t7061-wtstatus-ignore.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
index cdc0747bf..dc3be92a2 100755
--- a/t/t7061-wtstatus-ignore.sh
+++ b/t/t7061-wtstatus-ignore.sh
@@ -11,7 +11,7 @@ cat >expected <<\EOF
 ?? untracked/
 EOF
 
-test_expect_success 'status untracked directory with --ignored' '
+test_expect_failure 'status untracked directory with --ignored' '
echo "ignored" >.gitignore &&
mkdir untracked &&
: >untracked/ignored &&
@@ -20,7 +20,7 @@ test_expect_success 'status untracked directory with 
--ignored' '
test_cmp expected actual
 '
 
-test_expect_success 'same with gitignore starting with BOM' '
+test_expect_failure 'same with gitignore starting with BOM' '
printf "\357\273\277ignored\n" >.gitignore &&
mkdir -p untracked &&
: >untracked/ignored &&
-- 
2.12.2



[PATCH v2 1/9] t7300: skip untracked dirs containing ignored files

2017-05-06 Thread Samuel Lijin
If git sees a directory which contains only untracked and ignored
files, clean -d should not remove that directory. It was recently
discovered that this is *not* true of git clean -d, and it's possible
that this has never worked correctly; this test and its accompanying
patch series aims to fix that.

Signed-off-by: Samuel Lijin 
---
 t/t7300-clean.sh | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index b89fd2a6a..252c75b40 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -653,4 +653,14 @@ test_expect_success 'git clean -d respects pathspecs 
(pathspec is prefix of dir)
test_path_is_dir foobar
 '
 
+test_expect_failure 'git clean -d skips untracked dirs containing ignored 
files' '
+   echo /foo/bar >.gitignore &&
+   rm -rf foo &&
+   mkdir -p foo &&
+   touch foo/bar &&
+   git clean -df &&
+   test_path_is_file foo/bar &&
+   test_path_is_dir foo
+'
+
 test_done
-- 
2.12.2



[PATCH v2 0/9] Keep git clean -d from inadvertently removing ignored files

2017-05-06 Thread Samuel Lijin
Addresses the issues raised by Stefan and Junio (thanks for your feedback) 
about not using C99-style comments and keeping tests working on every commit to 
prevent breaking git bisect. (About the latter one: is it necessary to prevent 
compiler warnings, in addition to compiler errors? Because if so I should 
probably squash some of the commits together.)

Note that this introduces a breaking change in the behavior of git status: when 
invoked with --ignored, git status will now return ignored files in an 
untracked directory, whereas previously it would not.

It's possible that there are standard practices that I might have missed, so if 
there is anything along those lines, I'd appreciate you letting me know. (As an 
aside, about the git bisect thing: is there a script somewhere that people use 
to test patch series before sending them out?)

Samuel Lijin (9):
  t7300: skip untracked dirs containing ignored files
  t7061: expect failure where expected behavior will change
  dir: recurse into untracked dirs for ignored files
  dir: add method to check if a dir_entry lexically contains another
  dir: hide untracked contents of untracked dirs
  dir: change linkage of cmp_name() and check_contains()
  builtin/clean: teach clean -d to skip dirs containing ignored files
  t7300: clean -d now skips untracked dirs containing ignored files
  t7061: expect ignored files in untracked dirs

 builtin/clean.c| 24 --
 dir.c  | 61 --
 dir.h  |  3 +++
 t/t7061-wtstatus-ignore.sh |  1 +
 t/t7300-clean.sh   | 10 
 5 files changed, 95 insertions(+), 4 deletions(-)

-- 
2.12.2



Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Samuel Lijin
Yep, I see these on public-inbox.org/git/ but not in my gmail inbox:

- Brandon [RFC 01/14] through [RFC 14/14] convert dir.c to take an
index parameter
- Johanne's Coverity patch series


Re: vger not relaying some of Junio's messages today?

2017-05-06 Thread Jonathan Tirado


binnbmf6RUfBU.bin
Description: application/pgp-encrypted


encrypted.asc
Description: Binary data


Re: Bug report: Git Stash; spelling mistake of stash followed by a yes prints character 'y' infinite times.

2017-05-06 Thread Dennis Kaarsemaker
On Wed, 2017-05-03 at 14:51 +0530, Rashmi Pai wrote:

> I am a corporate user of git. I noticed that when you switch between
> the branches and do a git stash ( I miss spelled it as git stahs). Git
> asked if i meant git stash. and i entered yes. and git printed the
> character y infinite times.

Hi Rashmi,

While git asks the question 'Did you mean stash', that question is
merely rhetorical, it does not expect an answer but exits. So what
you're seeing is the output of the shell builting 'yes', not output
from git.

D.


Re: [PATCH v3 12/25] split_commit_in_progress(): fix memory leak

2017-05-06 Thread René Scharfe

Am 04.05.2017 um 12:59 schrieb Johannes Schindelin:

Hi René,

On Wed, 3 May 2017, René Scharfe wrote:


Am 02.05.2017 um 18:02 schrieb Johannes Schindelin:

Reported via Coverity.

Signed-off-by: Johannes Schindelin 
---
   wt-status.c | 7 ++-
   1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/wt-status.c b/wt-status.c
index 0a6e16dbe0f..1f3f6bcb980 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1088,8 +1088,13 @@ static int split_commit_in_progress(struct wt_status
*s)
char *rebase_orig_head =
read_line_from_git_path("rebase-merge/orig-head");
   
   	if (!head || !orig_head || !rebase_amend || !rebase_orig_head ||

-   !s->branch || strcmp(s->branch, "HEAD"))
+   !s->branch || strcmp(s->branch, "HEAD")) {
+   free(head);
+   free(orig_head);
+   free(rebase_amend);
+   free(rebase_orig_head);
return split_in_progress;
+   }
   
if (!strcmp(rebase_amend, rebase_orig_head)) {

 if (strcmp(head, rebase_amend))



The return line could be replaced by "; else" to achieve the same
result, without duplicating the free calls.


True. It is much harder to explain it that way, though: the context looks
like this:

static int split_commit_in_progress(struct wt_status *s)
  {
 int split_in_progress = 0;
 char *head = read_line_from_git_path("HEAD");
 char *orig_head = read_line_from_git_path("ORIG_HEAD");
 char *rebase_amend = read_line_from_git_path("rebase-merge/amend");
 char *rebase_orig_head = 
read_line_from_git_path("rebase-merge/orig-head");

 if (!head || !orig_head || !rebase_amend || !rebase_orig_head ||
-   !s->branch || strcmp(s->branch, "HEAD"))
+   !s->branch || strcmp(s->branch, "HEAD")) {
+   free(head);
+   free(orig_head);
+   free(rebase_amend);
+   free(rebase_orig_head);
 return split_in_progress;
+   }

 if (!strcmp(rebase_amend, rebase_orig_head)) {
 if (strcmp(head, rebase_amend))
 split_in_progress = 1;
 } else if (strcmp(orig_head, rebase_orig_head)) {
 split_in_progress = 1;
 }

 if (!s->amend && !s->nowarn && !s->workdir_dirty)
 split_in_progress = 0;

 free(head);
 free(orig_head);
 free(rebase_amend);
 free(rebase_orig_head);
 return split_in_progress;
  }

So as you see, if we make the change you suggested, the next if() is hit
which possibly sets split_in_progress = 0.

The thing is: this variable has been initialized to 0 in the beginning! So
this conditional assignment would be a noop, unless any of the code paths
before this conditional modified split_in_progress.


Right. It could have been used as a quick two-line fix.


After you fully wrapped your head around this code, I am sure you agree
that the code is unnecessarily confusing to begin with: why do we go out
of our way to allocate and read all those strings, compare them to figure
out whether there is a split in progress, just to look at bits in the
wt_status struct (that we had available from the beginning) to potentially
undo all of that.


The only function with a higher cyclomatic complexity in this file is
wt_longstatus_print(), which spans more than 100 lines.  Amazing.


What's worse, I cannot even find a logical explanation why the code is so
confusing, as it has been added as it is today in commit 2d1ccebae41
(status: better advices when splitting a commit (during rebase -i),
2012-06-10).


Repeatedly I get the impression that defects or shortcomings tend to
cluster.  It pays to take a good look at the code surrounding a find of
an automatic checker for other possible improvements.


So I think this function really wants to be fixed more fully (although I
feel bad for inserting such a non-trivial fix into a patch series
otherwise populated by trivial memory/resource leak plugs):


It could be done in two steps.  Doing it in one is probably OK as well.


-- snipsnap --
Subject: [PATCH] squash! split_commit_in_progress(): fix memory leak

split_commit_in_progress(): simplify & fix memory leak

This function did a whole lot of unnecessary work, such as reading in
four files just to figure out that, oh, hey, we do not need to look at
them after all because the HEAD is not detached.

Simplify the entire function to return early when possible, to read in
the files only when necessary, and to release the allocated memory
always (there was a leak, reported via Coverity, where we failed to
release the allocated strings if the HEAD is not detached).

Signed-off-by: Johannes Schindelin 
---
  wt-status.c | 39 +--
  1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 1f3f6bcb980..117ac8cfb01 100644
--- 

Re: [PATCH v4 11/25] checkout: fix memory leak

2017-05-06 Thread René Scharfe

Am 04.05.2017 um 15:56 schrieb Johannes Schindelin:

This change addresses part of the NEEDSWORK comment above the code,
therefore the comment needs to be adjusted, too.

Discovered via Coverity.

Signed-off-by: Johannes Schindelin 
---
  builtin/checkout.c | 17 +
  1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index bfa5419f335..5faea3a05fa 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -235,14 +235,14 @@ static int checkout_merged(int pos, const struct checkout 
*state)
/*
 * NEEDSWORK:
 * There is absolutely no reason to write this as a blob object
-* and create a phony cache entry just to leak.  This hack is
-* primarily to get to the write_entry() machinery that massages
-* the contents to work-tree format and writes out which only
-* allows it for a cache entry.  The code in write_entry() needs
-* to be refactored to allow us to feed a 
-* instead of a cache entry.  Such a refactoring would help
-* merge_recursive as well (it also writes the merge result to the
-* object database even when it may contain conflicts).
+* and create a phony cache entry.  This hack is primarily to get
+* to the write_entry() machinery that massages the contents to
+* work-tree format and writes out which only allows it for a
+* cache entry.  The code in write_entry() needs to be refactored
+* to allow us to feed a  instead of a cache
+* entry.  Such a refactoring would help merge_recursive as well
+* (it also writes the merge result to the object database even
+* when it may contain conflicts).
 */
if (write_sha1_file(result_buf.ptr, result_buf.size,
blob_type, oid.hash))


Random observation: Using pretend_sha1_file here would at least avoid
writing the blob.


@@ -251,6 +251,7 @@ static int checkout_merged(int pos, const struct checkout 
*state)
if (!ce)
die(_("make_cache_entry failed for path '%s'"), path);
status = checkout_entry(ce, state, NULL);
+   free(ce);
return status;
  }


I wonder if that's safe.  Why document a leak when it could have been
plugged this easily instead?  A leak is better than a use after free, so
let's be extra careful here.  Would it leave the index inconsistent?  Or
perhaps freeing it has become safe in the meantime?

@Junio: Do you remember the reason for the leaks in 0cf8581e330
(checkout -m: recreate merge when checking out of unmerged index).

And result_buf is still leaked here, right?

FWIW, after fixing a different issue (patch just sent separately)
t*checkout*.sh complete successfully for me with --valgrind, with and
without freeing both ce and result_buf.ptr.  So it *seems* safe..

René


[PATCH] am: check return value of resolve_refdup before using hash

2017-05-06 Thread René Scharfe
If resolve_refdup() fails it returns NULL and possibly leaves its hash
output parameter untouched.  Make sure to use it only if the function
succeeded, in order to avoid accessing uninitialized memory.

Signed-off-by: Rene Scharfe 
---
 builtin/am.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/am.c b/builtin/am.c
index a95dd8b4e6..2c52c820aa 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2156,7 +2156,7 @@ static void am_abort(struct am_state *state)
am_rerere_clear();
 
curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
-   has_curr_head = !is_null_oid(_head);
+   has_curr_head = curr_branch && !is_null_oid(_head);
if (!has_curr_head)
hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
 
-- 
2.12.2



Re: Script to rebase branches

2017-05-06 Thread Dennis Kaarsemaker
On Sat, 2017-05-06 at 12:23 +0200, Lars Schneider wrote:
> Hi,
> 
> I am about to write a bash/sh script that helps me to rebase a bunch of 
> branches (e.g. select branches based on prefix, conflict resolution/
> rerere support, ...).
> 
> I wonder if anyone has such a script already and is willing to share it.

Dscho's git garden shears perhaps?

https://github.com/git-for-windows/build-extra/blob/master/shears.sh

D.


[PATCH] checkout: check return value of resolve_refdup before using hash

2017-05-06 Thread René Scharfe
If resolve_refdup() fails it returns NULL and possibly leaves its hash
output parameter untouched.  Make sure to use it only if the function
succeeded, in order to avoid accessing uninitialized memory.

Found with t/t2011-checkout-invalid-head.sh --valgrind.

Signed-off-by: Rene Scharfe 
---
 builtin/checkout.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index bfa5419f33..6c3d2e4f4c 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -833,7 +833,8 @@ static int switch_branches(const struct checkout_opts *opts,
int flag, writeout_error = 0;
memset(, 0, sizeof(old));
old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, );
-   old.commit = lookup_commit_reference_gently(rev.hash, 1);
+   if (old.path)
+   old.commit = lookup_commit_reference_gently(rev.hash, 1);
if (!(flag & REF_ISSYMREF))
old.path = NULL;
 
-- 
2.12.2



[ANNOUNCE] tig-2.2.2

2017-05-06 Thread Jonas Fonseca
Hello,

A new version of Tig has been release with several improvements and bug fixes.

What is Tig?

Tig is an ncurses-based text-mode interface for git. It functions mainly
as a Git repository browser, but can also assist in staging changes for
commit at chunk level and act as a pager for output from various Git
commands.

 - Homepage: https://jonas.github.io/tig/
 - Manual: https://jonas.github.io/tig/doc/manual.html
 - Tarballs: https://github.com/jonas/tig/releases
 - Gitter: https://gitter.im/jonas/tig
 - Q: http://stackoverflow.com/questions/tagged/tig

Release notes
-
Upgrade instructions:

 - The `status-untracked-dirs` option was renamed to
   `status-show-untracked-dirs` to match the new `status-show-untracked-files`
   option.

Improvements:

 - Use `diff-options` when preparing the diff in the stage view to make the diff
   state configurable. (GH #545)
 - Add 'status-show-untracked-files' option mirroring Git's
   'status.showUntrackedFiles' to toggle display of untracked files.  in the
   status view. On by default. (GH #562)
 - Update `ax_with_curses.m4` and use `pkg-config` to detect. (GH #546)
 - Add `tig-pick` script for using Tig as a commit picker. (GH #575, #580)
 - Add "smart case" option ('set ignore-case = smart-case') to ignore case when
   the search string is lower-case only. (GH #320, #579)

Bug fixes:

 - Fix author ident cache being keyed by email only. (GH #424, #526, #547)
 - Fix periodic refresh mode to properly detect ref changes. (GH #430, #591)
 - Add workaround for detecting failure to start the diff-highlight process.
 - Show diffs in the stash view when `set mailmap = true`. (GH #556)
 - Fix parsing of git-log revision arguments, such as `--exclude=...` in
   conjunction with `--all`. (GH #555)
 - Fix diff stat parsing for binary copies.
 - Fix crash when resizing terminal while search is in progress. (GH #515, #550)
 - Fix argument filtering to pass more arguments through to Git.
 - Check for termcap support in split tinfo libs. (GH #568, #585)

Change summary
--
The diffstat and log summary for changes made in this release.

 INSTALL.adoc |  10 +-
 Makefile |   2 +-
 NEWS.adoc|  44 -
 README.adoc  |   2 +-
 book.md  |   2 +-
 config.make.in   |   2 +-
 configure.ac |   2 +-
 contrib/tig-pick |  48 +
 doc/manual.adoc  |   5 +-
 doc/screenshots.md   |  11 ---
 doc/tig.1.adoc   |   2 +-
 doc/tigrc.5.adoc |  15 ++-
 include/tig/argv.h   |   1 +
 include/tig/diff.h   |   4 +-
 include/tig/git.h|   4 +-
 include/tig/options.h|   5 +-
 include/tig/types.h  |  12 ++-
 include/tig/util.h   |   1 +
 include/tig/view.h   |   4 +-
 src/argv.c   |   4 +-
 src/blame.c  |  29 +++---
 src/blob.c   |  16 ++-
 src/diff.c   |  56 ++-
 src/display.c|   8 +-
 src/draw.c   |   2 +-
 src/grep.c   |   4 +-
 src/help.c   |   9 +-
 src/io.c |   8 +-
 src/log.c|   2 +-
 src/main.c   |  16 +--
 src/options.c|  72 +-
 src/pager.c  |  10 +-
 src/parse.c  |  14 ++-
 src/refs.c   |  21 ++--
 src/search.c |  16 ++-
 src/stage.c  |  44 -
 src/stash.c  |   6 +-
 src/status.c |  40 +---
 src/tig.c|  30 +++---
 src/tree.c   |  10 +-
 src/util.c   |   6 +-
 src/view.c   |  25 ++---
 src/watch.c  |   2 +-
 test/diff/diff-highlight-test|  38 ++-
 test/files/repo-authornamechange.tgz | Bin 0 -> 7557 bytes
 test/main/author-name-change-test|  27 +
 test/main/filter-args-test   |  74 ++
 test/main/refresh-periodic-test  |  74 ++
 test/main/search-test|  22 +
 test/status/untracked-files-test |  27 +
 test/tigrc/compat-error-test |   5 +-
 tigrc|   6 +-
 tools/aspell.dict|   9 +-
 tools/ax_lib_readline.m4 |  16 ++-
 tools/ax_require_defined.m4  |  37 +++
 tools/ax_with_curses.m4  | 142 +++
 56 files changed, 822 insertions(+), 281 deletions(-)

22  Jonas Fonseca
  

good news

2017-05-06 Thread Lindsey
Dear Friend.

Good day ! after much stress, I decided to offer you the sum of Three
hundred thousand United States Dollars ($300,000.00) for your effort
which you made to assist me claimed my fund from the delivering
security company . I have giving rev father Peter Solomon the amount
contain  ($300,000.00) United States Dollars as your compensation for
all your past effort to assist me, I would have transfer the money
directly to you but, due to I am a Military I am not allowed to
transact or remit such huge sums of money from my account. to avoid
bank charges and condition of services which will delay the money
getting to you early enough,

Contact rev Peter Solomon to send you, your named Visa Card containing
the Three Hundred thousand United States Dollars, the rev father will
also send the four digits secret pin code to you after they  send the
CARD to you.

>From the card you can withdraw a maximum of Thirty Thousand United
States Dollars per a day and you can also transfer from the same Visa
Card.
to your local bank account a maximum of 30 thousand United States
Dollars per a day.

The card will be fully activated for withdrawals in any country of the
world and in countries where United States Dollars are not used you
will be paid in that country's local currency Dollar equivalent.

There is a change in my previous arrangement, so I will be traveling
to London tomorrow with my sick husband for treatment tomorrow with my
new partner who finish the transfer.

As soon as you receive the ATM card let me know.You can write to the
rev father through this

Email: (revfatherpetersolo...@aol.com)

Contact Person Peter Solomon

Thanks
Lindsey ,


Git smart http: parsing commit messages in git-receive-pack

2017-05-06 Thread akos tajti
Dear All,

we implemented a java servlet around the git-http-backend. This servlet 
intercepts the requests sent by the git client when pushing. One thing I want 
to achieve is parsing the commit messages in the pre push phase (request param 
service==git-receive-pack) and after checking if the commit messages contain a 
given string reject/accept the request. The problem is that I couldn't find a 
way of parsing the commit messages in git-receive-pack (I can do this in the 
post  push phase but in that case I cannot reject the push because the changes 
are already on the server). Is there a way of getting the commit messages 
before they're actually on the server so that I can reject the push?

Thanks in advance,
Ákos Tajti



Re: [RFC 00/14] convert dir.c to take an index parameter

2017-05-06 Thread Junio C Hamano
Brandon Williams  writes:

> One of the things brought up on the list in the past few days has been
> migrating away from using the index compatibility macros.  One of the issues
> brought up in that thread was how simply doing that conversion doesn't
> eliminate the reliance on global state (specifically the_index).  If one day 
> we
> want to have a 'repository object' passed around then we first need to convert
> different subsystems to be prepared to handle that.  This series provides a
> first step, converting the code in dir.c to take a 'struct index_state' and
> using that instead of implicitly using 'the_index'.

Very nicely done (I only skimmed "dir.c" in the end result and didn't
go through the changes with fine toothed comb, though).

I would have done this without the first step and then instead had a
final patch that only inserts a single

#define NO_THE_INDEX_COMPATIBILITY_MACROS

at the beginning of dir.c once everybody in dir.c loses the
reference to all "cache" macros at the end, if I were doing this
series, but it is a personal taste.  

The resulting dir.c does not even refer to the_index, which is very
nice.

Thanks.

> Brandon Williams (14):
>   dir: stop using the index compatibility macros
>   dir: convert read_skip_worktree_file_from_index to take an index
>   dir: convert directory_exists_in_index to take index
>   dir: convert get_dtype to take index
>   dir: convert dir_add* to take an index
>   dir: convert last_exclude_matching_from_list to take an index
>   dir: convert is_excluded_from_list to take an index
>   dir: convert add_excludes to take an index
>   dir: convert prep_exclude to take an index
>   dir: convert is_excluded to take an index
>   dir: convert open_cached_dir to take an index
>   dir: convert read_directory_recursive to take an index
>   dir: convert read_directory to take an index
>   dir: convert fill_directory to take an index
>
>  builtin/add.c  |   7 +-
>  builtin/check-ignore.c |   3 +-
>  builtin/clean.c|   4 +-
>  builtin/grep.c |   2 +-
>  builtin/ls-files.c |   4 +-
>  dir.c  | 200 
> -
>  dir.h  |  27 +--
>  unpack-trees.c |  10 +--
>  wt-status.c|   2 +-
>  9 files changed, 151 insertions(+), 108 deletions(-)


Script to rebase branches

2017-05-06 Thread Lars Schneider
Hi,

I am about to write a bash/sh script that helps me to rebase a bunch of 
branches (e.g. select branches based on prefix, conflict resolution/
rerere support, ...).

I wonder if anyone has such a script already and is willing to share it.

Thanks,
Lars


Not translatable strings in Git

2017-05-06 Thread Jordi Mas

Hello,

When translating git (https://github.com/git/git/tree/master/po)

The following strings cannot be translated:

 remote: Counting objects: 331, done.
 remote: Compressing objects: 100% (213/213), done.
 remote: Total 244 (delta 184), reused 34 (delta 29)
 27 files changed, 3399 insertions(+), 3320 deletions(-)
 create mode 100644 build-aux/flatpak/org.gnome.Nautilus-stable.json
 delete mode 100755 build-aux/meson/check_libgd.sh

Since they are not in the PO files.

When working on making these strings localisable, I suggest checking 
that in the same modules there are other hardcoded strings that cannot 
be localised.


Thanks

Jordi,


---
This email has been checked for viruses by AVG.
http://www.avg.com



Add an option to automatically submodule update on checkout

2017-05-06 Thread Ciro Santilli
This is a must if you are working with submodules, otherwise every git
checkout requires a git submodule update, and you forget it, and
things break, and you understand, and you go to stack overflow
questions 
http://stackoverflow.com/questions/22328053/why-doesnt-git-checkout-automatically-do-git-submodule-update-recursive
| 
http://stackoverflow.com/questions/4611512/is-there-a-way-to-make-git-pull-automatically-update-submodules
and you give up and create aliases :-)