5
#include "tree.h"
6
#include "blob.h"
7
#include "epoch.h"
8
+#include "diff.h"
9
10
#define SEEN (1u << 0)
11
#define INTERESTING (1u << 1)
45
static int stop_traversal = 0;
46
static int topo_order = 0;
47
static int no_merges = 0;
48
+static const char **paths = NULL;
49
50
static void show_commit(struct commit *commit)
51
{
379
}
380
}
381
382
+static int is_different = 0;
383
+
384
+static void file_add_remove(struct diff_options *options,
385
+ int addremove, unsigned mode,
386
+ const unsigned char *sha1,
387
+ const char *base, const char *path)
388
+{
389
+ is_different = 1;
390
+}
391
+
392
+static void file_change(struct diff_options *options,
393
+ unsigned old_mode, unsigned new_mode,
394
+ const unsigned char *old_sha1,
395
+ const unsigned char *new_sha1,
396
+ const char *base, const char *path)
397
+{
398
+ is_different = 1;
399
+}
400
+
401
+static struct diff_options diff_opt = {
402
+ .recursive = 1,
403
+ .add_remove = file_add_remove,
404
+ .change = file_change,
405
+};
406
+
407
+static struct commit *try_to_simplify_merge(struct commit *commit, struct commit_list *parent)
408
+{
409
+ if (!commit->tree)
410
+ return NULL;
411
+
412
+ while (parent) {
413
+ struct commit *p = parent->item;
414
+ parent = parent->next;
415
+ parse_commit(p);
416
+ if (!p->tree)
417
+ continue;
418
+ is_different = 0;
419
+ if (diff_tree_sha1(commit->tree->object.sha1,
420
+ p->tree->object.sha1, "", &diff_opt) < 0)
421
+ continue;
422
+ if (!is_different)
423
+ return p;
424
+ }
425
+ return NULL;
426
+}
427
+
428
+static void add_parents_to_list(struct commit *commit, struct commit_list **list)
429
+{
430
+ struct commit_list *parent = commit->parents;
431
+
432
+ /*
433
+ * If the commit is uninteresting, don't try to
434
+ * prune parents - we want the maximal uninteresting
435
+ * set.
436
+ *
437
+ * Normally we haven't parsed the parent
438
+ * yet, so we won't have a parent of a parent
439
+ * here. However, it may turn out that we've
440
+ * reached this commit some other way (where it
441
+ * wasn't uninteresting), in which case we need
442
+ * to mark its parents recursively too..
443
+ */
444
+ if (commit->object.flags & UNINTERESTING) {
445
+ while (parent) {
446
+ struct commit *p = parent->item;
447
+ parent = parent->next;
448
+ parse_commit(p);
449
+ p->object.flags |= UNINTERESTING;
450
+ if (p->parents)
451
+ mark_parents_uninteresting(p);
452
+ if (p->object.flags & SEEN)
453
+ continue;
454
+ p->object.flags |= SEEN;
455
+ insert_by_date(p, list);
456
+ }
457
+ return;
458
+ }
459
+
460
+ /*
461
+ * Ok, the commit wasn't uninteresting. If it
462
+ * is a merge, try to find the parent that has
463
+ * no differences in the path set if one exists.
464
+ */
465
+ if (paths && parent && parent->next) {
466
+ struct commit *preferred;
467
+
468
+ preferred = try_to_simplify_merge(commit, parent);
469
+ if (preferred) {
470
+ parent->item = preferred;
471
+ parent->next = NULL;
472
+ }
473
+ }
474
+
475
+ while (parent) {
476
+ struct commit *p = parent->item;
477
+
478
+ parent = parent->next;
479
+
480
+ parse_commit(p);
481
+ if (p->object.flags & SEEN)
482
+ continue;
483
+ p->object.flags |= SEEN;
484
+ insert_by_date(p, list);
485
+ }
486
+}
487
+
488
static struct commit_list *limit_list(struct commit_list *list)
489
{
490
struct commit_list *newlist = NULL;
491
struct commit_list **p = &newlist;
492
while (list) {
385
- struct commit *commit = pop_most_recent_commit(&list, SEEN);
493
+ struct commit_list *entry = list;
494
+ struct commit *commit = list->item;
495
struct object *obj = &commit->object;
496
497
+ list = list->next;
498
+ free(entry);
499
+
500
if (max_age != -1 && (commit->date < max_age))
501
obj->flags |= UNINTERESTING;
502
if (unpacked && has_sha1_pack(obj->sha1))
503
obj->flags |= UNINTERESTING;
504
+ add_parents_to_list(commit, &list);
505
if (obj->flags & UNINTERESTING) {
506
mark_parents_uninteresting(commit);
507
if (everybody_uninteresting(list))
620
global_lst = NULL;
621
}
622
510
-int main(int argc, char **argv)
623
+int main(int argc, const char **argv)
624
{
625
+ const char *prefix = setup_git_directory();
626
struct commit_list *list = NULL;
627
int i, limited = 0;
628
515
- setup_git_directory();
629
for (i = 1 ; i < argc; i++) {
630
int flags;
518
- char *arg = argv[i];
631
+ const char *arg = argv[i];
632
char *dotdot;
633
struct commit *commit;
634
700
limited = 1;
701
continue;
702
}
703
+ if (!strcmp(arg, "--")) {
704
+ paths = get_pathspec(prefix, argv + i + 1);
705
+ if (paths) {
706
+ limited = 1;
707
+ diff_tree_setup_paths(paths);
708
+ }
709
+ break;
710
+ }
711
712
if (show_breaks && !merge_order)
713
usage(rev_list_usage);