Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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