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>
Junio C Hamano committed
Nov 14, 2005 at 17:53 UTC
80b1e511d74ac2942043f912d850cb6b85b44689
3 files changed
+16
-7
Documentation/diff-options.txt
+5
@@ -13,6 +13,11 @@
13
--name-status::
14
Show only names and status of changed files.
15
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
+
21
-B::
22
Break complete rewrite changes into pairs of delete and create.
23
diff.c
+8
-6
@@ -650,7 +650,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
650
memset(one->sha1, 0, 20);
651
}
652
653
-static void run_diff(struct diff_filepair *p)
653
+static void run_diff(struct diff_filepair *p, struct diff_options *o)
654
{
655
const char *pgm = external_diff();
656
char msg[PATH_MAX*2+300], *xfrm_msg;
@@ -713,11 +713,11 @@ static void run_diff(struct diff_filepair *p)
713
714
if (memcmp(one->sha1, two->sha1, 20)) {
715
char one_sha1[41];
716
+ const char *index_fmt = o->full_index ? "index %s..%s" : "index %.7s..%.7s";
717
memcpy(one_sha1, sha1_to_hex(one->sha1), 41);
718
719
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));
721
if (one->mode == two->mode)
722
len += snprintf(msg + len, sizeof(msg) - len,
723
" %06o", one->mode);
@@ -794,6 +794,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
794
options->line_termination = 0;
795
else if (!strncmp(arg, "-l", 2))
796
options->rename_limit = strtoul(arg+2, NULL, 10);
797
+ else if (!strcmp(arg, "--full-index"))
798
+ options->full_index = 1;
799
else if (!strcmp(arg, "--name-only"))
800
options->output_format = DIFF_FORMAT_NAME;
801
else if (!strcmp(arg, "--name-status"))
@@ -1022,7 +1024,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
1024
return 0;
1025
}
1026
1025
-static void diff_flush_patch(struct diff_filepair *p)
1027
+static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o)
1028
{
1029
if (diff_unmodified_pair(p))
1030
return;
@@ -1031,7 +1033,7 @@ static void diff_flush_patch(struct diff_filepair *p)
1033
(DIFF_FILE_VALID(p->two) && S_ISDIR(p->two->mode)))
1034
return; /* no tree diffs in patch format */
1035
1034
- run_diff(p);
1036
+ run_diff(p, o);
1037
}
1038
1039
int diff_queue_is_empty(void)
@@ -1163,7 +1165,7 @@ void diff_flush(struct diff_options *options)
1165
die("internal error in diff-resolve-rename-copy");
1166
switch (diff_output_format) {
1167
case DIFF_FORMAT_PATCH:
1166
- diff_flush_patch(p);
1168
+ diff_flush_patch(p, options);
1169
break;
1170
case DIFF_FORMAT_RAW:
1171
case DIFF_FORMAT_NAME_STATUS:
diff.h
+3
-1
@@ -32,7 +32,8 @@ struct diff_options {
32
const char *orderfile;
33
const char *pickaxe;
34
unsigned recursive:1,
35
- tree_in_recursive:1;
35
+ tree_in_recursive:1,
36
+ full_index:1;
37
int break_opt;
38
int detect_rename;
39
int find_copies_harder;
@@ -96,6 +97,7 @@ extern void diffcore_std_no_resolve(struct diff_options *);
97
" -u synonym for -p.\n" \
98
" --name-only show only names of changed files.\n" \
99
" --name-status show names and status of changed files.\n" \
100
+" --full-index show full object name on index ines.\n" \
101
" -R swap input file pairs.\n" \
102
" -B detect complete rewrites.\n" \
103
" -M detect renames.\n" \