Skip to content

Commit 46171c9

Browse files
authored
Fix git log --graph -u hangs (git-for-windows#5193)
This fixes git-for-windows#5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
2 parents 49e3069 + e1d825a commit 46171c9

File tree

8 files changed

+42
-28
lines changed

8 files changed

+42
-28
lines changed

diff-lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ int index_differs_from(struct repository *r,
701701
return (has_changes != 0);
702702
}
703703

704-
static struct strbuf *idiff_prefix_cb(struct diff_options *opt UNUSED, void *data)
704+
static const char *idiff_prefix_cb(struct diff_options *opt UNUSED, void *data)
705705
{
706706
return data;
707707
}
@@ -716,7 +716,7 @@ void show_interdiff(const struct object_id *oid1, const struct object_id *oid2,
716716
opts.output_format = DIFF_FORMAT_PATCH;
717717
opts.output_prefix = idiff_prefix_cb;
718718
strbuf_addchars(&prefix, ' ', indent);
719-
opts.output_prefix_data = &prefix;
719+
opts.output_prefix_data = prefix.buf;
720720
diff_setup_done(&opts);
721721

722722
diff_tree_oid(oid1, oid2, "", &opts);

diff.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,12 +2317,10 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
23172317

23182318
const char *diff_line_prefix(struct diff_options *opt)
23192319
{
2320-
struct strbuf *msgbuf;
2321-
if (!opt->output_prefix)
2322-
return "";
2320+
if (opt->output_prefix)
2321+
return opt->output_prefix(opt, opt->output_prefix_data);
23232322

2324-
msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
2325-
return msgbuf->buf;
2323+
return "";
23262324
}
23272325

23282326
static unsigned long sane_truncate_line(char *line, unsigned long len)

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
9494
typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
9595
struct diff_options *options, void *data);
9696

97-
typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
97+
typedef const char *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
9898

9999
#define DIFF_FORMAT_RAW 0x0001
100100
#define DIFF_FORMAT_DIFFSTAT 0x0002

graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct git_graph {
314314
unsigned short default_column_color;
315315
};
316316

317-
static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void *data)
317+
static const char *diff_output_prefix_callback(struct diff_options *opt, void *data)
318318
{
319319
struct git_graph *graph = data;
320320
static struct strbuf msgbuf = STRBUF_INIT;
@@ -327,7 +327,7 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
327327
opt->line_prefix_length);
328328
if (graph)
329329
graph_padding_line(graph, &msgbuf);
330-
return &msgbuf;
330+
return msgbuf.buf;
331331
}
332332

333333
static const struct diff_options *default_diffopt;

line-log.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,6 @@ static void print_line(const char *prefix, char first,
897897
fputs("\\ No newline at end of file\n", file);
898898
}
899899

900-
static char *output_prefix(struct diff_options *opt)
901-
{
902-
if (opt->output_prefix) {
903-
struct strbuf *sb = opt->output_prefix(opt, opt->output_prefix_data);
904-
return sb->buf;
905-
} else {
906-
return xstrdup("");
907-
}
908-
}
909-
910900
static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *range)
911901
{
912902
unsigned int i, j = 0;
@@ -916,7 +906,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
916906
struct diff_ranges *diff = &range->diff;
917907

918908
struct diff_options *opt = &rev->diffopt;
919-
char *prefix = output_prefix(opt);
909+
const char *prefix = diff_line_prefix(opt);
920910
const char *c_reset = diff_get_color(opt->use_color, DIFF_RESET);
921911
const char *c_frag = diff_get_color(opt->use_color, DIFF_FRAGINFO);
922912
const char *c_meta = diff_get_color(opt->use_color, DIFF_METAINFO);
@@ -1003,7 +993,6 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
1003993
out:
1004994
free(p_ends);
1005995
free(t_ends);
1006-
free(prefix);
1007996
}
1008997

1009998
/*
@@ -1012,10 +1001,9 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang
10121001
*/
10131002
static void dump_diff_hacky(struct rev_info *rev, struct line_log_data *range)
10141003
{
1015-
char *prefix = output_prefix(&rev->diffopt);
1004+
const char *prefix = diff_line_prefix(&rev->diffopt);
10161005

10171006
fprintf(rev->diffopt.file, "%s\n", prefix);
1018-
free(prefix);
10191007

10201008
while (range) {
10211009
dump_diff_hacky_one(rev, range);

log-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,10 @@ int log_tree_diff_flush(struct rev_info *opt)
923923
*/
924924
int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
925925
if (opt->diffopt.output_prefix) {
926-
struct strbuf *msg = NULL;
926+
const char *msg;
927927
msg = opt->diffopt.output_prefix(&opt->diffopt,
928928
opt->diffopt.output_prefix_data);
929-
fwrite(msg->buf, msg->len, 1, opt->diffopt.file);
929+
fwrite(msg, strlen(msg), 1, opt->diffopt.file);
930930
}
931931

932932
/*

range-diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void patch_diff(const char *a, const char *b,
480480
diff_flush(diffopt);
481481
}
482482

483-
static struct strbuf *output_prefix_cb(struct diff_options *opt UNUSED, void *data)
483+
static const char *output_prefix_cb(struct diff_options *opt UNUSED, void *data)
484484
{
485485
return data;
486486
}
@@ -508,7 +508,7 @@ static void output(struct string_list *a, struct string_list *b,
508508
opts.flags.suppress_hunk_header_line_count = 1;
509509
opts.output_prefix = output_prefix_cb;
510510
strbuf_addstr(&indent, " ");
511-
opts.output_prefix_data = &indent;
511+
opts.output_prefix_data = indent.buf;
512512
diff_setup_done(&opts);
513513

514514
/*

t/t4211-line-log.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,32 @@ test_expect_success 'zero-width regex .* matches any function name' '
337337
test_cmp expect actual
338338
'
339339

340+
test_expect_success 'show line-log with graph' '
341+
qz_to_tab_space >expect <<-EOF &&
342+
* $head_oid Modify func2() in file.c
343+
|Z
344+
| diff --git a/file.c b/file.c
345+
| --- a/file.c
346+
| +++ b/file.c
347+
| @@ -6,4 +6,4 @@
348+
| int func2()
349+
| {
350+
| - return F2;
351+
| + return F2 + 2;
352+
| }
353+
* $root_oid Add func1() and func2() in file.c
354+
ZZ
355+
diff --git a/file.c b/file.c
356+
--- /dev/null
357+
+++ b/file.c
358+
@@ -0,0 +6,4 @@
359+
+int func2()
360+
+{
361+
+ return F2;
362+
+}
363+
EOF
364+
git log --graph --oneline -L:func2:file.c >actual &&
365+
test_cmp expect actual
366+
'
367+
340368
test_done

0 commit comments

Comments
 (0)