@matheusbsbs / matheus-bagliano / commits / d8f4790e6f
Fork 0

diff-tree --cc: denser combined diff output for a merge commit.

Building on the previous '-c' (combined) option, '--cc' option squelches the output further by omitting hunks that consist of difference with solely one parent. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 24, 2006 at 01:22 UTC d8f4790e6fe7a9d94468ea83d1370643604d43e5
3 files changed +73 -8
combine-diff.c
+64 -5
@@ -278,7 +278,25 @@ static int interesting(struct sline *sline, unsigned long all_mask)
278 return ((sline->flag & all_mask) != all_mask || sline->lost_head);
279 }
280
281 -static void make_hunks(struct sline *sline, unsigned long cnt, int num_parent)
281 +static unsigned long line_diff_parents(struct sline *sline, unsigned long all_mask)
282 +{
283 + /*
284 + * Look at the line and see from which parents we have difference.
285 + * Lower bits of sline->flag records if the parent had this line,
286 + * so XOR with all_mask gives us on-bits for parents we have
287 + * differences with.
288 + */
289 + unsigned long parents = (sline->flag ^ all_mask);
290 + if (sline->lost_head) {
291 + struct lline *ll;
292 + for (ll = sline->lost_head; ll; ll = ll->next)
293 + parents |= ll->parent_map;
294 + }
295 + return parents & all_mask;
296 +}
297 +
298 +static void make_hunks(struct sline *sline, unsigned long cnt,
299 + int num_parent, int dense)
300 {
301 unsigned long all_mask = (1UL<<num_parent) - 1;
302 unsigned long mark = (1UL<<num_parent);
@@ -302,6 +320,45 @@ static void make_hunks(struct sline *sline, unsigned long cnt, int num_parent)
320 }
321 i++;
322 }
323 + if (!dense)
324 + return;
325 +
326 + /* Look at each hunk, and if it contains changes from only
327 + * one parent, mark that uninteresting.
328 + */
329 + i = 0;
330 + while (i < cnt) {
331 + int j, hunk_end, diffs;
332 + unsigned long parents;
333 + while (i < cnt && !(sline[i].flag & mark))
334 + i++;
335 + if (cnt <= i)
336 + break; /* No more interesting hunks */
337 + for (hunk_end = i + 1; hunk_end < cnt; hunk_end++)
338 + if (!(sline[hunk_end].flag & mark))
339 + break;
340 + /* [i..hunk_end) are interesting. Now is it from
341 + * only one parent?
342 + * If lost lines are only from one parent and
343 + * remaining lines existed in parents other than
344 + * that parent, then the hunk is not that interesting.
345 + */
346 + parents = 0;
347 + diffs = 0;
348 + for (j = i; j < hunk_end; j++)
349 + parents |= line_diff_parents(sline + j, all_mask);
350 + /* Now, how many bits from [0..num_parent) are on? */
351 + for (j = 0; j < num_parent; j++) {
352 + if (parents & (1UL<<j))
353 + diffs++;
354 + }
355 + if (diffs < 2) {
356 + /* This hunk is not that interesting after all */
357 + for (j = i; j < hunk_end; j++)
358 + sline[j].flag &= ~mark;
359 + }
360 + i = hunk_end;
361 + }
362 }
363
364 static void dump_sline(struct sline *sline, int cnt, int num_parent)
@@ -351,7 +408,8 @@ static void dump_sline(struct sline *sline, int cnt, int num_parent)
408 }
409 }
410
354 -static void show_combined_diff(struct path_list *elem, int num_parent)
411 +static void show_combined_diff(struct path_list *elem, int num_parent,
412 + int dense)
413 {
414 unsigned long size, cnt, lno;
415 char *result, *cp, *ep;
@@ -390,7 +448,7 @@ static void show_combined_diff(struct path_list *elem, int num_parent)
448 for (i = 0; i < num_parent; i++)
449 combine_diff(elem->parent_sha1[i], ourtmp, sline, cnt, i);
450
393 - make_hunks(sline, cnt, num_parent);
451 + make_hunks(sline, cnt, num_parent, dense);
452
453 dump_sline(sline, cnt, num_parent);
454 unlink(ourtmp);
@@ -410,7 +468,8 @@ static void show_combined_diff(struct path_list *elem, int num_parent)
468 }
469
470 int diff_tree_combined_merge(const unsigned char *sha1,
413 - const char *header, int show_empty_merge)
471 + const char *header,
472 + int show_empty_merge, int dense)
473 {
474 struct commit *commit = lookup_commit(sha1);
475 struct diff_options diffopts;
@@ -455,7 +514,7 @@ int diff_tree_combined_merge(const unsigned char *sha1,
514 else
515 printf("%s", p->path);
516 putchar('\n');
458 - show_combined_diff(p, num_parent);
517 + show_combined_diff(p, num_parent, dense);
518 }
519 }
520
diff-tree.c
+8 -2
@@ -8,6 +8,7 @@ static int verbose_header = 0;
8 static int ignore_merges = 1;
9 static int show_empty_combined = 0;
10 static int combine_merges = 0;
11 +static int dense_combined_merges = 0;
12 static int read_stdin = 0;
13
14 static const char *header = NULL;
@@ -121,7 +122,8 @@ static int diff_tree_commit(const unsigned char *commit_sha1)
122 header = generate_header(sha1, sha1,
123 commit->buffer);
124 return diff_tree_combined_merge(sha1, header,
124 - show_empty_combined);
125 + show_empty_combined,
126 + dense_combined_merges);
127 }
128 }
129
@@ -168,7 +170,7 @@ static int diff_tree_stdin(char *line)
170 }
171
172 static const char diff_tree_usage[] =
171 -"git-diff-tree [--stdin] [-m] [-c] [-s] [-v] [--pretty] [-t] [-r] [--root] "
173 +"git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] "
174 "[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\n"
175 " -r diff recursively\n"
176 " --root include the initial commit as diff against /dev/null\n"
@@ -235,6 +237,10 @@ int main(int argc, const char **argv)
237 combine_merges = 1;
238 continue;
239 }
240 + if (!strcmp(arg, "--cc")) {
241 + dense_combined_merges = combine_merges = 1;
242 + continue;
243 + }
244 if (!strcmp(arg, "-v")) {
245 verbose_header = 1;
246 header_prefix = "diff-tree ";
diff.h
+1 -1
@@ -56,7 +56,7 @@ extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
56 extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
57 const char *base, struct diff_options *opt);
58
59 -extern int diff_tree_combined_merge(const unsigned char *sha1, const char *, int);
59 +extern int diff_tree_combined_merge(const unsigned char *sha1, const char *, int, int);
60
61 extern void diff_addremove(struct diff_options *,
62 int addremove,