blame: factor out helper for calling xdi_diff()

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 9, 2012 at 22:23 UTC 4b4132fd89b248896d527dffd1ddfb7bbf375a45
1 file changed +16 -22
builtin/blame.c
+16 -22
@@ -88,6 +88,20 @@ struct origin {
88 char path[FLEX_ARRAY];
89 };
90
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 +
105 /*
106 * Prepare diff_filespec and convert it using diff textconv API
107 * if the textconv driver exists.
@@ -781,9 +795,6 @@ static int pass_blame_to_parent(struct scoreboard *sb,
795 int last_in_target;
796 mmfile_t file_p, file_o;
797 struct blame_chunk_cb_data d;
784 - xpparam_t xpp;
785 - xdemitconf_t xecfg;
786 - xdemitcb_t ecb;
798
799 memset(&d, 0, sizeof(d));
800 d.sb = sb; d.target = target; d.parent = parent;
@@ -795,14 +806,7 @@ static int pass_blame_to_parent(struct scoreboard *sb,
806 fill_origin_blob(&sb->revs->diffopt, target, &file_o);
807 num_get_patch++;
808
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);
810 /* The rest (i.e. anything after tlno) are the same as the parent */
811 blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent);
812
@@ -932,9 +936,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
936 int cnt;
937 mmfile_t file_o;
938 struct handle_split_cb_data d;
935 - xpparam_t xpp;
936 - xdemitconf_t xecfg;
937 - xdemitcb_t ecb;
939
940 memset(&d, 0, sizeof(d));
941 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,
956 * file_o is a part of final image we are annotating.
957 * file_p partially may match that image.
958 */
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;
959 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);
961 /* remainder, if any, all match the preimage */
962 handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
963 }