Skip to content

Commit 34e98ea

Browse files
author
Junio C Hamano
committed
Merge branch 'lt/logopt'
* lt/logopt: Fix "git log --stat": make sure to set recursive with --stat. combine-diff: show diffstat with the first parent. git.c: LOGSIZE is unused after log printing cleanup. Log message printout cleanups (#3): fix --pretty=oneline Log message printout cleanups (#2) Log message printout cleanups rev-list --header: output format fix Fixes for option parsing log/whatchanged/show - log formatting cleanup. Simplify common default options setup for built-in log family. Tentative built-in "git show" Built-in git-whatchanged. rev-list option parser fix. Split init_revisions() out of setup_revisions() Fix up rev-list option parsing. Fix up default abbrev in setup_revisions() argument parser. Common option parsing for "git log --diff" and friends
2 parents 4baff50 + 3a624b3 commit 34e98ea

File tree

14 files changed

+472
-437
lines changed

14 files changed

+472
-437
lines changed

combine-diff.c

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "diffcore.h"
66
#include "quote.h"
77
#include "xdiff-interface.h"
8+
#include "log-tree.h"
89

910
static int uninteresting(struct diff_filepair *p)
1011
{
@@ -584,10 +585,20 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
584585
sline->p_lno[i] = sline->p_lno[j];
585586
}
586587

588+
static void dump_quoted_path(const char *prefix, const char *path)
589+
{
590+
fputs(prefix, stdout);
591+
if (quote_c_style(path, NULL, NULL, 0))
592+
quote_c_style(path, NULL, stdout, 0);
593+
else
594+
printf("%s", path);
595+
putchar('\n');
596+
}
597+
587598
static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
588-
int dense, const char *header,
589-
struct diff_options *opt)
599+
int dense, struct rev_info *rev)
590600
{
601+
struct diff_options *opt = &rev->diffopt;
591602
unsigned long result_size, cnt, lno;
592603
char *result, *cp;
593604
struct sline *sline; /* survived lines */
@@ -688,16 +699,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
688699
if (show_hunks || mode_differs || working_tree_file) {
689700
const char *abb;
690701

691-
if (header) {
692-
shown_header++;
693-
printf("%s%c", header, opt->line_termination);
694-
}
695-
printf("diff --%s ", dense ? "cc" : "combined");
696-
if (quote_c_style(elem->path, NULL, NULL, 0))
697-
quote_c_style(elem->path, NULL, stdout, 0);
698-
else
699-
printf("%s", elem->path);
700-
putchar('\n');
702+
if (rev->loginfo)
703+
show_log(rev, rev->loginfo, "\n");
704+
dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path);
701705
printf("index ");
702706
for (i = 0; i < num_parent; i++) {
703707
abb = find_unique_abbrev(elem->parent[i].sha1,
@@ -728,6 +732,8 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
728732
}
729733
putchar('\n');
730734
}
735+
dump_quoted_path("--- a/", elem->path);
736+
dump_quoted_path("+++ b/", elem->path);
731737
dump_sline(sline, cnt, num_parent);
732738
}
733739
free(result);
@@ -749,8 +755,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
749755

750756
#define COLONS "::::::::::::::::::::::::::::::::"
751757

752-
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
758+
static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev)
753759
{
760+
struct diff_options *opt = &rev->diffopt;
754761
int i, offset;
755762
const char *prefix;
756763
int line_termination, inter_name_termination;
@@ -760,8 +767,8 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
760767
if (!line_termination)
761768
inter_name_termination = 0;
762769

763-
if (header)
764-
printf("%s%c", header, line_termination);
770+
if (rev->loginfo)
771+
show_log(rev, rev->loginfo, "\n");
765772

766773
if (opt->output_format == DIFF_FORMAT_RAW) {
767774
offset = strlen(COLONS) - num_parent;
@@ -802,40 +809,44 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
802809
}
803810
}
804811

805-
int show_combined_diff(struct combine_diff_path *p,
812+
void show_combined_diff(struct combine_diff_path *p,
806813
int num_parent,
807814
int dense,
808-
const char *header,
809-
struct diff_options *opt)
815+
struct rev_info *rev)
810816
{
817+
struct diff_options *opt = &rev->diffopt;
811818
if (!p->len)
812-
return 0;
819+
return;
813820
switch (opt->output_format) {
814821
case DIFF_FORMAT_RAW:
815822
case DIFF_FORMAT_NAME_STATUS:
816823
case DIFF_FORMAT_NAME:
817-
show_raw_diff(p, num_parent, header, opt);
818-
return 1;
819-
820-
default:
824+
show_raw_diff(p, num_parent, rev);
825+
return;
821826
case DIFF_FORMAT_PATCH:
822-
return show_patch_diff(p, num_parent, dense, header, opt);
827+
show_patch_diff(p, num_parent, dense, rev);
828+
return;
829+
default:
830+
return;
823831
}
824832
}
825833

826-
const char *diff_tree_combined_merge(const unsigned char *sha1,
827-
const char *header, int dense,
828-
struct diff_options *opt)
834+
void diff_tree_combined_merge(const unsigned char *sha1,
835+
int dense, struct rev_info *rev)
829836
{
837+
struct diff_options *opt = &rev->diffopt;
830838
struct commit *commit = lookup_commit(sha1);
831839
struct diff_options diffopts;
832840
struct commit_list *parents;
833841
struct combine_diff_path *p, *paths = NULL;
834842
int num_parent, i, num_paths;
843+
int do_diffstat;
835844

845+
do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
846+
opt->with_stat);
836847
diffopts = *opt;
837-
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
838848
diffopts.with_raw = 0;
849+
diffopts.with_stat = 0;
839850
diffopts.recursive = 1;
840851

841852
/* count parents */
@@ -849,11 +860,24 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
849860
parents;
850861
parents = parents->next, i++) {
851862
struct commit *parent = parents->item;
863+
/* show stat against the first parent even
864+
* when doing combined diff.
865+
*/
866+
if (i == 0 && do_diffstat)
867+
diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
868+
else
869+
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
852870
diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
853871
&diffopts);
854872
diffcore_std(&diffopts);
855873
paths = intersect_paths(paths, i, num_parent);
874+
875+
if (do_diffstat && rev->loginfo)
876+
show_log(rev, rev->loginfo,
877+
opt->with_stat ? "---\n" : "\n");
856878
diff_flush(&diffopts);
879+
if (opt->with_stat)
880+
putchar('\n');
857881
}
858882

859883
/* find out surviving paths */
@@ -866,17 +890,13 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
866890
int saved_format = opt->output_format;
867891
opt->output_format = DIFF_FORMAT_RAW;
868892
for (p = paths; p; p = p->next) {
869-
if (show_combined_diff(p, num_parent, dense,
870-
header, opt))
871-
header = NULL;
893+
show_combined_diff(p, num_parent, dense, rev);
872894
}
873895
opt->output_format = saved_format;
874896
putchar(opt->line_termination);
875897
}
876898
for (p = paths; p; p = p->next) {
877-
if (show_combined_diff(p, num_parent, dense,
878-
header, opt))
879-
header = NULL;
899+
show_combined_diff(p, num_parent, dense, rev);
880900
}
881901
}
882902

@@ -886,5 +906,4 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
886906
paths = paths->next;
887907
free(tmp);
888908
}
889-
return header;
890909
}

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ enum cmit_fmt {
4545
CMIT_FMT_FULL,
4646
CMIT_FMT_FULLER,
4747
CMIT_FMT_ONELINE,
48+
49+
CMIT_FMT_UNSPECIFIED,
4850
};
4951

5052
extern enum cmit_fmt get_commit_format(const char *arg);

diff-files.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,35 @@
55
*/
66
#include "cache.h"
77
#include "diff.h"
8+
#include "commit.h"
9+
#include "revision.h"
810

911
static const char diff_files_usage[] =
1012
"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
1113
COMMON_DIFF_OPTIONS_HELP;
1214

13-
static struct diff_options diff_options;
15+
static struct rev_info rev;
1416
static int silent = 0;
1517
static int diff_unmerged_stage = 2;
1618
static int combine_merges = 0;
1719
static int dense_combined_merges = 0;
1820

1921
static void show_unmerge(const char *path)
2022
{
21-
diff_unmerge(&diff_options, path);
23+
diff_unmerge(&rev.diffopt, path);
2224
}
2325

2426
static void show_file(int pfx, struct cache_entry *ce)
2527
{
26-
diff_addremove(&diff_options, pfx, ntohl(ce->ce_mode),
28+
diff_addremove(&rev.diffopt, pfx, ntohl(ce->ce_mode),
2729
ce->sha1, ce->name, NULL);
2830
}
2931

3032
static void show_modified(int oldmode, int mode,
3133
const unsigned char *old_sha1, const unsigned char *sha1,
3234
char *path)
3335
{
34-
diff_change(&diff_options, oldmode, mode, old_sha1, sha1, path, NULL);
36+
diff_change(&rev.diffopt, oldmode, mode, old_sha1, sha1, path, NULL);
3537
}
3638

3739
int main(int argc, const char **argv)
@@ -41,7 +43,7 @@ int main(int argc, const char **argv)
4143
int entries, i;
4244

4345
git_config(git_diff_config);
44-
diff_setup(&diff_options);
46+
diff_setup(&rev.diffopt);
4547
while (1 < argc && argv[1][0] == '-') {
4648
if (!strcmp(argv[1], "--")) {
4749
argv++;
@@ -74,7 +76,7 @@ int main(int argc, const char **argv)
7476
dense_combined_merges = combine_merges = 1;
7577
else {
7678
int diff_opt_cnt;
77-
diff_opt_cnt = diff_opt_parse(&diff_options,
79+
diff_opt_cnt = diff_opt_parse(&rev.diffopt,
7880
argv+1, argc-1);
7981
if (diff_opt_cnt < 0)
8082
usage(diff_files_usage);
@@ -89,13 +91,13 @@ int main(int argc, const char **argv)
8991
argv++; argc--;
9092
}
9193
if (dense_combined_merges)
92-
diff_options.output_format = DIFF_FORMAT_PATCH;
94+
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
9395

9496
/* Find the directory, and set up the pathspec */
9597
pathspec = get_pathspec(prefix, argv + 1);
9698
entries = read_cache();
9799

98-
if (diff_setup_done(&diff_options) < 0)
100+
if (diff_setup_done(&rev.diffopt) < 0)
99101
usage(diff_files_usage);
100102

101103
/* At this point, if argc == 1, then we are doing everything.
@@ -167,8 +169,7 @@ int main(int argc, const char **argv)
167169
if (combine_merges && num_compare_stages == 2) {
168170
show_combined_diff(&combine.p, 2,
169171
dense_combined_merges,
170-
NULL,
171-
&diff_options);
172+
&rev);
172173
free(combine.p.path);
173174
continue;
174175
}
@@ -194,7 +195,7 @@ int main(int argc, const char **argv)
194195
continue;
195196
}
196197
changed = ce_match_stat(ce, &st, 0);
197-
if (!changed && !diff_options.find_copies_harder)
198+
if (!changed && !rev.diffopt.find_copies_harder)
198199
continue;
199200
oldmode = ntohl(ce->ce_mode);
200201

@@ -207,7 +208,7 @@ int main(int argc, const char **argv)
207208
ce->sha1, (changed ? null_sha1 : ce->sha1),
208209
ce->name);
209210
}
210-
diffcore_std(&diff_options);
211-
diff_flush(&diff_options);
211+
diffcore_std(&rev.diffopt);
212+
diff_flush(&rev.diffopt);
212213
return 0;
213214
}

0 commit comments

Comments
 (0)