Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 924 lines (845 sloc) 23.808 kb
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
1 #include "cache.h"
2 #include "commit.h"
8e44025 Use blob_, commit_, tag_, and tree_type throughout.
Peter Eriksen authored
3 #include "blob.h"
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
4 #include "diff.h"
5 #include "diffcore.h"
6 #include "quote.h"
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
7 #include "xdiff-interface.h"
9153983 Log message printout cleanups
Linus Torvalds authored
8 #include "log-tree.h"
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
9
10 static int uninteresting(struct diff_filepair *p)
11 {
12 if (diff_unmodified_pair(p))
13 return 1;
14 return 0;
15 }
16
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
17 static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr, int n, int num_parent)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
18 {
19 struct diff_queue_struct *q = &diff_queued_diff;
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
20 struct combine_diff_path *p;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
21 int i;
22
23 if (!n) {
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
24 struct combine_diff_path *list = NULL, **tail = &list;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
25 for (i = 0; i < q->nr; i++) {
26 int len;
27 const char *path;
28 if (uninteresting(q->queue[i]))
29 continue;
30 path = q->queue[i]->two->path;
31 len = strlen(path);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
32 p = xmalloc(combine_diff_path_size(num_parent, len));
33 p->path = (char*) &(p->parent[num_parent]);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
34 memcpy(p->path, path, len);
35 p->path[len] = 0;
36 p->len = len;
37 p->next = NULL;
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
38 memset(p->parent, 0,
39 sizeof(p->parent[0]) * num_parent);
40
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
41 memcpy(p->sha1, q->queue[i]->two->sha1, 20);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
42 p->mode = q->queue[i]->two->mode;
43 memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
44 p->parent[n].mode = q->queue[i]->one->mode;
d416df8 combine-diff: Record diff status a bit more faithfully
Junio C Hamano authored
45 p->parent[n].status = q->queue[i]->status;
5290a0f combine-diff: fix appending at the tail of a list.
Junio C Hamano authored
46 *tail = p;
47 tail = &p->next;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
48 }
49 return list;
50 }
51
52 for (p = curr; p; p = p->next) {
53 int found = 0;
54 if (!p->len)
55 continue;
56 for (i = 0; i < q->nr; i++) {
57 const char *path;
58 int len;
59
60 if (uninteresting(q->queue[i]))
61 continue;
62 path = q->queue[i]->two->path;
63 len = strlen(path);
64 if (len == p->len && !memcmp(path, p->path, len)) {
65 found = 1;
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
66 memcpy(p->parent[n].sha1,
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
67 q->queue[i]->one->sha1, 20);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
68 p->parent[n].mode = q->queue[i]->one->mode;
d416df8 combine-diff: Record diff status a bit more faithfully
Junio C Hamano authored
69 p->parent[n].status = q->queue[i]->status;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
70 break;
71 }
72 }
73 if (!found)
74 p->len = 0;
75 }
76 return curr;
77 }
78
b469d8b combine-diff: add a bit more comments.
Junio C Hamano authored
79 /* Lines lost from parent */
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
80 struct lline {
81 struct lline *next;
82 int len;
83 unsigned long parent_map;
84 char line[FLEX_ARRAY];
85 };
86
b469d8b combine-diff: add a bit more comments.
Junio C Hamano authored
87 /* Lines surviving in the merge result */
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
88 struct sline {
89 struct lline *lost_head, **lost_tail;
90 char *bol;
91 int len;
46dc941 combine-diff: cleanup.
Junio C Hamano authored
92 /* bit 0 up to (N-1) are on if the parent has this line (i.e.
93 * we did not change it).
b469d8b combine-diff: add a bit more comments.
Junio C Hamano authored
94 * bit N is used for "interesting" lines, including context.
95 */
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
96 unsigned long flag;
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
97 unsigned long *p_lno;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
98 };
99
100 static char *grab_blob(const unsigned char *sha1, unsigned long *size)
101 {
102 char *blob;
103 char type[20];
104 if (!memcmp(sha1, null_sha1, 20)) {
105 /* deleted blob */
106 *size = 0;
107 return xcalloc(1, 1);
108 }
109 blob = read_sha1_file(sha1, type, size);
8e44025 Use blob_, commit_, tag_, and tree_type throughout.
Peter Eriksen authored
110 if (strcmp(type, blob_type))
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
111 die("object '%s' is not a blob!", sha1_to_hex(sha1));
112 return blob;
113 }
114
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
115 static void append_lost(struct sline *sline, int n, const char *line, int len)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
116 {
117 struct lline *lline;
118 unsigned long this_mask = (1UL<<n);
119 if (line[len-1] == '\n')
120 len--;
121
122 /* Check to see if we can squash things */
123 if (sline->lost_head) {
124 struct lline *last_one = NULL;
125 /* We cannot squash it with earlier one */
126 for (lline = sline->lost_head;
127 lline;
128 lline = lline->next)
129 if (lline->parent_map & this_mask)
130 last_one = lline;
131 lline = last_one ? last_one->next : sline->lost_head;
132 while (lline) {
133 if (lline->len == len &&
134 !memcmp(lline->line, line, len)) {
135 lline->parent_map |= this_mask;
136 return;
137 }
138 lline = lline->next;
139 }
140 }
141
142 lline = xmalloc(sizeof(*lline) + len + 1);
143 lline->len = len;
144 lline->next = NULL;
145 lline->parent_map = this_mask;
146 memcpy(lline->line, line, len);
147 lline->line[len] = 0;
5290a0f combine-diff: fix appending at the tail of a list.
Junio C Hamano authored
148 *sline->lost_tail = lline;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
149 sline->lost_tail = &lline->next;
150 }
151
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
152 struct combine_diff_state {
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
153 struct xdiff_emit_state xm;
154
a0fd314 Match ofs/cnt types in diff interface.
Junio C Hamano authored
155 unsigned int lno;
156 int ob, on, nb, nn;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
157 unsigned long nmask;
158 int num_parent;
159 int n;
160 struct sline *sline;
161 struct sline *lost_bucket;
162 };
163
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
164 static void consume_line(void *state_, char *line, unsigned long len)
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
165 {
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
166 struct combine_diff_state *state = state_;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
167 if (5 < len && !memcmp("@@ -", line, 4)) {
168 if (parse_hunk_header(line, len,
169 &state->ob, &state->on,
170 &state->nb, &state->nn))
171 return;
172 state->lno = state->nb;
173 if (!state->nb)
174 /* @@ -1,2 +0,0 @@ to remove the
175 * first two lines...
176 */
177 state->nb = 1;
178 if (state->nn == 0)
179 /* @@ -X,Y +N,0 @@ removed Y lines
180 * that would have come *after* line N
181 * in the result. Our lost buckets hang
182 * to the line after the removed lines,
183 */
184 state->lost_bucket = &state->sline[state->nb];
185 else
186 state->lost_bucket = &state->sline[state->nb-1];
187 if (!state->sline[state->nb-1].p_lno)
188 state->sline[state->nb-1].p_lno =
189 xcalloc(state->num_parent,
190 sizeof(unsigned long));
191 state->sline[state->nb-1].p_lno[state->n] = state->ob;
192 return;
193 }
194 if (!state->lost_bucket)
195 return; /* not in any hunk yet */
196 switch (line[0]) {
197 case '-':
198 append_lost(state->lost_bucket, state->n, line+1, len-1);
199 break;
200 case '+':
201 state->sline[state->lno-1].flag |= state->nmask;
202 state->lno++;
203 break;
204 }
205 }
206
207 static void combine_diff(const unsigned char *parent, mmfile_t *result_file,
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
208 struct sline *sline, int cnt, int n, int num_parent)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
209 {
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
210 unsigned int p_lno, lno;
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
211 unsigned long nmask = (1UL << n);
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
212 xpparam_t xpp;
213 xdemitconf_t xecfg;
214 mmfile_t parent_file;
215 xdemitcb_t ecb;
216 struct combine_diff_state state;
217 unsigned long sz;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
218
4462731 combine-diff: do not punt on removed or added files.
Junio C Hamano authored
219 if (!cnt)
220 return; /* result deleted */
221
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
222 parent_file.ptr = grab_blob(parent, &sz);
223 parent_file.size = sz;
224 xpp.flags = XDF_NEED_MINIMAL;
225 xecfg.ctxlen = 0;
226 xecfg.flags = 0;
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
227 ecb.outf = xdiff_outf;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
228 ecb.priv = &state;
229 memset(&state, 0, sizeof(state));
d9ea73e combine-diff: refactor built-in xdiff interface.
Junio C Hamano authored
230 state.xm.consume = consume_line;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
231 state.nmask = nmask;
232 state.sline = sline;
233 state.lno = 1;
234 state.num_parent = num_parent;
235 state.n = n;
236
237 xdl_diff(&parent_file, result_file, &xpp, &xecfg, &ecb);
238 free(parent_file.ptr);
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
239
240 /* Assign line numbers for this parent.
241 *
242 * sline[lno].p_lno[n] records the first line number
243 * (counting from 1) for parent N if the final hunk display
244 * started by showing sline[lno] (possibly showing the lost
245 * lines attached to it first).
246 */
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
247 for (lno = 0, p_lno = 1; lno <= cnt; lno++) {
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
248 struct lline *ll;
249 sline[lno].p_lno[n] = p_lno;
250
251 /* How many lines would this sline advance the p_lno? */
252 ll = sline[lno].lost_head;
253 while (ll) {
254 if (ll->parent_map & nmask)
255 p_lno++; /* '-' means parent had it */
256 ll = ll->next;
257 }
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
258 if (lno < cnt && !(sline[lno].flag & nmask))
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
259 p_lno++; /* no '+' means parent had it */
260 }
261 sline[lno].p_lno[n] = p_lno; /* trailer */
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
262 }
263
264 static unsigned long context = 3;
265 static char combine_marker = '@';
266
267 static int interesting(struct sline *sline, unsigned long all_mask)
268 {
46dc941 combine-diff: cleanup.
Junio C Hamano authored
269 /* If some parents lost lines here, or if we have added to
270 * some parent, it is interesting.
271 */
272 return ((sline->flag & all_mask) || sline->lost_head);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
273 }
274
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
275 static unsigned long adjust_hunk_tail(struct sline *sline,
276 unsigned long all_mask,
277 unsigned long hunk_begin,
278 unsigned long i)
279 {
46dc941 combine-diff: cleanup.
Junio C Hamano authored
280 /* i points at the first uninteresting line. If the last line
281 * of the hunk was interesting only because it has some
282 * deletion, then it is not all that interesting for the
283 * purpose of giving trailing context lines. This is because
284 * we output '-' line and then unmodified sline[i-1] itself in
285 * that case which gives us one extra context line.
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
286 */
46dc941 combine-diff: cleanup.
Junio C Hamano authored
287 if ((hunk_begin + 1 <= i) && !(sline[i-1].flag & all_mask))
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
288 i--;
289 return i;
290 }
291
46dc941 combine-diff: cleanup.
Junio C Hamano authored
292 static unsigned long find_next(struct sline *sline,
293 unsigned long mark,
294 unsigned long i,
295 unsigned long cnt,
296 int uninteresting)
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
297 {
46dc941 combine-diff: cleanup.
Junio C Hamano authored
298 /* We have examined up to i-1 and are about to look at i.
299 * Find next interesting or uninteresting line. Here,
300 * "interesting" does not mean interesting(), but marked by
301 * the give_context() function below (i.e. it includes context
302 * lines that are not interesting to interesting() function
303 * that are surrounded by interesting() ones.
304 */
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
305 while (i <= cnt)
46dc941 combine-diff: cleanup.
Junio C Hamano authored
306 if (uninteresting
307 ? !(sline[i].flag & mark)
308 : (sline[i].flag & mark))
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
309 return i;
310 else
311 i++;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
312 return i;
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
313 }
314
315 static int give_context(struct sline *sline, unsigned long cnt, int num_parent)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
316 {
317 unsigned long all_mask = (1UL<<num_parent) - 1;
318 unsigned long mark = (1UL<<num_parent);
319 unsigned long i;
320
46dc941 combine-diff: cleanup.
Junio C Hamano authored
321 /* Two groups of interesting lines may have a short gap of
322 * unintersting lines. Connect such groups to give them a
323 * bit of context.
324 *
325 * We first start from what the interesting() function says,
326 * and mark them with "mark", and paint context lines with the
327 * mark. So interesting() would still say false for such context
328 * lines but they are treated as "interesting" in the end.
329 */
330 i = find_next(sline, mark, 0, cnt, 0);
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
331 if (cnt < i)
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
332 return 0;
333
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
334 while (i <= cnt) {
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
335 unsigned long j = (context < i) ? (i - context) : 0;
336 unsigned long k;
46dc941 combine-diff: cleanup.
Junio C Hamano authored
337
338 /* Paint a few lines before the first interesting line. */
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
339 while (j < i)
340 sline[j++].flag |= mark;
341
342 again:
46dc941 combine-diff: cleanup.
Junio C Hamano authored
343 /* we know up to i is to be included. where does the
344 * next uninteresting one start?
345 */
346 j = find_next(sline, mark, i, cnt, 1);
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
347 if (cnt < j)
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
348 break; /* the rest are all interesting */
349
350 /* lookahead context lines */
46dc941 combine-diff: cleanup.
Junio C Hamano authored
351 k = find_next(sline, mark, j, cnt, 0);
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
352 j = adjust_hunk_tail(sline, all_mask, i, j);
353
354 if (k < j + context) {
355 /* k is interesting and [j,k) are not, but
356 * paint them interesting because the gap is small.
357 */
358 while (j < k)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
359 sline[j++].flag |= mark;
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
360 i = k;
361 goto again;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
362 }
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
363
364 /* j is the first uninteresting line and there is
46dc941 combine-diff: cleanup.
Junio C Hamano authored
365 * no overlap beyond it within context lines. Paint
366 * the trailing edge a bit.
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
367 */
368 i = k;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
369 k = (j + context < cnt+1) ? j + context : cnt+1;
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
370 while (j < k)
371 sline[j++].flag |= mark;
372 }
373 return 1;
374 }
375
376 static int make_hunks(struct sline *sline, unsigned long cnt,
377 int num_parent, int dense)
378 {
379 unsigned long all_mask = (1UL<<num_parent) - 1;
380 unsigned long mark = (1UL<<num_parent);
381 unsigned long i;
382 int has_interesting = 0;
383
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
384 for (i = 0; i <= cnt; i++) {
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
385 if (interesting(&sline[i], all_mask))
386 sline[i].flag |= mark;
387 else
388 sline[i].flag &= ~mark;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
389 }
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
390 if (!dense)
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
391 return give_context(sline, cnt, num_parent);
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
392
263eee2 combine-diff: extend --cc logic to Octopus.
Junio C Hamano authored
393 /* Look at each hunk, and if we have changes from only one
394 * parent, or the changes are the same from all but one
395 * parent, mark that uninteresting.
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
396 */
397 i = 0;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
398 while (i <= cnt) {
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
399 unsigned long j, hunk_begin, hunk_end;
bf1c32b combine-diff: update --cc "uninteresting hunks" logic.
Junio C Hamano authored
400 unsigned long same_diff;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
401 while (i <= cnt && !(sline[i].flag & mark))
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
402 i++;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
403 if (cnt < i)
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
404 break; /* No more interesting hunks */
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
405 hunk_begin = i;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
406 for (j = i + 1; j <= cnt; j++) {
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
407 if (!(sline[j].flag & mark)) {
408 /* Look beyond the end to see if there
409 * is an interesting line after this
410 * hunk within context span.
411 */
412 unsigned long la; /* lookahead */
413 int contin = 0;
414 la = adjust_hunk_tail(sline, all_mask,
415 hunk_begin, j);
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
416 la = (la + context < cnt + 1) ?
417 (la + context) : cnt + 1;
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
418 while (j <= --la) {
419 if (sline[la].flag & mark) {
420 contin = 1;
421 break;
422 }
423 }
424 if (!contin)
425 break;
426 j = la;
427 }
428 }
429 hunk_end = j;
430
bf1c32b combine-diff: update --cc "uninteresting hunks" logic.
Junio C Hamano authored
431 /* [i..hunk_end) are interesting. Now is it really
fd4b1d2 combine-diff: add safety check to --cc.
Junio C Hamano authored
432 * interesting? We check if there are only two versions
433 * and the result matches one of them. That is, we look
434 * at:
435 * (+) line, which records lines added to which parents;
436 * this line appears in the result.
437 * (-) line, which records from what parents the line
438 * was removed; this line does not appear in the result.
439 * then check the set of parents the result has difference
440 * from, from all lines. If there are lines that has
441 * different set of parents that the result has differences
442 * from, that means we have more than two versions.
443 *
444 * Even when we have only two versions, if the result does
445 * not match any of the parents, the it should be considered
446 * interesting. In such a case, we would have all '+' line.
447 * After passing the above "two versions" test, that would
448 * appear as "the same set of parents" to be "all parents".
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
449 */
bf1c32b combine-diff: update --cc "uninteresting hunks" logic.
Junio C Hamano authored
450 same_diff = 0;
451 has_interesting = 0;
452 for (j = i; j < hunk_end && !has_interesting; j++) {
46dc941 combine-diff: cleanup.
Junio C Hamano authored
453 unsigned long this_diff = sline[j].flag & all_mask;
bf1c32b combine-diff: update --cc "uninteresting hunks" logic.
Junio C Hamano authored
454 struct lline *ll = sline[j].lost_head;
455 if (this_diff) {
456 /* This has some changes. Is it the
457 * same as others?
458 */
459 if (!same_diff)
460 same_diff = this_diff;
461 else if (same_diff != this_diff) {
462 has_interesting = 1;
463 break;
464 }
465 }
466 while (ll && !has_interesting) {
467 /* Lost this line from these parents;
468 * who are they? Are they the same?
469 */
470 this_diff = ll->parent_map;
471 if (!same_diff)
472 same_diff = this_diff;
473 else if (same_diff != this_diff) {
474 has_interesting = 1;
475 }
476 ll = ll->next;
477 }
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
478 }
bf1c32b combine-diff: update --cc "uninteresting hunks" logic.
Junio C Hamano authored
479
fd4b1d2 combine-diff: add safety check to --cc.
Junio C Hamano authored
480 if (!has_interesting && same_diff != all_mask) {
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
481 /* This hunk is not that interesting after all */
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
482 for (j = hunk_begin; j < hunk_end; j++)
d8f4790 diff-tree --cc: denser combined diff output for a merge commit.
Junio C Hamano authored
483 sline[j].flag &= ~mark;
484 }
485 i = hunk_end;
486 }
3ec1909 combine-diff: better hunk splitting.
Junio C Hamano authored
487
488 has_interesting = give_context(sline, cnt, num_parent);
8828cdc diff-tree --cc: squelch header generation on empty patch.
Junio C Hamano authored
489 return has_interesting;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
490 }
491
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
492 static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, unsigned long cnt, int n)
493 {
494 l0 = sline[l0].p_lno[n];
495 l1 = sline[l1].p_lno[n];
f7a3d33 combine-diff: finishing touches to git-diff-tree --cc
Junio C Hamano authored
496 printf(" -%lu,%lu", l0, l1-l0);
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
497 }
498
499 static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
500 {
501 unsigned long mark = (1UL<<num_parent);
502 int i;
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
503 unsigned long lno = 0;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
504
4462731 combine-diff: do not punt on removed or added files.
Junio C Hamano authored
505 if (!cnt)
506 return; /* result deleted */
507
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
508 while (1) {
509 struct sline *sl = &sline[lno];
8bc7574 combine-diff: type fix.
Junio C Hamano authored
510 unsigned long hunk_end;
511 unsigned long rlines;
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
512 while (lno <= cnt && !(sline[lno].flag & mark))
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
513 lno++;
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
514 if (cnt < lno)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
515 break;
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
516 else {
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
517 for (hunk_end = lno + 1; hunk_end <= cnt; hunk_end++)
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
518 if (!(sline[hunk_end].flag & mark))
519 break;
520 }
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
521 rlines = hunk_end - lno;
522 if (cnt < hunk_end)
523 rlines--; /* pointing at the last delete hunk */
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
524 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
525 for (i = 0; i < num_parent; i++)
526 show_parent_lno(sline, lno, hunk_end, cnt, i);
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
527 printf(" +%lu,%lu ", lno+1, rlines);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
528 for (i = 0; i <= num_parent; i++) putchar(combine_marker);
529 putchar('\n');
530 while (lno < hunk_end) {
531 struct lline *ll;
532 int j;
46dc941 combine-diff: cleanup.
Junio C Hamano authored
533 unsigned long p_mask;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
534 sl = &sline[lno++];
535 ll = sl->lost_head;
536 while (ll) {
537 for (j = 0; j < num_parent; j++) {
538 if (ll->parent_map & (1UL<<j))
539 putchar('-');
540 else
541 putchar(' ');
542 }
543 puts(ll->line);
544 ll = ll->next;
545 }
7406595 combine-diff: fix hunks at the end (take #2).
Junio C Hamano authored
546 if (cnt < lno)
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
547 break;
46dc941 combine-diff: cleanup.
Junio C Hamano authored
548 p_mask = 1;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
549 for (j = 0; j < num_parent; j++) {
46dc941 combine-diff: cleanup.
Junio C Hamano authored
550 if (p_mask & sl->flag)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
551 putchar('+');
46dc941 combine-diff: cleanup.
Junio C Hamano authored
552 else
553 putchar(' ');
554 p_mask <<= 1;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
555 }
e228340 combine-diff: minor output changes.
Junio C Hamano authored
556 printf("%.*s\n", sl->len, sl->bol);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
557 }
558 }
559 }
560
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
561 static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
562 int i, int j)
563 {
564 /* We have already examined parent j and we know parent i
565 * and parent j are the same, so reuse the combined result
566 * of parent j for parent i.
567 */
568 unsigned long lno, imask, jmask;
569 imask = (1UL<<i);
570 jmask = (1UL<<j);
571
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
572 for (lno = 0; lno <= cnt; lno++) {
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
573 struct lline *ll = sline->lost_head;
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
574 sline->p_lno[i] = sline->p_lno[j];
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
575 while (ll) {
576 if (ll->parent_map & jmask)
577 ll->parent_map |= imask;
578 ll = ll->next;
579 }
46dc941 combine-diff: cleanup.
Junio C Hamano authored
580 if (sline->flag & jmask)
581 sline->flag |= imask;
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
582 sline++;
583 }
4462731 combine-diff: do not punt on removed or added files.
Junio C Hamano authored
584 /* the overall size of the file (sline[cnt]) */
585 sline->p_lno[i] = sline->p_lno[j];
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
586 }
587
eab144a Log message printout cleanups (#2)
Linus Torvalds authored
588 static void dump_quoted_path(const char *prefix, const char *path)
589 {
590 fputs(prefix, stdout);
591 if (quote_c_style(path, NULL, NULL, 0))
592 quote_c_style(path, NULL, stdout, 0);
593 else
594 printf("%s", path);
595 putchar('\n');
596 }
597
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
598 static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
9153983 Log message printout cleanups
Linus Torvalds authored
599 int dense, struct rev_info *rev)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
600 {
9153983 Log message printout cleanups
Linus Torvalds authored
601 struct diff_options *opt = &rev->diffopt;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
602 unsigned long result_size, cnt, lno;
310f8b5 cleanups: Remove unused vars from combine-diff.c
Serge E. Hallyn authored
603 char *result, *cp;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
604 struct sline *sline; /* survived lines */
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
605 int mode_differs = 0;
8828cdc diff-tree --cc: squelch header generation on empty patch.
Junio C Hamano authored
606 int i, show_hunks, shown_header = 0;
713a11f combine-diff: diff-files fix.
Junio C Hamano authored
607 int working_tree_file = !memcmp(elem->sha1, null_sha1, 20);
e70c6b3 combine-diff: Honour --full-index.
Mark Wooding authored
608 int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
609 mmfile_t result_file;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
610
ee1e541 git diff: support "-U" and "--unified" options properly
Linus Torvalds authored
611 context = opt->context;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
612 /* Read the result of merge first */
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
613 if (!working_tree_file)
614 result = grab_blob(elem->sha1, &result_size);
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
615 else {
9843a1f combine-diff: do not send NULL to printf
Junio C Hamano authored
616 /* Used by diff-tree to read from the working tree */
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
617 struct stat st;
618 int fd;
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
619 if (0 <= (fd = open(elem->path, O_RDONLY)) &&
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
620 !fstat(fd, &st)) {
621 int len = st.st_size;
622 int cnt = 0;
623
1b0c717 tree/diff header cleanup.
Junio C Hamano authored
624 elem->mode = canon_mode(st.st_mode);
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
625 result_size = len;
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
626 result = xmalloc(len + 1);
627 while (cnt < len) {
628 int done = xread(fd, result+cnt, len-cnt);
629 if (done == 0)
630 break;
631 if (done < 0)
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
632 die("read error '%s'", elem->path);
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
633 cnt += done;
634 }
635 result[len] = 0;
636 }
637 else {
638 /* deleted file */
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
639 result_size = 0;
713a11f combine-diff: diff-files fix.
Junio C Hamano authored
640 elem->mode = 0;
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
641 result = xmalloc(1);
642 result[0] = 0;
643 }
644 if (0 <= fd)
645 close(fd);
646 }
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
647
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
648 for (cnt = 0, cp = result; cp - result < result_size; cp++) {
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
649 if (*cp == '\n')
650 cnt++;
651 }
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
652 if (result_size && result[result_size-1] != '\n')
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
653 cnt++; /* incomplete line */
654
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
655 sline = xcalloc(cnt+2, sizeof(*sline));
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
656 sline[0].bol = result;
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
657 for (lno = 0; lno <= cnt + 1; lno++) {
4462731 combine-diff: do not punt on removed or added files.
Junio C Hamano authored
658 sline[lno].lost_tail = &sline[lno].lost_head;
659 sline[lno].flag = 0;
660 }
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
661 for (lno = 0, cp = result; cp - result < result_size; cp++) {
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
662 if (*cp == '\n') {
663 sline[lno].len = cp - sline[lno].bol;
664 lno++;
665 if (lno < cnt)
666 sline[lno].bol = cp + 1;
667 }
668 }
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
669 if (result_size && result[result_size-1] != '\n')
670 sline[cnt-1].len = result_size - (sline[cnt-1].bol - result);
671
672 result_file.ptr = result;
673 result_file.size = result_size;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
674
8a470eb combine-diff: do not lose hunks with only deletion at end.
Junio C Hamano authored
675 /* Even p_lno[cnt+1] is valid -- that is for the end line number
676 * for deletion hunk at the end.
677 */
678 sline[0].p_lno = xcalloc((cnt+2) * num_parent, sizeof(unsigned long));
679 for (lno = 0; lno <= cnt; lno++)
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
680 sline[lno+1].p_lno = sline[lno].p_lno + num_parent;
681
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
682 for (i = 0; i < num_parent; i++) {
683 int j;
684 for (j = 0; j < i; j++) {
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
685 if (!memcmp(elem->parent[i].sha1,
686 elem->parent[j].sha1, 20)) {
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
687 reuse_combine_diff(sline, cnt, i, j);
688 break;
689 }
690 }
691 if (i <= j)
f23fc77 combine-diff: use built-in xdiff.
Junio C Hamano authored
692 combine_diff(elem->parent[i].sha1, &result_file, sline,
f16706c combine-diff: show parent line numbers as well.
Junio C Hamano authored
693 cnt, i, num_parent);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
694 if (elem->parent[i].mode != elem->mode)
695 mode_differs = 1;
3c39e9b combine-diff: reuse diff from the same blob.
Junio C Hamano authored
696 }
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
697
8828cdc diff-tree --cc: squelch header generation on empty patch.
Junio C Hamano authored
698 show_hunks = make_hunks(sline, cnt, num_parent, dense);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
699
713a11f combine-diff: diff-files fix.
Junio C Hamano authored
700 if (show_hunks || mode_differs || working_tree_file) {
9843a1f combine-diff: do not send NULL to printf
Junio C Hamano authored
701 const char *abb;
702
9153983 Log message printout cleanups
Linus Torvalds authored
703 if (rev->loginfo)
704 show_log(rev, rev->loginfo, "\n");
eab144a Log message printout cleanups (#2)
Linus Torvalds authored
705 dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path);
823bcd6 combine-diff: fix placement of deletion.
Junio C Hamano authored
706 printf("index ");
707 for (i = 0; i < num_parent; i++) {
297a1aa find_unique_abbrev() simplification.
Junio C Hamano authored
708 abb = find_unique_abbrev(elem->parent[i].sha1,
e70c6b3 combine-diff: Honour --full-index.
Mark Wooding authored
709 abbrev);
9843a1f combine-diff: do not send NULL to printf
Junio C Hamano authored
710 printf("%s%s", i ? "," : "", abb);
823bcd6 combine-diff: fix placement of deletion.
Junio C Hamano authored
711 }
e70c6b3 combine-diff: Honour --full-index.
Mark Wooding authored
712 abb = find_unique_abbrev(elem->sha1, abbrev);
9843a1f combine-diff: do not send NULL to printf
Junio C Hamano authored
713 printf("..%s\n", abb);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
714
715 if (mode_differs) {
d416df8 combine-diff: Record diff status a bit more faithfully
Junio C Hamano authored
716 int added = !!elem->mode;
717 for (i = 0; added && i < num_parent; i++)
718 if (elem->parent[i].status !=
719 DIFF_STATUS_ADDED)
720 added = 0;
721 if (added)
722 printf("new file mode %06o", elem->mode);
723 else {
724 if (!elem->mode)
725 printf("deleted file ");
726 printf("mode ");
727 for (i = 0; i < num_parent; i++) {
728 printf("%s%06o", i ? "," : "",
729 elem->parent[i].mode);
730 }
731 if (elem->mode)
732 printf("..%06o", elem->mode);
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
733 }
d416df8 combine-diff: Record diff status a bit more faithfully
Junio C Hamano authored
734 putchar('\n');
2454c96 combine-diff: show mode changes as well.
Junio C Hamano authored
735 }
eab144a Log message printout cleanups (#2)
Linus Torvalds authored
736 dump_quoted_path("--- a/", elem->path);
737 dump_quoted_path("+++ b/", elem->path);
8828cdc diff-tree --cc: squelch header generation on empty patch.
Junio C Hamano authored
738 dump_sline(sline, cnt, num_parent);
739 }
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
740 free(result);
741
742 for (i = 0; i < cnt; i++) {
743 if (sline[i].lost_head) {
744 struct lline *ll = sline[i].lost_head;
745 while (ll) {
746 struct lline *tmp = ll;
747 ll = ll->next;
748 free(tmp);
749 }
750 }
751 }
46dc941 combine-diff: cleanup.
Junio C Hamano authored
752 free(sline[0].p_lno);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
753 free(sline);
8828cdc diff-tree --cc: squelch header generation on empty patch.
Junio C Hamano authored
754 return shown_header;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
755 }
756
ee63802 diff-tree -c raw output
Linus Torvalds authored
757 #define COLONS "::::::::::::::::::::::::::::::::"
758
9153983 Log message printout cleanups
Linus Torvalds authored
759 static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev)
ee63802 diff-tree -c raw output
Linus Torvalds authored
760 {
9153983 Log message printout cleanups
Linus Torvalds authored
761 struct diff_options *opt = &rev->diffopt;
310f8b5 cleanups: Remove unused vars from combine-diff.c
Serge E. Hallyn authored
762 int i, offset;
ee63802 diff-tree -c raw output
Linus Torvalds authored
763 const char *prefix;
764 int line_termination, inter_name_termination;
765
766 line_termination = opt->line_termination;
767 inter_name_termination = '\t';
768 if (!line_termination)
769 inter_name_termination = 0;
770
9153983 Log message printout cleanups
Linus Torvalds authored
771 if (rev->loginfo)
772 show_log(rev, rev->loginfo, "\n");
ee63802 diff-tree -c raw output
Linus Torvalds authored
773
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
774 if (opt->output_format == DIFF_FORMAT_RAW) {
775 offset = strlen(COLONS) - num_parent;
776 if (offset < 0)
777 offset = 0;
778 prefix = COLONS + offset;
779
780 /* Show the modes */
781 for (i = 0; i < num_parent; i++) {
782 printf("%s%06o", prefix, p->parent[i].mode);
783 prefix = " ";
784 }
785 printf("%s%06o", prefix, p->mode);
786
787 /* Show sha1's */
788 for (i = 0; i < num_parent; i++)
789 printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
790 opt->abbrev));
791 printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
792 }
793
794 if (opt->output_format == DIFF_FORMAT_RAW ||
d416df8 combine-diff: Record diff status a bit more faithfully
Junio C Hamano authored
795 opt->output_format == DIFF_FORMAT_NAME_STATUS) {
796 for (i = 0; i < num_parent; i++)
797 putchar(p->parent[i].status);
798 putchar(inter_name_termination);
799 }
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
800
801 if (line_termination) {
802 if (quote_c_style(p->path, NULL, NULL, 0))
803 quote_c_style(p->path, NULL, stdout, 0);
804 else
805 printf("%s", p->path);
806 putchar(line_termination);
807 }
808 else {
809 printf("%s%c", p->path, line_termination);
ee63802 diff-tree -c raw output
Linus Torvalds authored
810 }
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
811 }
812
9153983 Log message printout cleanups
Linus Torvalds authored
813 void show_combined_diff(struct combine_diff_path *p,
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
814 int num_parent,
815 int dense,
9153983 Log message printout cleanups
Linus Torvalds authored
816 struct rev_info *rev)
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
817 {
9153983 Log message printout cleanups
Linus Torvalds authored
818 struct diff_options *opt = &rev->diffopt;
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
819 if (!p->len)
9153983 Log message printout cleanups
Linus Torvalds authored
820 return;
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
821 switch (opt->output_format) {
822 case DIFF_FORMAT_RAW:
823 case DIFF_FORMAT_NAME_STATUS:
824 case DIFF_FORMAT_NAME:
9153983 Log message printout cleanups
Linus Torvalds authored
825 show_raw_diff(p, num_parent, rev);
826 return;
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
827 case DIFF_FORMAT_PATCH:
9153983 Log message printout cleanups
Linus Torvalds authored
828 show_patch_diff(p, num_parent, dense, rev);
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
829 return;
830 default:
831 return;
0a79807 combine-diff: move formatting logic to show_combined_diff()
Junio C Hamano authored
832 }
ee63802 diff-tree -c raw output
Linus Torvalds authored
833 }
834
0fe7c1d built-in diff: assorted updates.
Junio C Hamano authored
835 void diff_tree_combined(const unsigned char *sha1,
836 const unsigned char parent[][20],
837 int num_parent,
838 int dense,
839 struct rev_info *rev)
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
840 {
9153983 Log message printout cleanups
Linus Torvalds authored
841 struct diff_options *opt = &rev->diffopt;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
842 struct diff_options diffopts;
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
843 struct combine_diff_path *p, *paths = NULL;
0fe7c1d built-in diff: assorted updates.
Junio C Hamano authored
844 int i, num_paths;
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
845 int do_diffstat;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
846
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
847 do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
848 opt->with_stat);
5b23683 combined-diff: use diffcore before intersecting paths.
Junio C Hamano authored
849 diffopts = *opt;
86ff1d2 diff-* --patch-with-raw
Junio C Hamano authored
850 diffopts.with_raw = 0;
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
851 diffopts.with_stat = 0;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
852 diffopts.recursive = 1;
853
854 /* find set of paths that everybody touches */
0fe7c1d built-in diff: assorted updates.
Junio C Hamano authored
855 for (i = 0; i < num_parent; i++) {
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
856 /* show stat against the first parent even
857 * when doing combined diff.
858 */
859 if (i == 0 && do_diffstat)
860 diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
861 else
862 diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
0fe7c1d built-in diff: assorted updates.
Junio C Hamano authored
863 diff_tree_sha1(parent[i], sha1, "", &diffopts);
5b23683 combined-diff: use diffcore before intersecting paths.
Junio C Hamano authored
864 diffcore_std(&diffopts);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
865 paths = intersect_paths(paths, i, num_parent);
eab144a Log message printout cleanups (#2)
Linus Torvalds authored
866
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
867 if (do_diffstat && rev->loginfo)
868 show_log(rev, rev->loginfo,
869 opt->with_stat ? "---\n" : "\n");
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
870 diff_flush(&diffopts);
965f803 combine-diff: show diffstat with the first parent.
Junio C Hamano authored
871 if (opt->with_stat)
872 putchar('\n');
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
873 }
874
875 /* find out surviving paths */
876 for (num_paths = 0, p = paths; p; p = p->next) {
877 if (p->len)
878 num_paths++;
879 }
e3c3a55 combine-diff: remove misguided --show-empty hack.
Junio C Hamano authored
880 if (num_paths) {
86ff1d2 diff-* --patch-with-raw
Junio C Hamano authored
881 if (opt->with_raw) {
882 int saved_format = opt->output_format;
883 opt->output_format = DIFF_FORMAT_RAW;
884 for (p = paths; p; p = p->next) {
9153983 Log message printout cleanups
Linus Torvalds authored
885 show_combined_diff(p, num_parent, dense, rev);
86ff1d2 diff-* --patch-with-raw
Junio C Hamano authored
886 }
887 opt->output_format = saved_format;
90c1b08 Separate the raw diff and patch with a newline
Petr Baudis authored
888 putchar(opt->line_termination);
86ff1d2 diff-* --patch-with-raw
Junio C Hamano authored
889 }
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
890 for (p = paths; p; p = p->next) {
9153983 Log message printout cleanups
Linus Torvalds authored
891 show_combined_diff(p, num_parent, dense, rev);
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
892 }
893 }
894
895 /* Clean things up */
896 while (paths) {
ea726d0 diff-files: -c and --cc options.
Junio C Hamano authored
897 struct combine_diff_path *tmp = paths;
af3feef diff-tree -c: show a merge commit a bit more sensibly.
Junio C Hamano authored
898 paths = paths->next;
899 free(tmp);
900 }
901 }
0fe7c1d built-in diff: assorted updates.
Junio C Hamano authored
902
903 void diff_tree_combined_merge(const unsigned char *sha1,
904 int dense, struct rev_info *rev)
905 {
906 int num_parent;
907 const unsigned char (*parent)[20];
908 struct commit *commit = lookup_commit(sha1);
909 struct commit_list *parents;
910
911 /* count parents */
912 for (parents = commit->parents, num_parent = 0;
913 parents;
914 parents = parents->next, num_parent++)
915 ; /* nothing */
916
917 parent = xmalloc(num_parent * sizeof(*parent));
918 for (parents = commit->parents, num_parent = 0;
919 parents;
920 parents = parents->next, num_parent++)
921 memcpy(parent + num_parent, parents->item->object.sha1, 20);
922 diff_tree_combined(sha1, parent, num_parent, dense, rev);
923 }
Something went wrong with that request. Please try again.