From: Yann Dirson <ydirson@altern.org>
To: git@vger.kernel.org
Cc: Yann Dirson <ydirson@altern.org>, Yann Dirson <ydirson@free.fr>
Subject: [PATCH v6 4/5] [RFC] Consider all parents of a file as candidates for bulk rename.
Date: Fri, 15 Oct 2010 01:29:58 +0200 [thread overview]
Message-ID: <1287098999-9244-5-git-send-email-ydirson@altern.org> (raw)
In-Reply-To: <1287098999-9244-4-git-send-email-ydirson@altern.org>
We previously only looked at the immediate parents of a file involved
in a move. Now consider upper ones as candidates too.
The way it is done here is somewhat inefficient, but at least it
handles all previously-known cases of incorrectness.
Note this patch largely puts existing code in a look, and is a bit
easier to read with -w.
Signed-off-by: Yann Dirson <ydirson@free.fr>
---
diffcore-rename.c | 118 ++++++++++++++++++++++++++++-------------------------
1 files changed, 63 insertions(+), 55 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 1be1af1..ff69201 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -542,7 +542,7 @@ static int maybe_disqualify_bulkmove(const char* one_parent_path,
if (strncmp(rename_dst[j].two->path,
one_parent_path, onep_len))
break; /* exhausted directory in this direction */
- fprintf(stderr, "[DBG] leftover file %s in %s\n",
+ fprintf(stderr, "[DBG] leftover file %s in '%s'\n",
rename_dst[j].two->path, one_parent_path);
if (rename_dst[j].i_am_not_single || /* those were already here */
(rename_dst[j].pair &&
@@ -596,66 +596,74 @@ static void check_one_bulk_move(struct diff_filepair *dstpair)
maybe_disqualify_bulkmove(one_parent_path, one_leftover))
return;
- fprintf(stderr, "[] %s -> %s ?\n",dstpair->one->path, dstpair->two->path);
+ fprintf(stderr, "[] %s -> %s ?\n", dstpair->one->path, dstpair->two->path);
- // FIXME: loop over successive prefixes
- unsigned needs_adding = 1;
+ // loop over successive prefixes
+ // FIXME: also loop over two_parent_path prefixes ?
+ do {
+ unsigned needs_adding = 1;
- /* already considered ? */
- for (seen=bulkmove_candidates; seen; seen = seen->next) {
- if (seen->discarded) {
- /* already seen a rename from seen->one to some than ->two */
- needs_adding = 0;
- continue;
- }
- /* check exact dir */
- if (!strcmp(seen->one->path, one_parent_path)) {
- /* already added */
- needs_adding = 0;
- /* check that seen entry matches this rename */
- if (strcmp(two_parent_path, seen->two->path)) {
- fprintf(stderr, "[DBG] discarding dir %s from bulk moves (split into %s and %s)\n",
- seen->one->path, two_parent_path, seen->two->path);
- // FIXME: may be worth to free it instead
- seen->discarded = 1;
- }
- continue;
- }
- if (!prefixcmp(one_parent_path, seen->one->path)) {
- if (prefixcmp(two_parent_path, seen->two->path)) {
- fprintf(stderr, "[DBG] discarding dir %s from bulk moves (split into %s and %s)\n",
- seen->one->path, two_parent_path, seen->two->path);
- // FIXME: may be worth to free it instead
- seen->discarded = 1;
+ fprintf(stderr, "[[]] %s ...\n", one_parent_path);
+
+ /* already considered ? */
+ for (seen=bulkmove_candidates; seen; seen = seen->next) {
+ if (seen->discarded) {
+ /* already seen a rename from seen->one to some than ->two */
+ needs_adding = 0;
continue;
}
- } else {
- fprintf(stderr, "[DBG] %s considered irrelevant for %s -> %s\n",
- dstpair->one->path, seen->one->path, seen->two->path);
- continue;
+ fprintf(stderr, "[DBG] ? %s -> %s\n", seen->one->path, seen->two->path);
+ /* subdir of "seen" source dir ? */
+ if (!prefixcmp(one_parent_path, seen->one->path)) {
+ /* subdir of "seen" dest dir ? */
+ if (!prefixcmp(two_parent_path, seen->two->path)) {
+ if (!strcmp(seen->one->path, one_parent_path) &&
+ !strcmp(seen->two->path, two_parent_path)) {
+ /* already added */
+ fprintf(stderr, "[DBG] already added\n");
+ needs_adding = 0;
+ } else // confirms
+ fprintf(stderr, "[DBG] 'dstpair' conforts 'seen'\n");
+ } else {
+ fprintf(stderr, "[DBG] discarding %s -> %s from bulk moves (split into %s and %s)\n",
+ seen->one->path, seen->two->path,
+ two_parent_path, seen->two->path);
+ // FIXME: may be worth to free it instead
+ seen->discarded = 1;
+ if (!strcmp(seen->one->path, one_parent_path) &&
+ prefixcmp(seen->two->path, two_parent_path)) {
+ fprintf(stderr, "[DBG] ... and not adding self\n");
+ needs_adding = 0;
+ }
+ continue;
+ }
+ }
+ else fprintf(stderr, "[DBG] 'dstpair' unrelated to 'seen'\n");
+
+ /* dstpair confirms seen, or does not infirm */
+ fprintf(stderr, "[DBG] %s -> %s DOES NOT cause discard of %s -> %s\n",
+ dstpair->one->path, dstpair->two->path,
+ seen->one->path, seen->two->path);
+ }
+ if (needs_adding) { /* record potential dir rename */
+ /* all checks ok, we keep that entry */
+ seen = xmalloc(sizeof(*seen));
+ seen->one = alloc_filespec(one_parent_path);
+ fill_filespec(seen->one, null_sha1, S_IFDIR);
+ seen->two = alloc_filespec(two_parent_path);
+ fill_filespec(seen->two, null_sha1, S_IFDIR);
+ seen->discarded = 0;
+ seen->next = bulkmove_candidates;
+ bulkmove_candidates = seen;
+ fprintf(stderr, "[DBG] %s -> %s suggests possible bulk move from %s to %s\n",
+ dstpair->one->path,
+ dstpair->two->path,
+ one_parent_path, two_parent_path);
}
- /* dstpair confirms seen */
- fprintf(stderr, "[DBG] %s -> %s DOES NOT cause discard of %s -> %s\n",
- dstpair->one->path, dstpair->two->path,
- seen->one->path, seen->two->path);
- }
- if (needs_adding) { /* record potential dir rename */
- /* all checks ok, we keep that entry */
- seen = xmalloc(sizeof(*seen));
- seen->one = alloc_filespec(one_parent_path);
- fill_filespec(seen->one, null_sha1, S_IFDIR);
- seen->two = alloc_filespec(two_parent_path);
- fill_filespec(seen->two, null_sha1, S_IFDIR);
- seen->discarded = 0;
- seen->next = bulkmove_candidates;
- bulkmove_candidates = seen;
- fprintf(stderr, "[DBG] %s -> %s suggests possible bulk move from %s to %s\n",
- dstpair->one->path,
- dstpair->two->path,
- one_parent_path, two_parent_path);
- return;
- }
+ /* next parent if any */
+ copy_dirname(one_parent_path, one_parent_path);
+ } while (*one_parent_path);
}
/*
--
1.7.2.3
next prev parent reply other threads:[~2010-10-14 23:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-14 23:29 [PATCH v6 0/5] Detection of directory renames Yann Dirson
2010-10-14 23:29 ` [PATCH v6 1/5] Introduce bulk-move detection in diffcore Yann Dirson
2010-10-14 23:29 ` [PATCH v6 2/5] Add testcases for the --detect-bulk-moves diffcore flag Yann Dirson
2010-10-14 23:29 ` [PATCH v6 3/5] [RFC] Handle the simpler case of a subdir invalidating bulk move Yann Dirson
2010-10-14 23:29 ` Yann Dirson [this message]
2010-10-14 23:29 ` [PATCH v6 5/5] [WIP] Allow hiding renames of individual files involved in a directory rename Yann Dirson
2010-10-17 19:24 ` [PATCH v6.1] [RFC] Consider all parents of a file as candidates for bulk rename Yann Dirson
2010-10-15 5:17 ` [PATCH] compat: add memrchr() Jonathan Nieder
2010-10-15 5:31 ` Ævar Arnfjörð Bjarmason
2010-10-15 6:06 ` Jonathan Nieder
2010-10-15 10:49 ` Ævar Arnfjörð Bjarmason
2010-10-15 22:27 ` Junio C Hamano
2010-10-15 6:57 ` Johannes Sixt
2010-10-15 8:56 ` Ludvig Strigeus
2010-10-15 15:26 ` [PATCH v2] " Jonathan Nieder
2010-10-15 8:56 ` [PATCH] " Erik Faye-Lund
2010-10-15 9:35 ` Johannes Sixt
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287098999-9244-5-git-send-email-ydirson@altern.org \
--to=ydirson@altern.org \
--cc=git@vger.kernel.org \
--cc=ydirson@free.fr \
/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.
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).