From a64dd34d8cce018742badb49b87c5c565be655ce Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 28 Feb 2006 20:19:47 -0800 Subject: diffcore-break: micro-optimize by avoiding delta between identical files. We did not check if we have the same file on both sides when computing break score. This is usually not a problem, but if the user said --find-copies-harde with -B, we ended up trying a delta between the same data even when we know the SHA1 hash of both sides match. Signed-off-by: Junio C Hamano (cherry picked from aeecd23ae2785a0462d42191974e9d9a8e439fbe commit) diff --git a/diffcore-break.c b/diffcore-break.c index c57513a..95b5eb4 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -58,6 +58,10 @@ static int should_break(struct diff_filespec *src, if (!S_ISREG(src->mode) || !S_ISREG(dst->mode)) return 0; /* leave symlink rename alone */ + if (src->sha1_valid && dst->sha1_valid && + !memcmp(src->sha1, dst->sha1, 20)) + return 0; /* they are the same */ + if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0)) return 0; /* error but caught downstream */ -- cgit v0.10.2-6-g49f6 From b9003c06a89a6d78255bb837c921ca03ee27fae6 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 27 Feb 2006 12:52:50 +0000 Subject: combine-diff: Honour --full-index. For some reason, combined diffs don't honour the --full-index flag when emitting patches. Fix this. Signed-off-by: Mark Wooding Signed-off-by: Junio C Hamano (cherry picked from e70c6b35749c316f6e97099bd6bdac895c9d6f68 commit) diff --git a/combine-diff.c b/combine-diff.c index d812600..984103e 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -621,7 +621,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt, } static int show_patch_diff(struct combine_diff_path *elem, int num_parent, - int dense, const char *header) + int dense, const char *header, + struct diff_options *opt) { unsigned long size, cnt, lno; char *result, *cp, *ep; @@ -631,6 +632,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, char ourtmp_buf[TMPPATHLEN]; char *ourtmp = ourtmp_buf; int working_tree_file = !memcmp(elem->sha1, null_sha1, 20); + int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV; /* Read the result of merge first */ if (!working_tree_file) { @@ -735,10 +737,10 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, printf("index "); for (i = 0; i < num_parent; i++) { abb = find_unique_abbrev(elem->parent[i].sha1, - DEFAULT_ABBREV); + abbrev); printf("%s%s", i ? "," : "", abb); } - abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV); + abb = find_unique_abbrev(elem->sha1, abbrev); printf("..%s\n", abb); if (mode_differs) { @@ -862,7 +864,7 @@ int show_combined_diff(struct combine_diff_path *p, default: case DIFF_FORMAT_PATCH: - return show_patch_diff(p, num_parent, dense, header); + return show_patch_diff(p, num_parent, dense, header, opt); } } -- cgit v0.10.2-6-g49f6 From feffaddce0cec7fd3f749d23e95579b683961002 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 27 Feb 2006 12:52:52 +0000 Subject: combine-diff: Honour -z option correctly. Combined diffs don't null terminate things in the same way as standard diffs. This is presumably wrong. Signed-off-by: Mark Wooding Signed-off-by: Junio C Hamano (cherry picked from 6baf0484efcd29bb5e58ccd5ea0379481d4a83f4 commit) diff --git a/combine-diff.c b/combine-diff.c index 984103e..a23894d 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -726,7 +726,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, if (header) { shown_header++; - puts(header); + printf("%s%c", header, opt->line_termination); } printf("diff --%s ", dense ? "cc" : "combined"); if (quote_c_style(elem->path, NULL, NULL, 0)) @@ -799,7 +799,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha inter_name_termination = 0; if (header) - puts(header); + printf("%s%c", header, line_termination); for (i = 0; i < num_parent; i++) { if (p->parent[i].mode) -- cgit v0.10.2-6-g49f6 From 573464319f70bd54a7c48cfd7bed6a0f6f331f42 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 18 Feb 2006 23:42:03 -0800 Subject: Allow git-mv to accept ./ in paths. Signed-off-by: Junio C Hamano (cherry picked from 9a0e6731c632c841cd2de9dec0b9091b2f10c6fd commit) diff --git a/git-mv.perl b/git-mv.perl index 83dc7e4..2ea852c 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -75,6 +75,15 @@ while(scalar @srcArgs > 0) { $dst = shift @dstArgs; $bad = ""; + for ($src, $dst) { + # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" + s|^\./||; + s|/\./|/| while (m|/\./|); + s|//+|/|g; + # Also "a/b/../c" ==> "a/c" + 1 while (s,(^|/)[^/]+/\.\./,$1,); + } + if ($opt_v) { print "Checking rename of '$src' to '$dst'\n"; } -- cgit v0.10.2-6-g49f6 From 5e6f85f6c1d988d125dfcba16bb43a9a65f9eab3 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Wed, 1 Mar 2006 18:16:36 +0100 Subject: git-mv: Allow -h without repo & fix error message This fixes "git-mv -h" to output the usage without the need to be in a git repository. Additionally: - fix confusing error message when only one arg was given - fix typo in error message Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano diff --git a/git-mv.perl b/git-mv.perl index 2ea852c..8cd95c4 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -19,15 +19,15 @@ EOT exit(1); } -my $GIT_DIR = `git rev-parse --git-dir`; -exit 1 if $?; # rev-parse would have given "not a git dir" message. -chomp($GIT_DIR); - our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v); getopts("hnfkv") || usage; usage() if $opt_h; @ARGV >= 1 or usage; +my $GIT_DIR = `git rev-parse --git-dir`; +exit 1 if $?; # rev-parse would have given "not a git dir" message. +chomp($GIT_DIR); + my (@srcArgs, @dstArgs, @srcs, @dsts); my ($src, $dst, $base, $dstDir); @@ -46,10 +46,14 @@ if (-d $ARGV[$argCount-1]) { } } else { - if ($argCount != 2) { + if ($argCount < 2) { + print "Error: need at least two arguments\n"; + exit(1); + } + if ($argCount > 2) { print "Error: moving to directory '" . $ARGV[$argCount-1] - . "' not possible; not exisiting\n"; + . "' not possible; not existing\n"; exit(1); } @srcArgs = ($ARGV[0]); -- cgit v0.10.2-6-g49f6 From 9e7c73de0bcd410d12f897b19419dd35accd961e Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Wed, 1 Mar 2006 19:09:23 +0100 Subject: git-mv: fixes for path handling Moving a directory ending in a slash was not working as the destination was not calculated correctly. E.g. in the git repo, git-mv t/ Documentation gave the error Error: destination 'Documentation' already exists To get rid of this problem, strip trailing slashes from all arguments. The comment in cg-mv made me curious about this issue; Pasky, thanks! As result, the workaround in cg-mv is not needed any more. Also, another bug was shown by cg-mv. When moving files outside of a subdirectory, it typically calls git-mv with something like git-mv Documentation/git.txt Documentation/../git-mv.txt which triggers the following error from git-update-index: Ignoring path Documentation/../git-mv.txt The result is a moved file, removed from git revisioning, but not added again. To fix this, the paths have to be normalized not have ".." in the middle. This was already done in git-mv, but only for a better visual appearance :( Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano diff --git a/git-mv.perl b/git-mv.perl index 8cd95c4..f3e859a 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -31,13 +31,14 @@ chomp($GIT_DIR); my (@srcArgs, @dstArgs, @srcs, @dsts); my ($src, $dst, $base, $dstDir); +# remove any trailing slash in arguments +for (@ARGV) { s/\/*$//; } + my $argCount = scalar @ARGV; if (-d $ARGV[$argCount-1]) { $dstDir = $ARGV[$argCount-1]; - # remove any trailing slash - $dstDir =~ s/\/$//; @srcArgs = @ARGV[0..$argCount-2]; - + foreach $src (@srcArgs) { $base = $src; $base =~ s/^.*\///; @@ -61,6 +62,16 @@ else { $dstDir = ""; } +# normalize paths, needed to compare against versioned files and update-index +# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" +for (@srcArgs, @dstArgs) { + s|^\./||; + s|/\./|/| while (m|/\./|); + s|//+|/|g; + # Also "a/b/../c" ==> "a/c" + 1 while (s,(^|/)[^/]+/\.\./,$1,); +} + my (@allfiles,@srcfiles,@dstfiles); my $safesrc; my (%overwritten, %srcForDst); @@ -79,15 +90,6 @@ while(scalar @srcArgs > 0) { $dst = shift @dstArgs; $bad = ""; - for ($src, $dst) { - # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" - s|^\./||; - s|/\./|/| while (m|/\./|); - s|//+|/|g; - # Also "a/b/../c" ==> "a/c" - 1 while (s,(^|/)[^/]+/\.\./,$1,); - } - if ($opt_v) { print "Checking rename of '$src' to '$dst'\n"; } -- cgit v0.10.2-6-g49f6