Skip to content

HTTPS clone URL

Subversion checkout URL

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