Skip to content

Commit 80b1e51

Browse files
author
Junio C Hamano
committed
diff: --full-index
A new option, --full-index, is introduced to diff family. This causes the full object name of pre- and post-images to appear on the index line of patch formatted output, to be used in conjunction with --allow-binary-replacement option of git-apply. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 011f427 commit 80b1e51

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Documentation/diff-options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
--name-status::
1414
Show only names and status of changed files.
1515

16+
--full-index::
17+
Instead of the first handful characters, show full
18+
object name of pre- and post-image blob on the "index"
19+
line when generating a patch format output.
20+
1621
-B::
1722
Break complete rewrite changes into pairs of delete and create.
1823

diff.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
650650
memset(one->sha1, 0, 20);
651651
}
652652

653-
static void run_diff(struct diff_filepair *p)
653+
static void run_diff(struct diff_filepair *p, struct diff_options *o)
654654
{
655655
const char *pgm = external_diff();
656656
char msg[PATH_MAX*2+300], *xfrm_msg;
@@ -713,11 +713,11 @@ static void run_diff(struct diff_filepair *p)
713713

714714
if (memcmp(one->sha1, two->sha1, 20)) {
715715
char one_sha1[41];
716+
const char *index_fmt = o->full_index ? "index %s..%s" : "index %.7s..%.7s";
716717
memcpy(one_sha1, sha1_to_hex(one->sha1), 41);
717718

718719
len += snprintf(msg + len, sizeof(msg) - len,
719-
"index %.7s..%.7s", one_sha1,
720-
sha1_to_hex(two->sha1));
720+
index_fmt, one_sha1, sha1_to_hex(two->sha1));
721721
if (one->mode == two->mode)
722722
len += snprintf(msg + len, sizeof(msg) - len,
723723
" %06o", one->mode);
@@ -794,6 +794,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
794794
options->line_termination = 0;
795795
else if (!strncmp(arg, "-l", 2))
796796
options->rename_limit = strtoul(arg+2, NULL, 10);
797+
else if (!strcmp(arg, "--full-index"))
798+
options->full_index = 1;
797799
else if (!strcmp(arg, "--name-only"))
798800
options->output_format = DIFF_FORMAT_NAME;
799801
else if (!strcmp(arg, "--name-status"))
@@ -1022,7 +1024,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
10221024
return 0;
10231025
}
10241026

1025-
static void diff_flush_patch(struct diff_filepair *p)
1027+
static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o)
10261028
{
10271029
if (diff_unmodified_pair(p))
10281030
return;
@@ -1031,7 +1033,7 @@ static void diff_flush_patch(struct diff_filepair *p)
10311033
(DIFF_FILE_VALID(p->two) && S_ISDIR(p->two->mode)))
10321034
return; /* no tree diffs in patch format */
10331035

1034-
run_diff(p);
1036+
run_diff(p, o);
10351037
}
10361038

10371039
int diff_queue_is_empty(void)
@@ -1163,7 +1165,7 @@ void diff_flush(struct diff_options *options)
11631165
die("internal error in diff-resolve-rename-copy");
11641166
switch (diff_output_format) {
11651167
case DIFF_FORMAT_PATCH:
1166-
diff_flush_patch(p);
1168+
diff_flush_patch(p, options);
11671169
break;
11681170
case DIFF_FORMAT_RAW:
11691171
case DIFF_FORMAT_NAME_STATUS:

diff.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct diff_options {
3232
const char *orderfile;
3333
const char *pickaxe;
3434
unsigned recursive:1,
35-
tree_in_recursive:1;
35+
tree_in_recursive:1,
36+
full_index:1;
3637
int break_opt;
3738
int detect_rename;
3839
int find_copies_harder;
@@ -96,6 +97,7 @@ extern void diffcore_std_no_resolve(struct diff_options *);
9697
" -u synonym for -p.\n" \
9798
" --name-only show only names of changed files.\n" \
9899
" --name-status show names and status of changed files.\n" \
100+
" --full-index show full object name on index ines.\n" \
99101
" -R swap input file pairs.\n" \
100102
" -B detect complete rewrites.\n" \
101103
" -M detect renames.\n" \

0 commit comments

Comments
 (0)