Skip to content

Commit 9153983

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Log message printout cleanups
On Sun, 16 Apr 2006, Junio C Hamano wrote: > > In the mid-term, I am hoping we can drop the generate_header() > callchain _and_ the custom code that formats commit log in-core, > found in cmd_log_wc(). Ok, this was nastier than expected, just because the dependencies between the different log-printing stuff were absolutely _everywhere_, but here's a patch that does exactly that. The patch is not very easy to read, and the "--patch-with-stat" thing is still broken (it does not call the "show_log()" thing properly for merges). That's not a new bug. In the new world order it _should_ do something like if (rev->logopt) show_log(rev, rev->logopt, "---\n"); but it doesn't. I haven't looked at the --with-stat logic, so I left it alone. That said, this patch removes more lines than it adds, and in particular, the "cmd_log_wc()" loop is now a very clean: while ((commit = get_revision(rev)) != NULL) { log_tree_commit(rev, commit); free(commit->buffer); commit->buffer = NULL; } so it doesn't get much prettier than this. All the complexity is entirely hidden in log-tree.c, and any code that needs to flush the log literally just needs to do the "if (rev->logopt) show_log(...)" incantation. I had to make the combined_diff() logic take a "struct rev_info" instead of just a "struct diff_options", but that part is pretty clean. This does change "git whatchanged" from using "diff-tree" as the commit descriptor to "commit", and I changed one of the tests to reflect that new reality. Otherwise everything still passes, and my other tests look fine too. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent db89665 commit 9153983

File tree

11 files changed

+151
-185
lines changed

11 files changed

+151
-185
lines changed

combine-diff.c

Lines changed: 21 additions & 26 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
{
@@ -585,9 +586,9 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
585586
}
586587

587588
static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
588-
int dense, const char *header,
589-
struct diff_options *opt)
589+
int dense, struct rev_info *rev)
590590
{
591+
struct diff_options *opt = &rev->diffopt;
591592
unsigned long result_size, cnt, lno;
592593
char *result, *cp, *ep;
593594
struct sline *sline; /* survived lines */
@@ -689,10 +690,8 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
689690
if (show_hunks || mode_differs || working_tree_file) {
690691
const char *abb;
691692

692-
if (header) {
693-
shown_header++;
694-
printf("%s%c", header, opt->line_termination);
695-
}
693+
if (rev->loginfo)
694+
show_log(rev, rev->loginfo, "\n");
696695
printf("diff --%s ", dense ? "cc" : "combined");
697696
if (quote_c_style(elem->path, NULL, NULL, 0))
698697
quote_c_style(elem->path, NULL, stdout, 0);
@@ -750,8 +749,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
750749

751750
#define COLONS "::::::::::::::::::::::::::::::::"
752751

753-
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
752+
static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev)
754753
{
754+
struct diff_options *opt = &rev->diffopt;
755755
int i, offset, mod_type = 'A';
756756
const char *prefix;
757757
int line_termination, inter_name_termination;
@@ -761,8 +761,8 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
761761
if (!line_termination)
762762
inter_name_termination = 0;
763763

764-
if (header)
765-
printf("%s%c", header, line_termination);
764+
if (rev->loginfo)
765+
show_log(rev, rev->loginfo, "\n");
766766

767767
for (i = 0; i < num_parent; i++) {
768768
if (p->parent[i].mode)
@@ -810,31 +810,31 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
810810
}
811811
}
812812

813-
int show_combined_diff(struct combine_diff_path *p,
813+
void show_combined_diff(struct combine_diff_path *p,
814814
int num_parent,
815815
int dense,
816-
const char *header,
817-
struct diff_options *opt)
816+
struct rev_info *rev)
818817
{
818+
struct diff_options *opt = &rev->diffopt;
819819
if (!p->len)
820-
return 0;
820+
return;
821821
switch (opt->output_format) {
822822
case DIFF_FORMAT_RAW:
823823
case DIFF_FORMAT_NAME_STATUS:
824824
case DIFF_FORMAT_NAME:
825-
show_raw_diff(p, num_parent, header, opt);
826-
return 1;
825+
show_raw_diff(p, num_parent, rev);
826+
return;
827827

828828
default:
829829
case DIFF_FORMAT_PATCH:
830-
return show_patch_diff(p, num_parent, dense, header, opt);
830+
show_patch_diff(p, num_parent, dense, rev);
831831
}
832832
}
833833

834-
const char *diff_tree_combined_merge(const unsigned char *sha1,
835-
const char *header, int dense,
836-
struct diff_options *opt)
834+
void diff_tree_combined_merge(const unsigned char *sha1,
835+
int dense, struct rev_info *rev)
837836
{
837+
struct diff_options *opt = &rev->diffopt;
838838
struct commit *commit = lookup_commit(sha1);
839839
struct diff_options diffopts;
840840
struct commit_list *parents;
@@ -874,17 +874,13 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
874874
int saved_format = opt->output_format;
875875
opt->output_format = DIFF_FORMAT_RAW;
876876
for (p = paths; p; p = p->next) {
877-
if (show_combined_diff(p, num_parent, dense,
878-
header, opt))
879-
header = NULL;
877+
show_combined_diff(p, num_parent, dense, rev);
880878
}
881879
opt->output_format = saved_format;
882880
putchar(opt->line_termination);
883881
}
884882
for (p = paths; p; p = p->next) {
885-
if (show_combined_diff(p, num_parent, dense,
886-
header, opt))
887-
header = NULL;
883+
show_combined_diff(p, num_parent, dense, rev);
888884
}
889885
}
890886

@@ -894,5 +890,4 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
894890
paths = paths->next;
895891
free(tmp);
896892
}
897-
return header;
898893
}

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
}

diff-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int main(int argc, const char **argv)
7171
nr_sha1 = 0;
7272
init_revisions(opt);
7373
opt->abbrev = 0;
74+
opt->diff = 1;
7475
argc = setup_revisions(argc, argv, opt, NULL);
7576

7677
while (--argc > 0) {

diff.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "tree-walk.h"
88

9+
struct rev_info;
910
struct diff_options;
1011

1112
typedef void (*change_fn_t)(struct diff_options *options,
@@ -70,11 +71,10 @@ struct combine_diff_path {
7071
(sizeof(struct combine_diff_path) + \
7172
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
7273

73-
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
74-
int dense, const char *header,
75-
struct diff_options *);
74+
extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
75+
int dense, struct rev_info *);
7676

77-
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
77+
extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
7878

7979
extern void diff_addremove(struct diff_options *,
8080
int addremove,

git.c

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -282,75 +282,22 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
282282
struct rev_info *rev)
283283
{
284284
struct commit *commit;
285-
char *buf = xmalloc(LOGSIZE);
286-
const char *commit_prefix = "commit ";
287-
int shown = 0;
288285

289286
rev->abbrev = DEFAULT_ABBREV;
290287
rev->commit_format = CMIT_FMT_DEFAULT;
288+
rev->verbose_header = 1;
291289
argc = setup_revisions(argc, argv, rev, "HEAD");
292290

293291
if (argc > 1)
294292
die("unrecognized argument: %s", argv[1]);
295-
if (rev->commit_format == CMIT_FMT_ONELINE)
296-
commit_prefix = "";
297293

298294
prepare_revision_walk(rev);
299295
setup_pager();
300296
while ((commit = get_revision(rev)) != NULL) {
301-
unsigned long ofs = 0;
302-
303-
if (shown && rev->diff &&
304-
rev->commit_format != CMIT_FMT_ONELINE)
305-
putchar('\n');
306-
307-
ofs = sprintf(buf, "%s", commit_prefix);
308-
if (rev->abbrev_commit && rev->abbrev)
309-
ofs += sprintf(buf + ofs, "%s",
310-
find_unique_abbrev(commit->object.sha1,
311-
rev->abbrev));
312-
else
313-
ofs += sprintf(buf + ofs, "%s",
314-
sha1_to_hex(commit->object.sha1));
315-
if (rev->parents) {
316-
struct commit_list *parents = commit->parents;
317-
while (parents) {
318-
struct object *o = &(parents->item->object);
319-
parents = parents->next;
320-
if (o->flags & TMP_MARK)
321-
continue;
322-
ofs += sprintf(buf + ofs, " %s",
323-
sha1_to_hex(o->sha1));
324-
o->flags |= TMP_MARK;
325-
}
326-
/* TMP_MARK is a general purpose flag that can
327-
* be used locally, but the user should clean
328-
* things up after it is done with them.
329-
*/
330-
for (parents = commit->parents;
331-
parents;
332-
parents = parents->next)
333-
parents->item->object.flags &= ~TMP_MARK;
334-
}
335-
buf[ofs++] =
336-
(rev->commit_format == CMIT_FMT_ONELINE) ? ' ' : '\n';
337-
ofs += pretty_print_commit(rev->commit_format, commit, ~0,
338-
buf + ofs,
339-
LOGSIZE - ofs - 20,
340-
rev->abbrev);
341-
342-
if (rev->diff) {
343-
rev->use_precomputed_header = buf;
344-
strcpy(buf + ofs, "\n---\n");
345-
log_tree_commit(rev, commit);
346-
}
347-
else
348-
printf("%s\n", buf);
349-
shown = 1;
297+
log_tree_commit(rev, commit);
350298
free(commit->buffer);
351299
commit->buffer = NULL;
352300
}
353-
free(buf);
354301
return 0;
355302
}
356303

0 commit comments

Comments
 (0)