Skip to content

Commit 096c948

Browse files
committed
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
2 parents 1a75372 + 3046c7f commit 096c948

6 files changed

+138
-26
lines changed

Documentation/diff-options.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,11 @@ endif::git-format-patch[]
446446
--abbrev[=<n>]::
447447
Instead of showing the full 40-byte hexadecimal object
448448
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>`.
453454

454455
-B[<n>][/<m>]::
455456
--break-rewrites[=[<n>][/<m>]]::

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,10 @@ static void fill_metainfo(struct strbuf *msg,
43194319
}
43204320
if (one && two && !oideq(&one->oid, &two->oid)) {
43214321
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;
43234326

43244327
if (o->flags.binary) {
43254328
mmfile_t mf;

t/t4013-diff-various.sh

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,45 @@ test_expect_success setup '
130130
EOF
131131

132132
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"
154172
}
155173

156174
V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
@@ -221,6 +239,9 @@ diff-tree --root -r --abbrev=4 initial
221239
:noellipses diff-tree --root -r --abbrev=4 initial
222240
diff-tree -p initial
223241
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
224245
diff-tree --patch-with-stat initial
225246
diff-tree --root --patch-with-stat initial
226247
diff-tree --patch-with-raw initial
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
$
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
$
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
$

0 commit comments

Comments
 (0)