Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4b4132f

Browse files
René Scharfegitster
authored andcommitted
blame: factor out helper for calling xdi_diff()
Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d23ec7 commit 4b4132f

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

builtin/blame.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ struct origin {
8888
char path[FLEX_ARRAY];
8989
};
9090

91+
static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,
92+
xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)
93+
{
94+
xpparam_t xpp = {0};
95+
xdemitconf_t xecfg = {0};
96+
xdemitcb_t ecb = {0};
97+
98+
xpp.flags = xdl_opts;
99+
xecfg.ctxlen = ctxlen;
100+
xecfg.hunk_func = hunk_func;
101+
ecb.priv = cb_data;
102+
return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);
103+
}
104+
91105
/*
92106
* Prepare diff_filespec and convert it using diff textconv API
93107
* if the textconv driver exists.
@@ -781,9 +795,6 @@ static int pass_blame_to_parent(struct scoreboard *sb,
781795
int last_in_target;
782796
mmfile_t file_p, file_o;
783797
struct blame_chunk_cb_data d;
784-
xpparam_t xpp;
785-
xdemitconf_t xecfg;
786-
xdemitcb_t ecb;
787798

788799
memset(&d, 0, sizeof(d));
789800
d.sb = sb; d.target = target; d.parent = parent;
@@ -795,14 +806,7 @@ static int pass_blame_to_parent(struct scoreboard *sb,
795806
fill_origin_blob(&sb->revs->diffopt, target, &file_o);
796807
num_get_patch++;
797808

798-
memset(&xpp, 0, sizeof(xpp));
799-
xpp.flags = xdl_opts;
800-
memset(&xecfg, 0, sizeof(xecfg));
801-
xecfg.ctxlen = 0;
802-
xecfg.hunk_func = blame_chunk_cb;
803-
memset(&ecb, 0, sizeof(ecb));
804-
ecb.priv = &d;
805-
xdi_diff(&file_p, &file_o, &xpp, &xecfg, &ecb);
809+
diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d);
806810
/* The rest (i.e. anything after tlno) are the same as the parent */
807811
blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent);
808812

@@ -932,9 +936,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
932936
int cnt;
933937
mmfile_t file_o;
934938
struct handle_split_cb_data d;
935-
xpparam_t xpp;
936-
xdemitconf_t xecfg;
937-
xdemitcb_t ecb;
938939

939940
memset(&d, 0, sizeof(d));
940941
d.sb = sb; d.ent = ent; d.parent = parent; d.split = split;
@@ -955,15 +956,8 @@ static void find_copy_in_blob(struct scoreboard *sb,
955956
* file_o is a part of final image we are annotating.
956957
* file_p partially may match that image.
957958
*/
958-
memset(&xpp, 0, sizeof(xpp));
959-
xpp.flags = xdl_opts;
960-
memset(&xecfg, 0, sizeof(xecfg));
961-
xecfg.ctxlen = 1;
962-
xecfg.hunk_func = handle_split_cb;
963-
memset(&ecb, 0, sizeof(ecb));
964-
ecb.priv = &d;
965959
memset(split, 0, sizeof(struct blame_entry [3]));
966-
xdi_diff(file_p, &file_o, &xpp, &xecfg, &ecb);
960+
diff_hunks(file_p, &file_o, 1, handle_split_cb, &d);
967961
/* remainder, if any, all match the preimage */
968962
handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
969963
}

0 commit comments

Comments
 (0)