Skip to content

Commit c89606f

Browse files
committed
Merge branch 'jb/diff-no-index-no-abbrev'
"git diff --no-index" did not take "--no-abbrev" option. * jb/diff-no-index-no-abbrev: diff: handle --no-abbrev in no-index case
2 parents 0a45050 + 43d1948 commit c89606f

8 files changed

Lines changed: 39 additions & 1 deletion

diff.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,8 @@ static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
31063106
abbrev = FALLBACK_DEFAULT_ABBREV;
31073107
if (abbrev > GIT_SHA1_HEXSZ)
31083108
die("BUG: oid abbreviation out of range: %d", abbrev);
3109-
hex[abbrev] = '\0';
3109+
if (abbrev)
3110+
hex[abbrev] = '\0';
31103111
return hex;
31113112
}
31123113
}
@@ -3364,6 +3365,7 @@ void diff_setup(struct diff_options *options)
33643365

33653366
options->file = stdout;
33663367

3368+
options->abbrev = DEFAULT_ABBREV;
33673369
options->line_termination = '\n';
33683370
options->break_opt = -1;
33693371
options->rename_limit = -1;
@@ -4024,6 +4026,8 @@ int diff_opt_parse(struct diff_options *options,
40244026
offending, optarg);
40254027
return argcount;
40264028
}
4029+
else if (!strcmp(arg, "--no-abbrev"))
4030+
options->abbrev = 0;
40274031
else if (!strcmp(arg, "--abbrev"))
40284032
options->abbrev = DEFAULT_ABBREV;
40294033
else if (skip_prefix(arg, "--abbrev=", &arg)) {

t/t4013-diff-various.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ diff --line-prefix=abc master master^ side
311311
diff --dirstat master~1 master~2
312312
diff --dirstat initial rearrange
313313
diff --dirstat-by-file initial rearrange
314+
# No-index --abbrev and --no-abbrev
315+
diff --raw initial
316+
diff --raw --abbrev=4 initial
317+
diff --raw --no-abbrev initial
318+
diff --no-index --raw dir2 dir
319+
diff --no-index --raw --abbrev=4 dir2 dir
320+
diff --no-index --raw --no-abbrev dir2 dir
314321
EOF
315322

316323
test_expect_success 'log -S requires an argument' '
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ git diff --no-index --raw --abbrev=4 dir2 dir
2+
:000000 100644 0000... 0000... A dir/sub
3+
$
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ git diff --no-index --raw --no-abbrev dir2 dir
2+
:000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A dir/sub
3+
$
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ git diff --no-index --raw dir2 dir
2+
:000000 100644 0000000... 0000000... A dir/sub
3+
$
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$ git diff --raw --abbrev=4 initial
2+
:100644 100644 35d2... 9929... M dir/sub
3+
:100644 100644 01e7... 10a8... M file0
4+
:000000 100644 0000... b1e6... A file1
5+
:100644 000000 01e7... 0000... D file2
6+
$
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$ git diff --raw --no-abbrev initial
2+
:100644 100644 35d242ba79ae89ac695e26b3d4c27a8e6f028f9e 992913c5aa0a5476d10c49ed0f21fc0c6d1aedf3 M dir/sub
3+
:100644 100644 01e79c32a8c99c557f0757da7cb6d65b3414466d 10a8a9f3657f91a156b9f0184ed79a20adef9f7f M file0
4+
:000000 100644 0000000000000000000000000000000000000000 b1e67221afe8461efd244b487afca22d46b95eb8 A file1
5+
:100644 000000 01e79c32a8c99c557f0757da7cb6d65b3414466d 0000000000000000000000000000000000000000 D file2
6+
$

t/t4013/diff.diff_--raw_initial

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$ git diff --raw initial
2+
:100644 100644 35d242b... 992913c... M dir/sub
3+
:100644 100644 01e79c3... 10a8a9f... M file0
4+
:000000 100644 0000000... b1e6722... A file1
5+
:100644 000000 01e79c3... 0000000... D file2
6+
$

0 commit comments

Comments
 (0)