Git fork

Merge branch 'dd/diff-customize-index-line-abbrev'

The output from the "diff" family of the commands had abbreviated
object names of blobs involved in the patch, but its length was not
affected by the --abbrev option. Now it is.

* dd/diff-customize-index-line-abbrev:
diff: index-line: respect --abbrev in object's name
t4013: improve diff-post-processor logic

+138 -26
+5 -4
Documentation/diff-options.txt
··· 446 446 --abbrev[=<n>]:: 447 447 Instead of showing the full 40-byte hexadecimal object 448 448 name in diff-raw format output and diff-tree header 449 - lines, show only a partial prefix. This is 450 - independent of the `--full-index` option above, which controls 451 - the diff-patch output format. Non default number of 452 - digits can be specified with `--abbrev=<n>`. 449 + lines, show only a partial prefix. 450 + In diff-patch output format, `--full-index` takes higher 451 + precedence, i.e. if `--full-index` is specified, full blob 452 + names will be shown regardless of `--abbrev`. 453 + Non default number of digits can be specified with `--abbrev=<n>`. 453 454 454 455 -B[<n>][/<m>]:: 455 456 --break-rewrites[=[<n>][/<m>]]::
+4 -1
diff.c
··· 4319 4319 } 4320 4320 if (one && two && !oideq(&one->oid, &two->oid)) { 4321 4321 const unsigned hexsz = the_hash_algo->hexsz; 4322 - int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV; 4322 + int abbrev = o->abbrev ? o->abbrev : DEFAULT_ABBREV; 4323 + 4324 + if (o->flags.full_index) 4325 + abbrev = hexsz; 4323 4326 4324 4327 if (o->flags.binary) { 4325 4328 mmfile_t mf;
+42 -21
t/t4013-diff-various.sh
··· 130 130 EOF 131 131 132 132 process_diffs () { 133 - _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" && 134 - _x07="$_x05[0-9a-f][0-9a-f]" && 135 - sed -e "s/$OID_REGEX/$ZERO_OID/g" \ 136 - -e "s/From $_x40 /From $ZERO_OID /" \ 137 - -e "s/from $_x40)/from $ZERO_OID)/" \ 138 - -e "s/commit $_x40\$/commit $ZERO_OID/" \ 139 - -e "s/commit $_x40 (/commit $ZERO_OID (/" \ 140 - -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \ 141 - -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \ 142 - -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \ 143 - -e "s/^$_x40 /$ZERO_OID /" \ 144 - -e "s/^$_x40$/$ZERO_OID/" \ 145 - -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \ 146 - -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \ 147 - -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \ 148 - -e "s/$_x07 $_x07 /fffffff fffffff /g" \ 149 - -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \ 150 - -e "s/$_x07\.\.\./fffffff.../g" \ 151 - -e "s/ $_x04\.\.\./ ffff.../g" \ 152 - -e "s/ $_x04/ ffff/g" \ 153 - "$1" 133 + perl -e ' 134 + my $oid_length = length($ARGV[0]); 135 + my $x40 = "[0-9a-f]{40}"; 136 + my $xab = "[0-9a-f]{4,16}"; 137 + my $orx = "[0-9a-f]" x $oid_length; 138 + 139 + sub munge_oid { 140 + my ($oid) = @_; 141 + my $x; 142 + 143 + return "" unless length $oid; 144 + 145 + if ($oid =~ /^(100644|100755|120000)$/) { 146 + return $oid; 147 + } 148 + 149 + if ($oid =~ /^0*$/) { 150 + $x = "0"; 151 + } else { 152 + $x = "f"; 153 + } 154 + 155 + if (length($oid) == 40) { 156 + return $x x $oid_length; 157 + } else { 158 + return $x x length($oid); 159 + } 160 + } 161 + 162 + while (<STDIN>) { 163 + s/($orx)/munge_oid($1)/ge; 164 + s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge; 165 + s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge; 166 + s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge; 167 + s/^($x40)($| )/munge_oid($1) . $2/e; 168 + s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge; 169 + print; 170 + } 171 + ' "$ZERO_OID" <"$1" 154 172 } 155 173 156 174 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') ··· 221 239 :noellipses diff-tree --root -r --abbrev=4 initial 222 240 diff-tree -p initial 223 241 diff-tree --root -p initial 242 + diff-tree --root -p --abbrev=10 initial 243 + diff-tree --root -p --full-index initial 244 + diff-tree --root -p --full-index --abbrev=10 initial 224 245 diff-tree --patch-with-stat initial 225 246 diff-tree --root --patch-with-stat initial 226 247 diff-tree --patch-with-raw initial
+29
t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial
··· 1 + $ git diff-tree --root -p --abbrev=10 initial 2 + 444ac553ac7612cc88969031b02b3767fb8a353a 3 + diff --git a/dir/sub b/dir/sub 4 + new file mode 100644 5 + index 0000000000..35d242ba79 6 + --- /dev/null 7 + +++ b/dir/sub 8 + @@ -0,0 +1,2 @@ 9 + +A 10 + +B 11 + diff --git a/file0 b/file0 12 + new file mode 100644 13 + index 0000000000..01e79c32a8 14 + --- /dev/null 15 + +++ b/file0 16 + @@ -0,0 +1,3 @@ 17 + +1 18 + +2 19 + +3 20 + diff --git a/file2 b/file2 21 + new file mode 100644 22 + index 0000000000..01e79c32a8 23 + --- /dev/null 24 + +++ b/file2 25 + @@ -0,0 +1,3 @@ 26 + +1 27 + +2 28 + +3 29 + $
+29
t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial
··· 1 + $ git diff-tree --root -p --full-index --abbrev=10 initial 2 + 444ac553ac7612cc88969031b02b3767fb8a353a 3 + diff --git a/dir/sub b/dir/sub 4 + new file mode 100644 5 + index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e 6 + --- /dev/null 7 + +++ b/dir/sub 8 + @@ -0,0 +1,2 @@ 9 + +A 10 + +B 11 + diff --git a/file0 b/file0 12 + new file mode 100644 13 + index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d 14 + --- /dev/null 15 + +++ b/file0 16 + @@ -0,0 +1,3 @@ 17 + +1 18 + +2 19 + +3 20 + diff --git a/file2 b/file2 21 + new file mode 100644 22 + index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d 23 + --- /dev/null 24 + +++ b/file2 25 + @@ -0,0 +1,3 @@ 26 + +1 27 + +2 28 + +3 29 + $
+29
t/t4013/diff.diff-tree_--root_-p_--full-index_initial
··· 1 + $ git diff-tree --root -p --full-index initial 2 + 444ac553ac7612cc88969031b02b3767fb8a353a 3 + diff --git a/dir/sub b/dir/sub 4 + new file mode 100644 5 + index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e 6 + --- /dev/null 7 + +++ b/dir/sub 8 + @@ -0,0 +1,2 @@ 9 + +A 10 + +B 11 + diff --git a/file0 b/file0 12 + new file mode 100644 13 + index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d 14 + --- /dev/null 15 + +++ b/file0 16 + @@ -0,0 +1,3 @@ 17 + +1 18 + +2 19 + +3 20 + diff --git a/file2 b/file2 21 + new file mode 100644 22 + index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d 23 + --- /dev/null 24 + +++ b/file2 25 + @@ -0,0 +1,3 @@ 26 + +1 27 + +2 28 + +3 29 + $