[PATCH] Detect renames in diff family.

This rips out the rename detection engine from diff-helper and moves it
to the diff core, and updates the internal calling convention used by
diff-tree family into the diff core.  In order to give the same option
name to diff-tree family as well as to diff-helper, I've changed the
earlier diff-helper '-r' option to '-M' (stands for Move; sorry but the
natural abbreviation 'r' for 'rename' is already taken for 'recursive').

Although I did a fair amount of test with the git-diff-tree with
existing rename commits in the core GIT repository, this should still be
considered beta (preview) release.  This patch depends on the diff-delta
infrastructure just committed.

This implements almost everything I wanted to see in this series of
patch, except a few minor cleanups in the calling convention into diff
core, but that will be a separate cleanup patch.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Junio C Hamano
2005-05-19 03:32:35 -07:00
committed by Linus Torvalds
parent a310d43494
commit 5c97558c9a
12 changed files with 534 additions and 240 deletions

View File

@ -5,6 +5,7 @@ static int cached_only = 0;
static int generate_patch = 0;
static int match_nonexisting = 0;
static int line_termination = '\n';
static int detect_rename = 0;
/* A file entry went away or appeared */
static void show_file(const char *prefix, struct cache_entry *ce, unsigned char *sha1, unsigned int mode)
@ -165,13 +166,14 @@ static void mark_merge_entries(void)
}
static char *diff_cache_usage =
"git-diff-cache [-p] [-r] [-z] [-m] [--cached] <tree sha1>";
"git-diff-cache [-p] [-r] [-z] [-m] [-M] [--cached] <tree-ish>";
int main(int argc, char **argv)
{
unsigned char tree_sha1[20];
void *tree;
unsigned long size;
int ret;
read_cache();
while (argc > 2) {
@ -186,6 +188,10 @@ int main(int argc, char **argv)
generate_patch = 1;
continue;
}
if (!strcmp(arg, "-M")) {
generate_patch = detect_rename = 1;
continue;
}
if (!strcmp(arg, "-z")) {
line_termination = '\0';
continue;
@ -204,6 +210,9 @@ int main(int argc, char **argv)
if (argc != 2 || get_sha1(argv[1], tree_sha1))
usage(diff_cache_usage);
if (generate_patch)
diff_setup(detect_rename, 0, 0, 0, 0);
mark_merge_entries();
tree = read_object_with_reference(tree_sha1, "tree", &size, 0);
@ -212,5 +221,8 @@ int main(int argc, char **argv)
if (read_tree(tree, size, 1))
die("unable to read tree object %s", argv[1]);
return diff_cache(active_cache, active_nr);
ret = diff_cache(active_cache, active_nr);
if (generate_patch)
diff_flush();
return ret;
}