From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] unpack-trees: don't shift conflicts left and right
Date: Mon, 17 Jun 2013 22:30:12 +0200 [thread overview]
Message-ID: <51BF71D4.402@lsrfire.ath.cx> (raw)
In-Reply-To: <7va9mqlvpu.fsf@alter.siamese.dyndns.org>
Am 16.06.2013 02:56, schrieb Junio C Hamano:
> One thing renaming df_conficts to conflicts really proves is that
> this field is not used by the traverse_trees machinery at all.
>
> Before this patch, the bits in conflicts (now df_conflicts) mask had
> the semantics that is not consistent with the dirmask/mask the
> tree-walk machinery uses to communicate with its callers and
> callbacks. Everything in tree-walk.[ch] is about "walk N trees",
> and bit 0 of dirmask and mask always means the first tree, not
> "first tree, or in index if the callback is doing a merge", which
> is used in the conflicts field before this patch.
Right.
> I think the true source of the confusion is that the "conflicts"
> field does not logically belong there. It is not needed in the
> general "walk N trees" machinery.
NB: The only other caller of traverse_trees is git merge-tree.
> 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)?
---
tree-walk.h | 1 -
unpack-trees.c | 38 +++++++++++++++++++++++++++++---------
2 files changed, 29 insertions(+), 10 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..1c1b4de 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -416,11 +416,17 @@ static int unpack_index_entry(struct cache_entry *ce,
return ret;
}
+struct unpack_callback_info {
+ struct unpack_trees_options *options;
+ unsigned long df_conflicts;
+};
+
static int find_cache_pos(struct traverse_info *, const struct name_entry *);
static void restore_cache_bottom(struct traverse_info *info, int bottom)
{
- struct unpack_trees_options *o = info->data;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
if (o->diff_index_cached)
return;
@@ -429,7 +435,8 @@ static void restore_cache_bottom(struct traverse_info *info, int bottom)
static int switch_cache_bottom(struct traverse_info *info)
{
- struct unpack_trees_options *o = info->data;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
int ret, pos;
if (o->diff_index_cached)
@@ -452,9 +459,14 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
int i, ret, bottom;
struct tree_desc t[MAX_UNPACK_TREES];
void *buf[MAX_UNPACK_TREES];
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_callback_info newuci;
struct traverse_info newinfo;
struct name_entry *p;
+ newuci = *uci;
+ newuci.df_conflicts |= df_conflicts;
+
p = names;
while (!p->mode)
p++;
@@ -464,7 +476,7 @@ 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;
+ newinfo.data = &newuci;
for (i = 0; i < n; i++, dirmask >>= 1) {
const unsigned char *sha1 = NULL;
@@ -564,8 +576,9 @@ static int unpack_nondirectories(int n, unsigned long mask,
const struct traverse_info *info)
{
int i;
- struct unpack_trees_options *o = info->data;
- unsigned long conflicts = info->df_conflicts | dirmask;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
+ unsigned long conflicts = uci->df_conflicts | dirmask;
/* Do we have *only* directories? Nothing to do */
if (mask == dirmask && !src[0])
@@ -644,7 +657,8 @@ static int find_cache_pos(struct traverse_info *info,
const struct name_entry *p)
{
int pos;
- struct unpack_trees_options *o = info->data;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
struct index_state *index = o->src_index;
int pfxlen = info->pathlen;
int p_len = tree_entry_len(p);
@@ -699,7 +713,8 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info,
const struct name_entry *p)
{
int pos = find_cache_pos(info, p);
- struct unpack_trees_options *o = info->data;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
if (0 <= pos)
return o->src_index->cache[pos];
@@ -742,7 +757,8 @@ static void debug_unpack_callback(int n,
static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
{
struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
- struct unpack_trees_options *o = info->data;
+ struct unpack_callback_info *uci = info->data;
+ struct unpack_trees_options *o = uci->options;
const struct name_entry *p = names;
/* Find first entry with a real name (we could use "mask" too) */
@@ -1054,11 +1070,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
if (len) {
const char *prefix = o->prefix ? o->prefix : "";
+ struct unpack_callback_info uci;
struct traverse_info info;
+ memset(&uci, 0, sizeof(uci));
+ uci.options = o;
+
setup_traverse_info(&info, prefix);
info.fn = unpack_callback;
- info.data = o;
+ info.data = &uci;
info.show_all_errors = o->show_all_errors;
info.pathspec = o->pathspec;
next prev parent reply other threads:[~2013-06-17 20:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-15 23:44 [PATCH] unpack-trees: don't shift conflicts left and right René Scharfe
2013-06-16 0:56 ` Junio C Hamano
2013-06-17 20:30 ` René Scharfe [this message]
2013-06-17 20:44 ` Junio C Hamano
2013-06-17 22:29 ` René Scharfe
2013-06-17 23:29 ` Junio C Hamano
2013-06-17 23:26 ` René Scharfe
2013-06-17 23:42 ` Junio C Hamano
2013-06-18 19:33 ` René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51BF71D4.402@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).