git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] tree-walk: convert fill_tree_descriptor() to object_id
@ 2017-08-12  7:14 René Scharfe
  2017-08-12  8:04 ` Johannes Sixt
  2017-08-12  8:32 ` [PATCH v2] " René Scharfe
  0 siblings, 2 replies; 4+ messages in thread
From: René Scharfe @ 2017-08-12  7:14 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, brian m. carlson

All callers of fill_tree_descriptor() have been converted to object_id
already, so convert that function as well.  As a nice side-effect we get
rid of NULL checks in tree-diff.c, as fill_tree_descriptor() already
does them for us.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 Documentation/technical/api-tree-walking.txt |  6 +++---
 builtin/merge-tree.c                         | 10 +++++-----
 builtin/reset.c                              |  4 ++--
 notes.c                                      |  2 +-
 tree-diff.c                                  |  5 ++---
 tree-walk.c                                  |  9 +++++----
 tree-walk.h                                  |  2 +-
 unpack-trees.c                               |  6 +++---
 8 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/Documentation/technical/api-tree-walking.txt b/Documentation/technical/api-tree-walking.txt
index 14af37c3f1..a5334a472e 100644
--- a/Documentation/technical/api-tree-walking.txt
+++ b/Documentation/technical/api-tree-walking.txt
@@ -55,9 +55,9 @@ Initializing
 
 `fill_tree_descriptor`::
 
-	Initialize a `tree_desc` and decode its first entry given the sha1 of
-	a tree. Returns the `buffer` member if the sha1 is a valid tree
-	identifier and NULL otherwise.
+	Initialize a `tree_desc` and decode its first entry given the
+	object ID of a tree. Returns the `buffer` member if the sha1 is
+	a valid tree identifier and NULL otherwise.
 
 `setup_traverse_info`::
 
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index f12da292cf..6ea246a200 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -213,10 +213,10 @@ static void unresolved_directory(const struct traverse_info *info,
 
 	newbase = traverse_path(info, p);
 
-#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
-	buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
-	buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
-	buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
+#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid : NULL)
+	buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
+	buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
+	buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
 #undef ENTRY_SHA1
 
 	merge_trees(t, newbase);
@@ -352,7 +352,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
 
 	if (get_oid(rev, &oid))
 		die("unknown rev %s", rev);
-	buf = fill_tree_descriptor(desc, oid.hash);
+	buf = fill_tree_descriptor(desc, &oid);
 	if (!buf)
 		die("%s is not a tree", rev);
 	return buf;
diff --git a/builtin/reset.c b/builtin/reset.c
index 046403ed68..4a02d74073 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -75,13 +75,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
 		struct object_id head_oid;
 		if (get_oid("HEAD", &head_oid))
 			return error(_("You do not have a valid HEAD."));
-		if (!fill_tree_descriptor(desc, head_oid.hash))
+		if (!fill_tree_descriptor(desc, &head_oid))
 			return error(_("Failed to find tree of HEAD."));
 		nr++;
 		opts.fn = twoway_merge;
 	}
 
-	if (!fill_tree_descriptor(desc + nr - 1, oid->hash))
+	if (!fill_tree_descriptor(desc + nr - 1, oid))
 		return error(_("Failed to find tree of %s."), oid_to_hex(oid));
 	if (unpack_trees(nr, desc, &opts))
 		return -1;
diff --git a/notes.c b/notes.c
index 503754d79e..f090c88363 100644
--- a/notes.c
+++ b/notes.c
@@ -425,7 +425,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 	unsigned char type;
 	struct leaf_node *l;
 
-	buf = fill_tree_descriptor(&desc, subtree->val_oid.hash);
+	buf = fill_tree_descriptor(&desc, &subtree->val_oid);
 	if (!buf)
 		die("Could not read %s for notes-index",
 		     oid_to_hex(&subtree->val_oid));
diff --git a/tree-diff.c b/tree-diff.c
index 2357f72899..4bb93155bc 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -421,9 +421,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
 	 *   diff_tree_oid(parent, commit) )
 	 */
 	for (i = 0; i < nparent; ++i)
-		tptree[i] = fill_tree_descriptor(&tp[i],
-				parents_oid[i] ? parents_oid[i]->hash : NULL);
-	ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
+		tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);
+	ttree = fill_tree_descriptor(&t, oid);
 
 	/* Enable recursion indefinitely */
 	opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
diff --git a/tree-walk.c b/tree-walk.c
index 6a42e402b0..c99309069a 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -78,15 +78,16 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l
 	return result;
 }
 
-void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
+void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
 {
 	unsigned long size = 0;
 	void *buf = NULL;
 
-	if (sha1) {
-		buf = read_object_with_reference(sha1, tree_type, &size, NULL);
+	if (oid) {
+		buf = read_object_with_reference(oid->hash, tree_type, &size,
+						 NULL);
 		if (!buf)
-			die("unable to read tree %s", sha1_to_hex(sha1));
+			die("unable to read tree %s", oid_to_hex(oid));
 	}
 	init_tree_desc(desc, buf, size);
 	return buf;
diff --git a/tree-walk.h b/tree-walk.h
index 68bb78b928..b6bd1b4ccf 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -42,7 +42,7 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long
 int tree_entry(struct tree_desc *, struct name_entry *);
 int tree_entry_gently(struct tree_desc *, struct name_entry *);
 
-void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
+void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
 
 struct traverse_info;
 typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
diff --git a/unpack-trees.c b/unpack-trees.c
index 862cfce661..233ec5eb3d 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -662,10 +662,10 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 		else if (i > 1 && are_same_oid(&names[i], &names[i - 2]))
 			t[i] = t[i - 2];
 		else {
-			const unsigned char *sha1 = NULL;
+			const struct object_id *oid = NULL;
 			if (dirmask & 1)
-				sha1 = names[i].oid->hash;
-			buf[nr_buf++] = fill_tree_descriptor(t+i, sha1);
+				oid = names[i].oid;
+			buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
 		}
 	}
 
-- 
2.14.1


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

* Re: [PATCH] tree-walk: convert fill_tree_descriptor() to object_id
  2017-08-12  7:14 [PATCH] tree-walk: convert fill_tree_descriptor() to object_id René Scharfe
@ 2017-08-12  8:04 ` Johannes Sixt
  2017-08-12  8:32 ` [PATCH v2] " René Scharfe
  1 sibling, 0 replies; 4+ messages in thread
From: Johannes Sixt @ 2017-08-12  8:04 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano, brian m. carlson

Am 12.08.2017 um 09:14 schrieb René Scharfe:
> -	Initialize a `tree_desc` and decode its first entry given the sha1 of
> -	a tree. Returns the `buffer` member if the sha1 is a valid tree
> -	identifier and NULL otherwise.
> +	Initialize a `tree_desc` and decode its first entry given the
> +	object ID of a tree. Returns the `buffer` member if the sha1 is
> +	a valid tree identifier and NULL otherwise.

There is another mention of "sha1" in the rewritten text. Intended or an 
oversight?

> -#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
> -	buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
> -	buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
> -	buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
> +#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid : NULL)
> +	buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
> +	buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
> +	buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
>   #undef ENTRY_SHA1

This whould be #undef ENTRY_OID.

-- Hannes

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

* [PATCH v2] tree-walk: convert fill_tree_descriptor() to object_id
  2017-08-12  7:14 [PATCH] tree-walk: convert fill_tree_descriptor() to object_id René Scharfe
  2017-08-12  8:04 ` Johannes Sixt
@ 2017-08-12  8:32 ` René Scharfe
  2017-08-12 14:59   ` brian m. carlson
  1 sibling, 1 reply; 4+ messages in thread
From: René Scharfe @ 2017-08-12  8:32 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, brian m. carlson, Johannes Sixt

All callers of fill_tree_descriptor() have been converted to object_id
already, so convert that function as well.  As a nice side-effect we get
rid of NULL checks in tree-diff.c, as fill_tree_descriptor() already
does them for us.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Changes from v1: Don't mention sha1 in documentation anymore, #undef
ENTRY_OID.  Thanks for spotting, Johannes!

 Documentation/technical/api-tree-walking.txt |  6 +++---
 builtin/merge-tree.c                         | 12 ++++++------
 builtin/reset.c                              |  4 ++--
 notes.c                                      |  2 +-
 tree-diff.c                                  |  5 ++---
 tree-walk.c                                  |  9 +++++----
 tree-walk.h                                  |  2 +-
 unpack-trees.c                               |  6 +++---
 8 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/Documentation/technical/api-tree-walking.txt b/Documentation/technical/api-tree-walking.txt
index 14af37c3f1..bde18622a8 100644
--- a/Documentation/technical/api-tree-walking.txt
+++ b/Documentation/technical/api-tree-walking.txt
@@ -55,9 +55,9 @@ Initializing
 
 `fill_tree_descriptor`::
 
-	Initialize a `tree_desc` and decode its first entry given the sha1 of
-	a tree. Returns the `buffer` member if the sha1 is a valid tree
-	identifier and NULL otherwise.
+	Initialize a `tree_desc` and decode its first entry given the
+	object ID of a tree. Returns the `buffer` member if the latter
+	is a valid tree identifier and NULL otherwise.
 
 `setup_traverse_info`::
 
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index f12da292cf..d01ddecf66 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -213,11 +213,11 @@ static void unresolved_directory(const struct traverse_info *info,
 
 	newbase = traverse_path(info, p);
 
-#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
-	buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
-	buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
-	buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
-#undef ENTRY_SHA1
+#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid : NULL)
+	buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
+	buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
+	buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
+#undef ENTRY_OID
 
 	merge_trees(t, newbase);
 
@@ -352,7 +352,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
 
 	if (get_oid(rev, &oid))
 		die("unknown rev %s", rev);
-	buf = fill_tree_descriptor(desc, oid.hash);
+	buf = fill_tree_descriptor(desc, &oid);
 	if (!buf)
 		die("%s is not a tree", rev);
 	return buf;
diff --git a/builtin/reset.c b/builtin/reset.c
index 046403ed68..4a02d74073 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -75,13 +75,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
 		struct object_id head_oid;
 		if (get_oid("HEAD", &head_oid))
 			return error(_("You do not have a valid HEAD."));
-		if (!fill_tree_descriptor(desc, head_oid.hash))
+		if (!fill_tree_descriptor(desc, &head_oid))
 			return error(_("Failed to find tree of HEAD."));
 		nr++;
 		opts.fn = twoway_merge;
 	}
 
-	if (!fill_tree_descriptor(desc + nr - 1, oid->hash))
+	if (!fill_tree_descriptor(desc + nr - 1, oid))
 		return error(_("Failed to find tree of %s."), oid_to_hex(oid));
 	if (unpack_trees(nr, desc, &opts))
 		return -1;
diff --git a/notes.c b/notes.c
index 503754d79e..f090c88363 100644
--- a/notes.c
+++ b/notes.c
@@ -425,7 +425,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 	unsigned char type;
 	struct leaf_node *l;
 
-	buf = fill_tree_descriptor(&desc, subtree->val_oid.hash);
+	buf = fill_tree_descriptor(&desc, &subtree->val_oid);
 	if (!buf)
 		die("Could not read %s for notes-index",
 		     oid_to_hex(&subtree->val_oid));
diff --git a/tree-diff.c b/tree-diff.c
index 2357f72899..4bb93155bc 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -421,9 +421,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
 	 *   diff_tree_oid(parent, commit) )
 	 */
 	for (i = 0; i < nparent; ++i)
-		tptree[i] = fill_tree_descriptor(&tp[i],
-				parents_oid[i] ? parents_oid[i]->hash : NULL);
-	ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
+		tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);
+	ttree = fill_tree_descriptor(&t, oid);
 
 	/* Enable recursion indefinitely */
 	opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
diff --git a/tree-walk.c b/tree-walk.c
index 6a42e402b0..c99309069a 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -78,15 +78,16 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l
 	return result;
 }
 
-void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
+void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
 {
 	unsigned long size = 0;
 	void *buf = NULL;
 
-	if (sha1) {
-		buf = read_object_with_reference(sha1, tree_type, &size, NULL);
+	if (oid) {
+		buf = read_object_with_reference(oid->hash, tree_type, &size,
+						 NULL);
 		if (!buf)
-			die("unable to read tree %s", sha1_to_hex(sha1));
+			die("unable to read tree %s", oid_to_hex(oid));
 	}
 	init_tree_desc(desc, buf, size);
 	return buf;
diff --git a/tree-walk.h b/tree-walk.h
index 68bb78b928..b6bd1b4ccf 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -42,7 +42,7 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long
 int tree_entry(struct tree_desc *, struct name_entry *);
 int tree_entry_gently(struct tree_desc *, struct name_entry *);
 
-void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
+void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
 
 struct traverse_info;
 typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
diff --git a/unpack-trees.c b/unpack-trees.c
index 862cfce661..233ec5eb3d 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -662,10 +662,10 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 		else if (i > 1 && are_same_oid(&names[i], &names[i - 2]))
 			t[i] = t[i - 2];
 		else {
-			const unsigned char *sha1 = NULL;
+			const struct object_id *oid = NULL;
 			if (dirmask & 1)
-				sha1 = names[i].oid->hash;
-			buf[nr_buf++] = fill_tree_descriptor(t+i, sha1);
+				oid = names[i].oid;
+			buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
 		}
 	}
 
-- 
2.14.1

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

* Re: [PATCH v2] tree-walk: convert fill_tree_descriptor() to object_id
  2017-08-12  8:32 ` [PATCH v2] " René Scharfe
@ 2017-08-12 14:59   ` brian m. carlson
  0 siblings, 0 replies; 4+ messages in thread
From: brian m. carlson @ 2017-08-12 14:59 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano, Johannes Sixt

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

On Sat, Aug 12, 2017 at 10:32:59AM +0200, René Scharfe wrote:
> All callers of fill_tree_descriptor() have been converted to object_id
> already, so convert that function as well.  As a nice side-effect we get
> rid of NULL checks in tree-diff.c, as fill_tree_descriptor() already
> does them for us.
> 
> Helped-by: Johannes Sixt <j6t@kdbg.org>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>

This looks good to me.  I had written a very similar patch for a later
series, and they're pretty much identical.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

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

end of thread, other threads:[~2017-08-12 14:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-12  7:14 [PATCH] tree-walk: convert fill_tree_descriptor() to object_id René Scharfe
2017-08-12  8:04 ` Johannes Sixt
2017-08-12  8:32 ` [PATCH v2] " René Scharfe
2017-08-12 14:59   ` brian m. carlson

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).