From: Junio C Hamano Date: Tue, 31 Jan 2006 06:33:15 +0000 (-0800) Subject: combine-diff: show parent line numbers as well. X-Git-Tag: v1.2.0~70 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f16706cc59af32d0255e0a5ec9d04475bc976ede;p=git.git combine-diff: show parent line numbers as well. Signed-off-by: Junio C Hamano --- diff --git a/combine-diff.c b/combine-diff.c index a698475e..fa7af5e5 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -86,6 +86,7 @@ struct sline { * bit N is used for "interesting" lines, including context. */ unsigned long flag; + unsigned long *p_lno; }; static char *grab_blob(const unsigned char *sha1, unsigned long *size) @@ -210,14 +211,15 @@ static void append_lost(struct sline *sline, int n, const char *line) } static void combine_diff(const unsigned char *parent, const char *ourtmp, - struct sline *sline, int cnt, int n) + struct sline *sline, int cnt, int n, int num_parent) { FILE *in; char parent_tmp[TMPPATHLEN]; char cmd[TMPPATHLEN * 2 + 1024]; char line[MAXLINELEN]; - unsigned int lno, ob, on, nb, nn; - unsigned long pmask = ~(1UL << n); + unsigned int lno, ob, on, nb, nn, p_lno; + unsigned long nmask = (1UL << n); + unsigned long pmask = ~nmask; struct sline *lost_bucket = NULL; write_temp_blob(parent_tmp, parent); @@ -225,7 +227,7 @@ static void combine_diff(const unsigned char *parent, const char *ourtmp, parent_tmp, ourtmp); in = popen(cmd, "r"); if (!in) - return; + die("cannot spawn %s", cmd); lno = 1; while (fgets(line, sizeof(line), in) != NULL) { @@ -235,16 +237,25 @@ static void combine_diff(const unsigned char *parent, const char *ourtmp, &ob, &on, &nb, &nn)) break; lno = nb; - if (!nb) { + if (!nb) /* @@ -1,2 +0,0 @@ to remove the * first two lines... */ nb = 1; - } if (nn == 0) + /* @@ -X,Y +N,0 @@ removed Y lines + * that would have come *after* line N + * in the result. Our lost buckets hang + * to the line after the removed lines, + */ lost_bucket = &sline[nb]; else lost_bucket = &sline[nb-1]; + if (!sline[nb-1].p_lno) + sline[nb-1].p_lno = + xcalloc(num_parent, + sizeof(unsigned long)); + sline[nb-1].p_lno[n] = ob; continue; } if (!lost_bucket) @@ -261,6 +272,29 @@ static void combine_diff(const unsigned char *parent, const char *ourtmp, } fclose(in); unlink(parent_tmp); + + /* Assign line numbers for this parent. + * + * sline[lno].p_lno[n] records the first line number + * (counting from 1) for parent N if the final hunk display + * started by showing sline[lno] (possibly showing the lost + * lines attached to it first). + */ + for (lno = 0, p_lno = 1; lno < cnt; lno++) { + struct lline *ll; + sline[lno].p_lno[n] = p_lno; + + /* How many lines would this sline advance the p_lno? */ + ll = sline[lno].lost_head; + while (ll) { + if (ll->parent_map & nmask) + p_lno++; /* '-' means parent had it */ + ll = ll->next; + } + if (sline[lno].flag & nmask) + p_lno++; /* no '+' means parent had it */ + } + sline[lno].p_lno[n] = p_lno; /* trailer */ } static unsigned long context = 3; @@ -466,11 +500,18 @@ static int make_hunks(struct sline *sline, unsigned long cnt, return has_interesting; } -static void dump_sline(struct sline *sline, int cnt, int num_parent) +static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, unsigned long cnt, int n) +{ + l0 = sline[l0].p_lno[n]; + l1 = sline[l1].p_lno[n]; + printf("-%lu,%lu ", l0, l1-l0); +} + +static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent) { unsigned long mark = (1UL<lost_head; + sline->p_lno[i] = sline->p_lno[j]; while (ll) { if (ll->parent_map & jmask) ll->parent_map |= imask; @@ -590,7 +634,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent, if (result[size-1] != '\n') cnt++; /* incomplete line */ - sline = xcalloc(cnt, sizeof(*sline)); + sline = xcalloc(cnt+1, sizeof(*sline)); ep = result; sline[0].bol = result; for (lno = 0, cp = result; cp - result < size; cp++) { @@ -609,6 +653,10 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent, sline[cnt-1].flag = (1UL<parent_sha1[i], ourtmp, sline, - cnt, i); + cnt, i, num_parent); } show_hunks = make_hunks(sline, cnt, num_parent, dense);