summaryrefslogtreecommitdiff
path: root/combine-diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-01-24 01:22:04 -0800
committerJunio C Hamano <junkio@cox.net>2006-01-28 00:08:28 -0800
commitd8f4790e6fe7a9d94468ea83d1370643604d43e5 (patch)
tree21468108c5791e31c898b5f49bdd7566f0975e48 /combine-diff.c
parentaf3feefa1d057713c2277cc1543d438e60c65306 (diff)
downloadgit-d8f4790e6fe7a9d94468ea83d1370643604d43e5.tar.gz
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>
Diffstat (limited to 'combine-diff.c')
-rw-r--r--combine-diff.c69
1 files changed, 64 insertions, 5 deletions
diff --git a/combine-diff.c b/combine-diff.c
index 669002349a..062ed8a7bf 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -278,7 +278,25 @@ static int interesting(struct sline *sline, unsigned long all_mask)
return ((sline->flag & all_mask) != all_mask || sline->lost_head);
}
-static void make_hunks(struct sline *sline, unsigned long cnt, int num_parent)
+static unsigned long line_diff_parents(struct sline *sline, unsigned long all_mask)
+{
+ /*
+ * Look at the line and see from which parents we have difference.
+ * Lower bits of sline->flag records if the parent had this line,
+ * so XOR with all_mask gives us on-bits for parents we have
+ * differences with.
+ */
+ unsigned long parents = (sline->flag ^ all_mask);
+ if (sline->lost_head) {
+ struct lline *ll;
+ for (ll = sline->lost_head; ll; ll = ll->next)
+ parents |= ll->parent_map;
+ }
+ return parents & all_mask;
+}
+
+static void make_hunks(struct sline *sline, unsigned long cnt,
+ int num_parent, int dense)
{
unsigned long all_mask = (1UL<<num_parent) - 1;
unsigned long mark = (1UL<<num_parent);
@@ -302,6 +320,45 @@ static void make_hunks(struct sline *sline, unsigned long cnt, int num_parent)
}
i++;
}
+ if (!dense)
+ return;
+
+ /* Look at each hunk, and if it contains changes from only
+ * one parent, mark that uninteresting.
+ */
+ i = 0;
+ while (i < cnt) {
+ int j, hunk_end, diffs;
+ unsigned long parents;
+ while (i < cnt && !(sline[i].flag & mark))
+ i++;
+ if (cnt <= i)
+ break; /* No more interesting hunks */
+ for (hunk_end = i + 1; hunk_end < cnt; hunk_end++)
+ if (!(sline[hunk_end].flag & mark))
+ break;
+ /* [i..hunk_end) are interesting. Now is it from
+ * only one parent?
+ * If lost lines are only from one parent and
+ * remaining lines existed in parents other than
+ * that parent, then the hunk is not that interesting.
+ */
+ parents = 0;
+ diffs = 0;
+ for (j = i; j < hunk_end; j++)
+ parents |= line_diff_parents(sline + j, all_mask);
+ /* Now, how many bits from [0..num_parent) are on? */
+ for (j = 0; j < num_parent; j++) {
+ if (parents & (1UL<<j))
+ diffs++;
+ }
+ if (diffs < 2) {
+ /* This hunk is not that interesting after all */
+ for (j = i; j < hunk_end; j++)
+ sline[j].flag &= ~mark;
+ }
+ i = hunk_end;
+ }
}
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)
}
}
-static void show_combined_diff(struct path_list *elem, int num_parent)
+static void show_combined_diff(struct path_list *elem, int num_parent,
+ int dense)
{
unsigned long size, cnt, lno;
char *result, *cp, *ep;
@@ -390,7 +448,7 @@ static void show_combined_diff(struct path_list *elem, int num_parent)
for (i = 0; i < num_parent; i++)
combine_diff(elem->parent_sha1[i], ourtmp, sline, cnt, i);
- make_hunks(sline, cnt, num_parent);
+ make_hunks(sline, cnt, num_parent, dense);
dump_sline(sline, cnt, num_parent);
unlink(ourtmp);
@@ -410,7 +468,8 @@ static void show_combined_diff(struct path_list *elem, int num_parent)
}
int diff_tree_combined_merge(const unsigned char *sha1,
- const char *header, int show_empty_merge)
+ const char *header,
+ int show_empty_merge, int dense)
{
struct commit *commit = lookup_commit(sha1);
struct diff_options diffopts;
@@ -455,7 +514,7 @@ int diff_tree_combined_merge(const unsigned char *sha1,
else
printf("%s", p->path);
putchar('\n');
- show_combined_diff(p, num_parent);
+ show_combined_diff(p, num_parent, dense);
}
}