Thread (3 messages) flat view 3 messages, 2 authors, 2016-06-15

Re: [PATCH] unpack-trees: don't shift conflicts left and right

From: René Scharfe <hidden>
Date: 2016-06-15 22:57:47
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Am 17.06.2013 22:44, schrieb Junio C Hamano:
René Scharfe [off-list ref] writes:
quoted
quoted
The information is only useful for the unpack_trees callback, and
"info->data" is a more appropriate place to hang such a callback
specific data.

Perhaps we should use info->data field to point at

	struct {
          	struct unpack_trees_options *o;
          	unsigned long df_conflict;
	};

and get rid of info->conflicts field?
Here's a patch that does so, but it complicates matters quite a bit.
Did I miss anything (or rather: add too much)?
I do not think so.  These bits are needed per recursion level, and
it cannot be shoved into unpack_trees_options so I suspect that your
patch is the best we can do.  Or, perhaps we can

  - add df_conflict to struct unpack_trees_options;

  - have traverse_info->data point at struct unpack_trees_options as
    before; and

  - save the old value of o->df_conflict on the stack of
    traverse_trees_recursive(), update the field in place, and
    restore it when the recursion returns???
I'm not sure unpack_trees_options is the right place for that, but it
already has several members that aren't really "options".  It would
look something like this:


 tree-walk.h    | 1 -
 unpack-trees.c | 9 +++++++--
 unpack-trees.h | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tree-walk.h b/tree-walk.h
index ae04b64..4876695 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -46,7 +46,6 @@ struct traverse_info {
 	int pathlen;
 	struct pathspec *pathspec;
 
-	unsigned long df_conflicts;
 	traverse_callback_t fn;
 	void *data;
 	int show_all_errors;
diff --git a/unpack-trees.c b/unpack-trees.c
index b27f2a6..1c0ead0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -454,6 +454,10 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 	void *buf[MAX_UNPACK_TREES];
 	struct traverse_info newinfo;
 	struct name_entry *p;
+	struct unpack_trees_options *o = info->data;
+	unsigned long saved_df_conflicts = o->df_conflicts;
+
+	o->df_conflicts |= df_conflicts;
 
 	p = names;
 	while (!p->mode)
@@ -464,7 +468,6 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 	newinfo.pathspec = info->pathspec;
 	newinfo.name = *p;
 	newinfo.pathlen += tree_entry_len(p) + 1;
-	newinfo.df_conflicts |= df_conflicts;
 
 	for (i = 0; i < n; i++, dirmask >>= 1) {
 		const unsigned char *sha1 = NULL;
@@ -480,6 +483,8 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 	for (i = 0; i < n; i++)
 		free(buf[i]);
 
+	o->df_conflicts = saved_df_conflicts;
+
 	return ret;
 }
 
@@ -565,7 +570,7 @@ static int unpack_nondirectories(int n, unsigned long mask,
 {
 	int i;
 	struct unpack_trees_options *o = info->data;
-	unsigned long conflicts = info->df_conflicts | dirmask;
+	unsigned long conflicts = o->df_conflicts | dirmask;
 
 	/* Do we have *only* directories? Nothing to do */
 	if (mask == dirmask && !src[0])
diff --git a/unpack-trees.h b/unpack-trees.h
index 36a73a6..05ee968 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -66,6 +66,7 @@ struct unpack_trees_options {
 
 	struct cache_entry *df_conflict_entry;
 	void *unpack_data;
+	unsigned long df_conflicts;
 
 	struct index_state *dst_index;
 	struct index_state *src_index;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help