From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Strange merge failure (would be overwritten by merge / cannot merge)
Date: Sun, 6 Sep 2009 13:58:20 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.01.0909061354010.8946@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.01.0909061338350.8946@localhost.localdomain>
On Sun, 6 Sep 2009, Linus Torvalds wrote:
>
> I agree. It's why I initially wanted to do it _all_ in the
> unpack_callback() thing, but the more I tried, the more complex it got.
>
> So now my plan is to do the conflict handling at a tree level in
> traverse_trees(), and get rid of the use of 'df_name_compare()' just there
> first.
Grr. I need to go off and do some other things, and this still fails a few
tests. This is not my more exhaustive patch that actually tries to
remember the conflict entries we've used up, this is the most cut-down and
simplified "just remove df_name_compare() in tree-walk.c".
And it's not working, for some reason I'm not seeing, but I thought I'd
send it to you just as a way to show where I'm trying to take this. Maybe
you see what my thinko is.
[ In other words: in this version, we only do a single-entry lookahead,
exactly like we used to do before. So this is not meant to _fix_
anything, or change any semantics. It's an incremental "change the model
so that we can look ahead more in a future patch" patch.
But it's broken, and I have to run away for a while. ]
Linus
---
tree-walk.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/tree-walk.c b/tree-walk.c
index 02e2aed..dd563e9 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -62,7 +62,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
static int entry_compare(struct name_entry *a, struct name_entry *b)
{
- return df_name_compare(
+ return base_name_compare(
a->path, tree_entry_len(a->path, a->sha1), a->mode,
b->path, tree_entry_len(b->path, b->sha1), b->mode);
}
@@ -138,6 +138,68 @@ char *make_traverse_path(char *path, const struct traverse_info *info, const str
return path;
}
+/*
+ * See if 'entry' may conflict with a later tree entry in 't': if so,
+ * fill in 'conflict' with the conflicting tree entry from 't'.
+ *
+ * NOTE! Right now we do _not_ create a create a private copy of the tree
+ * descriptor, so we can't actually walk it any further without losing
+ * our place. We should change it to a loop over a copy of the tree
+ * descriptor, but then we'd also have to remember the skipped entries,
+ * so this is a hacky simple case that only handles the case we used
+ * to handle historically (ie clash in the very first entry)
+ *
+ * Note that only a regular file 'entry' can conflict with a later
+ * directory, since a directory with the same name will sort later.
+ */
+static int find_df_conflict(struct tree_desc *t, struct name_entry *entry, struct name_entry *conflict)
+{
+ int len;
+
+ if (S_ISDIR(entry->mode))
+ return 0;
+ len = tree_entry_len(entry->path, entry->sha1);
+
+ while (t->size) {
+ int nlen;
+
+ entry_extract(t, conflict);
+ nlen = tree_entry_len(conflict->path, conflict->sha1);
+
+ /*
+ * We can only have a future conflict if the entry matches the
+ * beginning of the name exactly, and if the next character is
+ * smaller than '/'.
+ *
+ * Break out otherwise.
+ */
+ if (nlen < len)
+ break;
+ if (memcmp(conflict->path, entry->path, nlen))
+ break;
+
+ /*
+ * FIXME! This is the case where we'd like to mark the tree
+ * entry used in the original 't' rather than modify 't'!
+ */
+ if (nlen == len) {
+ update_tree_entry(t);
+ return 1;
+ }
+
+ if (conflict->path[len] > '/')
+ break;
+ /*
+ * FIXME! Here we'd really like to do 'update_tree_entry(©);'
+ * but that requires us to remember the conflict position specially
+ * so now we just punt and stop looking for conflicts
+ */
+ break;
+ }
+ entry_clear(conflict);
+ return 0;
+}
+
int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
{
int ret = 0;
@@ -179,12 +241,15 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
dirmask &= mask;
/*
- * Clear all the unused name-entries.
+ * Clear all the unused name-entries, and look for
+ * conflicts.
*/
for (i = 0; i < n; i++) {
if (mask & (1ul << i))
continue;
entry_clear(entry + i);
+ if (find_df_conflict(t+i, entry+last, entry+i))
+ dirmask |= (1ul << i);
}
ret = info->fn(n, mask, dirmask, entry, info);
if (ret < 0)
next prev parent reply other threads:[~2009-09-06 20:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-04 20:28 Strange merge failure (would be overwritten by merge / cannot merge) Christoph Haas
2009-09-04 23:45 ` David Aguilar
2009-09-05 13:07 ` Christoph Haas
2009-09-05 17:46 ` Junio C Hamano
2009-09-06 0:33 ` Junio C Hamano
2009-09-06 8:21 ` Junio C Hamano
2009-09-06 18:18 ` Linus Torvalds
2009-09-06 19:39 ` Junio C Hamano
2009-09-06 19:54 ` Linus Torvalds
2009-09-06 20:36 ` Junio C Hamano
2009-09-06 20:42 ` Linus Torvalds
2009-09-06 20:58 ` Linus Torvalds [this message]
2009-09-06 21:17 ` Junio C Hamano
2009-09-06 21:37 ` Linus Torvalds
2009-09-06 22:49 ` Linus Torvalds
2009-09-06 21:11 ` Junio C Hamano
2009-09-05 6:40 ` unpack-trees traversing with index quite broken Junio C Hamano
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=alpine.LFD.2.01.0909061354010.8946@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--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).