[PATCH v3 4/4] Switch empty tree and blob lookups to use hash abstraction

2017-11-12 Thread brian m. carlson
Switch the uses of empty_tree_oid and empty_blob_oid to use the
current_hash abstraction that represents the current hash algorithm in
use.

Signed-off-by: brian m. carlson 
---
 builtin/am.c   | 2 +-
 builtin/checkout.c | 2 +-
 builtin/diff.c | 2 +-
 builtin/pull.c | 2 +-
 cache.h| 8 
 diff-lib.c | 2 +-
 merge-recursive.c  | 2 +-
 notes-merge.c  | 2 +-
 sequencer.c| 6 +++---
 submodule.c| 2 +-
 10 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 92c4853505..99dbde3e85 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1433,7 +1433,7 @@ static void write_index_patch(const struct am_state 
*state)
if (!get_oid_tree("HEAD", &head))
tree = lookup_tree(&head);
else
-   tree = lookup_tree(&empty_tree_oid);
+   tree = lookup_tree(the_hash_algo->empty_tree);
 
fp = xfopen(am_path(state, "patch"), "w");
init_revisions(&rev_info, NULL);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 6c2b4cd419..2b64805f35 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -514,7 +514,7 @@ static int merge_working_tree(const struct checkout_opts 
*opts,
}
tree = parse_tree_indirect(old->commit ?
   &old->commit->object.oid :
-  &empty_tree_oid);
+  the_hash_algo->empty_tree);
init_tree_desc(&trees[0], tree->buffer, tree->size);
tree = parse_tree_indirect(&new->commit->object.oid);
init_tree_desc(&trees[1], tree->buffer, tree->size);
diff --git a/builtin/diff.c b/builtin/diff.c
index 9808d062a8..16bfb22f73 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -379,7 +379,7 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix)
add_head_to_pending(&rev);
if (!rev.pending.nr) {
struct tree *tree;
-   tree = lookup_tree(&empty_tree_oid);
+   tree = 
lookup_tree(the_hash_algo->empty_tree);
add_pending_object(&rev, &tree->object, 
"HEAD");
}
break;
diff --git a/builtin/pull.c b/builtin/pull.c
index a28f0ffadd..3d26f8ff32 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -545,7 +545,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_oid, merge_head, 0))
+   if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
return 1;
 
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, 
UPDATE_REFS_DIE_ON_ERR))
diff --git a/cache.h b/cache.h
index c238688f6c..d68895b45f 100644
--- a/cache.h
+++ b/cache.h
@@ -1024,22 +1024,22 @@ extern const struct object_id empty_blob_oid;
 
 static inline int is_empty_blob_sha1(const unsigned char *sha1)
 {
-   return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
+   return !hashcmp(sha1, the_hash_algo->empty_blob->hash);
 }
 
 static inline int is_empty_blob_oid(const struct object_id *oid)
 {
-   return !hashcmp(oid->hash, EMPTY_BLOB_SHA1_BIN);
+   return !oidcmp(oid, the_hash_algo->empty_blob);
 }
 
 static inline int is_empty_tree_sha1(const unsigned char *sha1)
 {
-   return !hashcmp(sha1, EMPTY_TREE_SHA1_BIN);
+   return !hashcmp(sha1, the_hash_algo->empty_tree->hash);
 }
 
 static inline int is_empty_tree_oid(const struct object_id *oid)
 {
-   return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
+   return !oidcmp(oid, the_hash_algo->empty_tree);
 }
 
 /* set default permissions by passing mode arguments to open(2) */
diff --git a/diff-lib.c b/diff-lib.c
index 731f0886d6..893fee432c 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -217,7 +217,7 @@ int run_diff_files(struct rev_info *revs, unsigned int 
option)
} else if (revs->diffopt.ita_invisible_in_index &&
   ce_intent_to_add(ce)) {
diff_addremove(&revs->diffopt, '+', ce->ce_mode,
-  &empty_tree_oid, 0,
+  the_hash_algo->empty_tree, 0,
   ce->name, 0);
continue;
}
diff --git a/merge-recursive.c b/merge-recursive.c
index 2ca8444c65..f89cc751e1 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2081,7 +2081,7 @@ int merge_recursive(struct merge_options *o,
/* if there is no common ancestor, use an empty tree */
struct tree *tree;
 
-

Re: [PATCH v3 4/4] Switch empty tree and blob lookups to use hash abstraction

2017-11-13 Thread Stefan Beller
On Sun, Nov 12, 2017 at 1:28 PM, brian m. carlson
 wrote:
> Switch the uses of empty_tree_oid and empty_blob_oid to use the
> current_hash abstraction that represents the current hash algorithm in
> use.
>
> Signed-off-by: brian m. carlson 
> ---

Thanks for writing this series,
all four patches look good to me.

Thanks,
Stefan