]> git.ipfire.org Git - thirdparty/git.git/blame - range-diff.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / range-diff.c
CommitLineData
d9c66f0b 1#include "cache.h"
32a8f510 2#include "environment.h"
f394e093 3#include "gettext.h"
d9c66f0b 4#include "range-diff.h"
dabab1d6 5#include "object-name.h"
d9c66f0b
JS
6#include "string-list.h"
7#include "run-command.h"
dbbcd44f 8#include "strvec.h"
d9c66f0b
JS
9#include "hashmap.h"
10#include "xdiff-interface.h"
11#include "linear-assignment.h"
c8c5e43a 12#include "diffcore.h"
eb0be38c
JS
13#include "commit.h"
14#include "pretty.h"
4eba1fe6 15#include "userdiff.h"
b66885a3 16#include "apply.h"
359f0d75 17#include "revision.h"
d9c66f0b
JS
18
19struct patch_util {
20 /* For the search for an exact match */
21 struct hashmap_entry e;
22 const char *diff, *patch;
23
9dc46e02 24 int i, shown;
d9c66f0b
JS
25 int diffsize;
26 size_t diff_offset;
27 /* the index of the matching item in the other branch, or -1 */
28 int matching;
29 struct object_id oid;
30};
31
32/*
33 * Reads the patches into a string list, with the `util` field being populated
34 * as struct object_id (will need to be free()d).
35 */
bd361918 36static int read_patches(const char *range, struct string_list *list,
c972bf4c 37 const struct strvec *other_arg)
d9c66f0b
JS
38{
39 struct child_process cp = CHILD_PROCESS_INIT;
44b67cb6 40 struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
d9c66f0b
JS
41 struct patch_util *util = NULL;
42 int in_header = 1;
444e0969 43 char *line, *current_filename = NULL;
c4d59073 44 ssize_t len;
44b67cb6 45 size_t size;
2d102c2b 46 int ret = -1;
d9c66f0b 47
c972bf4c 48 strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
f6d8942b 49 "--reverse", "--date-order", "--decorate=no",
04b1f1fd 50 "--no-prefix", "--submodule=short",
f6d8942b
JK
51 /*
52 * Choose indicators that are not used anywhere
53 * else in diffs, but still look reasonable
54 * (e.g. will not be confusing when debugging)
55 */
56 "--output-indicator-new=>",
57 "--output-indicator-old=<",
58 "--output-indicator-context=#",
59 "--no-abbrev-commit",
60 "--pretty=medium",
61 "--notes",
62 NULL);
b7574782 63 strvec_push(&cp.args, range);
bd361918 64 if (other_arg)
d70a9eb6 65 strvec_pushv(&cp.args, other_arg->v);
d9c66f0b
JS
66 cp.out = -1;
67 cp.no_stdin = 1;
68 cp.git_cmd = 1;
69
70 if (start_command(&cp))
71 return error_errno(_("could not start `log`"));
44b67cb6 72 if (strbuf_read(&contents, cp.out, 0) < 0) {
d9c66f0b
JS
73 error_errno(_("could not read `log` output"));
74 finish_command(&cp);
2d102c2b 75 goto cleanup;
d9c66f0b 76 }
5189bb87 77 if (finish_command(&cp))
2d102c2b 78 goto cleanup;
d9c66f0b 79
44b67cb6
TG
80 line = contents.buf;
81 size = contents.len;
47ac23d3 82 for (; size > 0; size -= len, line += len) {
d9c66f0b 83 const char *p;
7c86d365
JK
84 char *eol;
85
86 eol = memchr(line, '\n', size);
87 if (eol) {
88 *eol = '\0';
89 len = eol + 1 - line;
90 } else {
91 len = size;
92 }
d9c66f0b 93
44b67cb6 94 if (skip_prefix(line, "commit ", &p)) {
d9c66f0b
JS
95 if (util) {
96 string_list_append(list, buf.buf)->util = util;
97 strbuf_reset(&buf);
98 }
ca56dadb 99 CALLOC_ARRAY(util, 1);
d850b7a5 100 if (repo_get_oid(the_repository, p, &util->oid)) {
d9c66f0b 101 error(_("could not parse commit '%s'"), p);
2d102c2b 102 FREE_AND_NULL(util);
d9c66f0b 103 string_list_clear(list, 1);
2d102c2b 104 goto cleanup;
d9c66f0b
JS
105 }
106 util->matching = -1;
107 in_header = 1;
108 continue;
109 }
110
8cf51561
VD
111 if (!util) {
112 error(_("could not parse first line of `log` output: "
113 "did not start with 'commit ': '%s'"),
114 line);
115 string_list_clear(list, 1);
2d102c2b 116 goto cleanup;
8cf51561
VD
117 }
118
44b67cb6 119 if (starts_with(line, "diff --git")) {
b66885a3
TG
120 struct patch patch = { 0 };
121 struct strbuf root = STRBUF_INIT;
122 int linenr = 0;
8d1675eb 123 int orig_len;
b66885a3 124
d9c66f0b
JS
125 in_header = 0;
126 strbuf_addch(&buf, '\n');
127 if (!util->diff_offset)
128 util->diff_offset = buf.len;
7c86d365
JK
129 if (eol)
130 *eol = '\n';
8d1675eb 131 orig_len = len;
937b76ed 132 len = parse_git_diff_header(&root, &linenr, 0, line,
b66885a3 133 len, size, &patch);
a2d474ad
JS
134 if (len < 0) {
135 error(_("could not parse git header '%.*s'"),
136 orig_len, line);
2d102c2b 137 FREE_AND_NULL(util);
a2d474ad 138 string_list_clear(list, 1);
2d102c2b 139 goto cleanup;
a2d474ad 140 }
b66885a3
TG
141 strbuf_addstr(&buf, " ## ");
142 if (patch.is_new > 0)
143 strbuf_addf(&buf, "%s (new)", patch.new_name);
144 else if (patch.is_delete > 0)
145 strbuf_addf(&buf, "%s (deleted)", patch.old_name);
146 else if (patch.is_rename)
147 strbuf_addf(&buf, "%s => %s", patch.old_name, patch.new_name);
148 else
149 strbuf_addstr(&buf, patch.new_name);
150
444e0969
TG
151 free(current_filename);
152 if (patch.is_delete > 0)
153 current_filename = xstrdup(patch.old_name);
154 else
155 current_filename = xstrdup(patch.new_name);
156
b66885a3
TG
157 if (patch.new_mode && patch.old_mode &&
158 patch.old_mode != patch.new_mode)
159 strbuf_addf(&buf, " (mode change %06o => %06o)",
160 patch.old_mode, patch.new_mode);
161
162 strbuf_addstr(&buf, " ##");
4998e93f 163 release_patch(&patch);
d9c66f0b 164 } else if (in_header) {
44b67cb6 165 if (starts_with(line, "Author: ")) {
499352c2 166 strbuf_addstr(&buf, " ## Metadata ##\n");
44b67cb6 167 strbuf_addstr(&buf, line);
d9c66f0b 168 strbuf_addstr(&buf, "\n\n");
499352c2 169 strbuf_addstr(&buf, " ## Commit message ##\n");
9f726e1b
DL
170 } else if (starts_with(line, "Notes") &&
171 line[strlen(line) - 1] == ':') {
172 strbuf_addstr(&buf, "\n\n");
173 /* strip the trailing colon */
174 strbuf_addf(&buf, " ## %.*s ##\n",
175 (int)(strlen(line) - 1), line);
44b67cb6
TG
176 } else if (starts_with(line, " ")) {
177 p = line + len - 2;
178 while (isspace(*p) && p >= line)
179 p--;
180 strbuf_add(&buf, line, p - line + 1);
d9c66f0b
JS
181 strbuf_addch(&buf, '\n');
182 }
183 continue;
e1db2630
TG
184 } else if (skip_prefix(line, "@@ ", &p)) {
185 p = strstr(p, "@@");
444e0969
TG
186 strbuf_addstr(&buf, "@@");
187 if (current_filename && p[2])
188 strbuf_addf(&buf, " %s:", current_filename);
189 if (p)
190 strbuf_addstr(&buf, p + 2);
b66885a3 191 } else if (!line[0])
d9c66f0b
JS
192 /*
193 * A completely blank (not ' \n', which is context)
194 * line is not valid in a diff. We skip it
195 * silently, because this neatly handles the blank
196 * separator line between commits in git-log
197 * output.
d9c66f0b
JS
198 */
199 continue;
44b67cb6 200 else if (line[0] == '>') {
8d5ccb59 201 strbuf_addch(&buf, '+');
44b67cb6
TG
202 strbuf_addstr(&buf, line + 1);
203 } else if (line[0] == '<') {
8d5ccb59 204 strbuf_addch(&buf, '-');
44b67cb6
TG
205 strbuf_addstr(&buf, line + 1);
206 } else if (line[0] == '#') {
8d5ccb59 207 strbuf_addch(&buf, ' ');
44b67cb6 208 strbuf_addstr(&buf, line + 1);
8d5ccb59 209 } else {
2543a641 210 strbuf_addch(&buf, ' ');
44b67cb6 211 strbuf_addstr(&buf, line);
8d5ccb59 212 }
d9c66f0b
JS
213
214 strbuf_addch(&buf, '\n');
215 util->diffsize++;
216 }
2d102c2b
ÆAB
217
218 ret = 0;
219cleanup:
44b67cb6 220 strbuf_release(&contents);
d9c66f0b
JS
221
222 if (util)
223 string_list_append(list, buf.buf)->util = util;
224 strbuf_release(&buf);
444e0969 225 free(current_filename);
d9c66f0b 226
2d102c2b 227 return ret;
d9c66f0b
JS
228}
229
5cf88fd8 230static int patch_util_cmp(const void *cmp_data UNUSED,
02c3c59e
JK
231 const struct patch_util *a,
232 const struct patch_util *b,
233 const char *keydata)
d9c66f0b
JS
234{
235 return strcmp(a->diff, keydata ? keydata : b->diff);
236}
237
238static void find_exact_matches(struct string_list *a, struct string_list *b)
239{
b19315d8 240 struct hashmap map = HASHMAP_INIT((hashmap_cmp_fn)patch_util_cmp, NULL);
d9c66f0b
JS
241 int i;
242
d9c66f0b
JS
243 /* First, add the patches of a to a hash map */
244 for (i = 0; i < a->nr; i++) {
245 struct patch_util *util = a->items[i].util;
246
247 util->i = i;
248 util->patch = a->items[i].string;
249 util->diff = util->patch + util->diff_offset;
d22245a2 250 hashmap_entry_init(&util->e, strhash(util->diff));
b94e5c1d 251 hashmap_add(&map, &util->e);
d9c66f0b
JS
252 }
253
254 /* Now try to find exact matches in b */
255 for (i = 0; i < b->nr; i++) {
256 struct patch_util *util = b->items[i].util, *other;
257
258 util->i = i;
259 util->patch = b->items[i].string;
260 util->diff = util->patch + util->diff_offset;
d22245a2 261 hashmap_entry_init(&util->e, strhash(util->diff));
404ab78e 262 other = hashmap_remove_entry(&map, util, e, NULL);
d9c66f0b
JS
263 if (other) {
264 if (other->matching >= 0)
265 BUG("already assigned!");
266
267 other->matching = i;
268 util->matching = other->i;
269 }
270 }
271
6da1a258 272 hashmap_clear(&map);
d9c66f0b
JS
273}
274
61bdc7c5
JK
275static int diffsize_consume(void *data,
276 char *line UNUSED,
277 unsigned long len UNUSED)
d9c66f0b
JS
278{
279 (*(int *)data)++;
a8d5eb6d 280 return 0;
d9c66f0b
JS
281}
282
61bdc7c5
JK
283static void diffsize_hunk(void *data,
284 long ob UNUSED, long on UNUSED,
285 long nb UNUSED, long nn UNUSED,
286 const char *func UNUSED, long funclen UNUSED)
d2eb8093
JK
287{
288 diffsize_consume(data, NULL, 0);
289}
290
d9c66f0b
JS
291static int diffsize(const char *a, const char *b)
292{
293 xpparam_t pp = { 0 };
294 xdemitconf_t cfg = { 0 };
295 mmfile_t mf1, mf2;
296 int count = 0;
297
298 mf1.ptr = (char *)a;
299 mf1.size = strlen(a);
300 mf2.ptr = (char *)b;
301 mf2.size = strlen(b);
302
303 cfg.ctxlen = 3;
d2eb8093
JK
304 if (!xdi_diff_outf(&mf1, &mf2,
305 diffsize_hunk, diffsize_consume, &count,
306 &pp, &cfg))
d9c66f0b
JS
307 return count;
308
309 error(_("failed to generate diff"));
310 return COST_MAX;
311}
312
313static void get_correspondences(struct string_list *a, struct string_list *b,
314 int creation_factor)
315{
316 int n = a->nr + b->nr;
317 int *cost, c, *a2b, *b2a;
318 int i, j;
319
320 ALLOC_ARRAY(cost, st_mult(n, n));
321 ALLOC_ARRAY(a2b, n);
322 ALLOC_ARRAY(b2a, n);
323
324 for (i = 0; i < a->nr; i++) {
325 struct patch_util *a_util = a->items[i].util;
326
327 for (j = 0; j < b->nr; j++) {
328 struct patch_util *b_util = b->items[j].util;
329
330 if (a_util->matching == j)
331 c = 0;
332 else if (a_util->matching < 0 && b_util->matching < 0)
333 c = diffsize(a_util->diff, b_util->diff);
334 else
335 c = COST_MAX;
336 cost[i + n * j] = c;
337 }
338
339 c = a_util->matching < 0 ?
340 a_util->diffsize * creation_factor / 100 : COST_MAX;
341 for (j = b->nr; j < n; j++)
342 cost[i + n * j] = c;
343 }
344
345 for (j = 0; j < b->nr; j++) {
346 struct patch_util *util = b->items[j].util;
347
348 c = util->matching < 0 ?
349 util->diffsize * creation_factor / 100 : COST_MAX;
350 for (i = a->nr; i < n; i++)
351 cost[i + n * j] = c;
352 }
353
354 for (i = a->nr; i < n; i++)
355 for (j = b->nr; j < n; j++)
356 cost[i + n * j] = 0;
357
358 compute_assignment(n, n, cost, a2b, b2a);
359
360 for (i = 0; i < a->nr; i++)
361 if (a2b[i] >= 0 && a2b[i] < b->nr) {
362 struct patch_util *a_util = a->items[i].util;
363 struct patch_util *b_util = b->items[a2b[i]].util;
364
365 a_util->matching = a2b[i];
366 b_util->matching = i;
367 }
368
369 free(cost);
370 free(a2b);
371 free(b2a);
372}
373
faa1df86 374static void output_pair_header(struct diff_options *diffopt,
d1f87a2d 375 int patch_no_width,
faa1df86 376 struct strbuf *buf,
eb0be38c
JS
377 struct strbuf *dashes,
378 struct patch_util *a_util,
379 struct patch_util *b_util)
d9c66f0b 380{
eb0be38c
JS
381 struct object_id *oid = a_util ? &a_util->oid : &b_util->oid;
382 struct commit *commit;
faa1df86
JS
383 char status;
384 const char *color_reset = diff_get_color_opt(diffopt, DIFF_RESET);
385 const char *color_old = diff_get_color_opt(diffopt, DIFF_FILE_OLD);
386 const char *color_new = diff_get_color_opt(diffopt, DIFF_FILE_NEW);
387 const char *color_commit = diff_get_color_opt(diffopt, DIFF_COMMIT);
388 const char *color;
d9165bef 389 int abbrev = diffopt->abbrev;
2b15969f
TL
390
391 if (abbrev < 0)
392 abbrev = DEFAULT_ABBREV;
eb0be38c
JS
393
394 if (!dashes->len)
395 strbuf_addchars(dashes, '-',
d850b7a5 396 strlen(repo_find_unique_abbrev(the_repository, oid, abbrev)));
eb0be38c 397
faa1df86
JS
398 if (!b_util) {
399 color = color_old;
400 status = '<';
401 } else if (!a_util) {
402 color = color_new;
403 status = '>';
404 } else if (strcmp(a_util->patch, b_util->patch)) {
405 color = color_commit;
406 status = '!';
407 } else {
408 color = color_commit;
409 status = '=';
410 }
411
eb0be38c 412 strbuf_reset(buf);
faa1df86 413 strbuf_addstr(buf, status == '!' ? color_old : color);
eb0be38c 414 if (!a_util)
d1f87a2d 415 strbuf_addf(buf, "%*s: %s ", patch_no_width, "-", dashes->buf);
eb0be38c 416 else
d1f87a2d 417 strbuf_addf(buf, "%*d: %s ", patch_no_width, a_util->i + 1,
d850b7a5 418 repo_find_unique_abbrev(the_repository, &a_util->oid, abbrev));
eb0be38c 419
faa1df86
JS
420 if (status == '!')
421 strbuf_addf(buf, "%s%s", color_reset, color);
422 strbuf_addch(buf, status);
423 if (status == '!')
424 strbuf_addf(buf, "%s%s", color_reset, color_new);
eb0be38c
JS
425
426 if (!b_util)
d1f87a2d 427 strbuf_addf(buf, " %*s: %s", patch_no_width, "-", dashes->buf);
eb0be38c 428 else
d1f87a2d 429 strbuf_addf(buf, " %*d: %s", patch_no_width, b_util->i + 1,
d850b7a5 430 repo_find_unique_abbrev(the_repository, &b_util->oid, abbrev));
eb0be38c
JS
431
432 commit = lookup_commit_reference(the_repository, oid);
433 if (commit) {
faa1df86
JS
434 if (status == '!')
435 strbuf_addf(buf, "%s%s", color_reset, color);
436
eb0be38c
JS
437 strbuf_addch(buf, ' ');
438 pp_commit_easy(CMIT_FMT_ONELINE, commit, buf);
439 }
faa1df86 440 strbuf_addf(buf, "%s\n", color_reset);
eb0be38c 441
87f1b2d4 442 fwrite(buf->buf, buf->len, 1, diffopt->file);
d9c66f0b
JS
443}
444
499352c2
TG
445static struct userdiff_driver section_headers = {
446 .funcname = { "^ ## (.*) ##$\n"
447 "^.?@@ (.*)$", REG_EXTENDED }
4eba1fe6
JS
448};
449
c8c5e43a
JS
450static struct diff_filespec *get_filespec(const char *name, const char *p)
451{
452 struct diff_filespec *spec = alloc_filespec(name);
453
14228447 454 fill_filespec(spec, null_oid(), 0, 0100644);
c8c5e43a
JS
455 spec->data = (char *)p;
456 spec->size = strlen(p);
457 spec->should_munmap = 0;
458 spec->is_stdin = 1;
499352c2 459 spec->driver = &section_headers;
c8c5e43a
JS
460
461 return spec;
462}
463
464static void patch_diff(const char *a, const char *b,
1ca69225 465 struct diff_options *diffopt)
c8c5e43a
JS
466{
467 diff_queue(&diff_queued_diff,
468 get_filespec("a", a), get_filespec("b", b));
469
470 diffcore_std(diffopt);
471 diff_flush(diffopt);
472}
473
61bdc7c5 474static struct strbuf *output_prefix_cb(struct diff_options *opt UNUSED, void *data)
3e6046ed
JS
475{
476 return data;
477}
478
c8c5e43a 479static void output(struct string_list *a, struct string_list *b,
3e6046ed 480 struct range_diff_options *range_diff_opts)
d9c66f0b 481{
eb0be38c 482 struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT;
d1f87a2d 483 int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr));
9dc46e02 484 int i = 0, j = 0;
3e6046ed
JS
485 struct diff_options opts;
486 struct strbuf indent = STRBUF_INIT;
487
488 if (range_diff_opts->diffopt)
489 memcpy(&opts, range_diff_opts->diffopt, sizeof(opts));
490 else
08539032 491 repo_diff_setup(the_repository, &opts);
3e6046ed 492
709b3f32 493 opts.no_free = 1;
3e6046ed
JS
494 if (!opts.output_format)
495 opts.output_format = DIFF_FORMAT_PATCH;
496 opts.flags.suppress_diff_headers = 1;
497 opts.flags.dual_color_diffed_diffs =
498 range_diff_opts->dual_color;
499 opts.flags.suppress_hunk_header_line_count = 1;
500 opts.output_prefix = output_prefix_cb;
501 strbuf_addstr(&indent, " ");
502 opts.output_prefix_data = &indent;
503 diff_setup_done(&opts);
9dc46e02
JS
504
505 /*
506 * We assume the user is really more interested in the second argument
507 * ("newer" version). To that end, we print the output in the order of
508 * the RHS (the `b` parameter). To put the LHS (the `a` parameter)
509 * commits that are no longer in the RHS into a good place, we place
510 * them once we have shown all of their predecessors in the LHS.
511 */
512
513 while (i < a->nr || j < b->nr) {
514 struct patch_util *a_util, *b_util;
515 a_util = i < a->nr ? a->items[i].util : NULL;
516 b_util = j < b->nr ? b->items[j].util : NULL;
517
518 /* Skip all the already-shown commits from the LHS. */
519 while (i < a->nr && a_util->shown)
520 a_util = ++i < a->nr ? a->items[i].util : NULL;
521
522 /* Show unmatched LHS commit whose predecessors were shown. */
523 if (i < a->nr && a_util->matching < 0) {
1e79f973
JS
524 if (!range_diff_opts->right_only)
525 output_pair_header(&opts, patch_no_width,
faa1df86 526 &buf, &dashes, a_util, NULL);
9dc46e02
JS
527 i++;
528 continue;
529 }
d9c66f0b 530
9dc46e02
JS
531 /* Show unmatched RHS commits. */
532 while (j < b->nr && b_util->matching < 0) {
1e79f973
JS
533 if (!range_diff_opts->left_only)
534 output_pair_header(&opts, patch_no_width,
faa1df86 535 &buf, &dashes, NULL, b_util);
9dc46e02 536 b_util = ++j < b->nr ? b->items[j].util : NULL;
d9c66f0b 537 }
d9c66f0b 538
9dc46e02
JS
539 /* Show matching LHS/RHS pair. */
540 if (j < b->nr) {
541 a_util = a->items[b_util->matching].util;
3e6046ed 542 output_pair_header(&opts, patch_no_width,
faa1df86 543 &buf, &dashes, a_util, b_util);
3e6046ed 544 if (!(opts.output_format & DIFF_FORMAT_NO_OUTPUT))
c8c5e43a 545 patch_diff(a->items[b_util->matching].string,
3e6046ed 546 b->items[j].string, &opts);
9dc46e02
JS
547 a_util->shown = 1;
548 j++;
549 }
d9c66f0b 550 }
eb0be38c
JS
551 strbuf_release(&buf);
552 strbuf_release(&dashes);
3e6046ed 553 strbuf_release(&indent);
709b3f32
RS
554 opts.no_free = 0;
555 diff_free(&opts);
73a834e9
ES
556}
557
d9c66f0b 558int show_range_diff(const char *range1, const char *range2,
f1ce6c19 559 struct range_diff_options *range_diff_opts)
d9c66f0b
JS
560{
561 int res = 0;
562
563 struct string_list branch1 = STRING_LIST_INIT_DUP;
564 struct string_list branch2 = STRING_LIST_INIT_DUP;
565
1e79f973 566 if (range_diff_opts->left_only && range_diff_opts->right_only)
43ea635c 567 res = error(_("options '%s' and '%s' cannot be used together"), "--left-only", "--right-only");
1e79f973
JS
568
569 if (!res && read_patches(range1, &branch1, range_diff_opts->other_arg))
d9c66f0b 570 res = error(_("could not parse log for '%s'"), range1);
f1ce6c19 571 if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg))
d9c66f0b
JS
572 res = error(_("could not parse log for '%s'"), range2);
573
574 if (!res) {
575 find_exact_matches(&branch1, &branch2);
f1ce6c19
JS
576 get_correspondences(&branch1, &branch2,
577 range_diff_opts->creation_factor);
3e6046ed 578 output(&branch1, &branch2, range_diff_opts);
d9c66f0b
JS
579 }
580
581 string_list_clear(&branch1, 1);
582 string_list_clear(&branch2, 1);
583
584 return res;
585}
679b5916
JS
586
587int is_range_diff_range(const char *arg)
588{
359f0d75
JS
589 char *copy = xstrdup(arg); /* setup_revisions() modifies it */
590 const char *argv[] = { "", copy, "--", NULL };
591 int i, positive = 0, negative = 0;
592 struct rev_info revs;
593
035c7de9 594 repo_init_revisions(the_repository, &revs, NULL);
359f0d75
JS
595 if (setup_revisions(3, argv, &revs, NULL) == 1) {
596 for (i = 0; i < revs.pending.nr; i++)
597 if (revs.pending.objects[i].item->flags & UNINTERESTING)
598 negative++;
599 else
600 positive++;
601 for (i = 0; i < revs.pending.nr; i++) {
602 struct object *obj = revs.pending.objects[i].item;
603
604 if (obj->type == OBJ_COMMIT)
605 clear_commit_marks((struct commit *)obj,
606 ALL_REV_FLAGS);
607 }
608 }
609
610 free(copy);
1878b5ed 611 release_revisions(&revs);
359f0d75 612 return negative > 0 && positive > 0;
679b5916 613}