Skip to content

Commit

Permalink
[PATCH] Detect renames in diff family.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano authored and Linus Torvalds committed May 19, 2005
1 parent a310d43 commit 5c97558
Show file tree
Hide file tree
Showing 12 changed files with 533 additions and 239 deletions.
5 changes: 4 additions & 1 deletion Documentation/git-diff-cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-diff-cache - Compares content and mode of blobs between the cache and reposi

SYNOPSIS
--------
'git-diff-cache' [-p] [-r] [-z] [-m] [--cached] <tree-ish>
'git-diff-cache' [-p] [-r] [-z] [-m] [-M] [--cached] <tree-ish>

DESCRIPTION
-----------
Expand All @@ -33,6 +33,9 @@ OPTIONS
-z::
\0 line termination on output

-M::
Detect renames; implies -p.

--cached::
do not consider the on-disk file at all

Expand Down
5 changes: 4 additions & 1 deletion Documentation/git-diff-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-diff-files - Compares files in the working tree and the cache

SYNOPSIS
--------
'git-diff-files' [-p] [-q] [-r] [-z] [<pattern>...]
'git-diff-files' [-p] [-q] [-r] [-z] [-M] [<pattern>...]

DESCRIPTION
-----------
Expand All @@ -26,6 +26,9 @@ OPTIONS
-q::
Remain silent even on nonexisting files

-M::
Detect renames; implies -p.

-r::
This flag does not mean anything. It is there only to match
git-diff-tree. Unlike git-diff-tree, git-diff-files always looks
Expand Down
4 changes: 2 additions & 2 deletions Documentation/git-diff-helper.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-diff-helper - Generates patch format output for git-diff-*

SYNOPSIS
--------
'git-diff-helper' [-z] [-R] [-r]
'git-diff-helper' [-z] [-R] [-M]

DESCRIPTION
-----------
Expand All @@ -31,7 +31,7 @@ OPTIONS
would show a diff to bring the working file back to what
is in the <tree>.

-r::
-M::
Detect renames.


Expand Down
5 changes: 4 additions & 1 deletion Documentation/git-diff-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-diff-tree - Compares the content and mode of blobs found via two tree object

SYNOPSIS
--------
'git-diff-tree' [-p] [-r] [-z] [--stdin] [-m] [-s] [-v] <tree-ish> <tree-ish> [<pattern>]\*
'git-diff-tree' [-p] [-r] [-z] [--stdin] [-M] [-m] [-s] [-v] <tree-ish> <tree-ish> [<pattern>]\*

DESCRIPTION
-----------
Expand All @@ -33,6 +33,9 @@ OPTIONS
generate patch (see section on generating patches). For
git-diff-tree, this flag implies '-r' as well.

-M::
Detect renames; implies -p, in turn implying also '-r'.

-r::
recurse

Expand Down
16 changes: 14 additions & 2 deletions diff-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
11 changes: 10 additions & 1 deletion diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "diff.h"

static const char *diff_files_usage =
"diff-files [-p] [-q] [-r] [-z] [paths...]";
"diff-files [-p] [-q] [-r] [-z] [-M] [paths...]";

static int generate_patch = 0;
static int line_termination = '\n';
static int detect_rename = 0;
static int silent = 0;

static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
Expand Down Expand Up @@ -79,6 +80,9 @@ int main(int argc, char **argv)
; /* no-op */
else if (!strcmp(argv[1], "-z"))
line_termination = 0;
else if (!strcmp(argv[1], "-M")) {
detect_rename = generate_patch = 1;
}
else
usage(diff_files_usage);
argv++; argc--;
Expand All @@ -92,6 +96,9 @@ int main(int argc, char **argv)
exit(1);
}

if (generate_patch)
diff_setup(detect_rename, 0, 0, 0, 0);

for (i = 0; i < entries; i++) {
struct stat st;
unsigned int oldmode, mode;
Expand Down Expand Up @@ -132,5 +139,7 @@ int main(int argc, char **argv)
show_modified(oldmode, mode, ce->sha1, null_sha1,
ce->name);
}
if (generate_patch)
diff_flush();
return 0;
}
Loading

0 comments on commit 5c97558

Please sign in to comment.