git-log --cherry-pick A...B
This is meant to be a saner replacement for "git-cherry". When used with "A...B", this filters out commits whose patch text has the same patch-id as a commit on the other side. It would probably most useful to use with --left-right. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 9, 2007 at 03:40 UTC
d7a17cad9798693dc31043aa4efcce0b207483b9
2 files changed
+89
revision.c
+88
@@ -8,6 +8,7 @@
8
#include "revision.h"
9
#include "grep.h"
10
#include "reflog-walk.h"
11
+#include "patch-ids.h"
12
13
static char *path_name(struct name_path *path, const char *name)
14
{
@@ -422,6 +423,86 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
423
}
424
}
425
426
+static void cherry_pick_list(struct commit_list *list)
427
+{
428
+ struct commit_list *p;
429
+ int left_count = 0, right_count = 0;
430
+ int left_first;
431
+ struct patch_ids ids;
432
+
433
+ /* First count the commits on the left and on the right */
434
+ for (p = list; p; p = p->next) {
435
+ struct commit *commit = p->item;
436
+ unsigned flags = commit->object.flags;
437
+ if (flags & BOUNDARY)
438
+ ;
439
+ else if (flags & SYMMETRIC_LEFT)
440
+ left_count++;
441
+ else
442
+ right_count++;
443
+ }
444
+
445
+ left_first = left_count < right_count;
446
+ init_patch_ids(&ids);
447
+
448
+ /* Compute patch-ids for one side */
449
+ for (p = list; p; p = p->next) {
450
+ struct commit *commit = p->item;
451
+ unsigned flags = commit->object.flags;
452
+
453
+ if (flags & BOUNDARY)
454
+ continue;
455
+ /*
456
+ * If we have fewer left, left_first is set and we omit
457
+ * commits on the right branch in this loop. If we have
458
+ * fewer right, we skip the left ones.
459
+ */
460
+ if (left_first != !!(flags & SYMMETRIC_LEFT))
461
+ continue;
462
+ commit->util = add_commit_patch_id(commit, &ids);
463
+ }
464
+
465
+ /* Check the other side */
466
+ for (p = list; p; p = p->next) {
467
+ struct commit *commit = p->item;
468
+ struct patch_id *id;
469
+ unsigned flags = commit->object.flags;
470
+
471
+ if (flags & BOUNDARY)
472
+ continue;
473
+ /*
474
+ * If we have fewer left, left_first is set and we omit
475
+ * commits on the left branch in this loop.
476
+ */
477
+ if (left_first == !!(flags & SYMMETRIC_LEFT))
478
+ continue;
479
+
480
+ /*
481
+ * Have we seen the same patch id?
482
+ */
483
+ id = has_commit_patch_id(commit, &ids);
484
+ if (!id)
485
+ continue;
486
+ id->seen = 1;
487
+ commit->object.flags |= SHOWN;
488
+ }
489
+
490
+ /* Now check the original side for seen ones */
491
+ for (p = list; p; p = p->next) {
492
+ struct commit *commit = p->item;
493
+ struct patch_id *ent;
494
+
495
+ ent = commit->util;
496
+ if (!ent)
497
+ continue;
498
+ if (ent->seen)
499
+ commit->object.flags |= SHOWN;
500
+ commit->util = NULL;
501
+ }
502
+
503
+ free_patch_ids(&ids);
504
+}
505
+
506
static void limit_list(struct rev_info *revs)
507
{
508
struct commit_list *list = revs->commits;
@@ -449,6 +530,9 @@ static void limit_list(struct rev_info *revs)
530
continue;
531
p = &commit_list_insert(commit, p)->next;
532
}
533
+ if (revs->cherry_pick)
534
+ cherry_pick_list(newlist);
535
+
536
revs->commits = newlist;
537
}
538
@@ -913,6 +997,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
997
revs->left_right = 1;
998
continue;
999
}
1000
+ if (!strcmp(arg, "--cherry-pick")) {
1001
+ revs->cherry_pick = 1;
1002
+ continue;
1003
+ }
1004
if (!strcmp(arg, "--objects")) {
1005
revs->tag_objects = 1;
1006
revs->tree_objects = 1;
revision.h
+1
@@ -47,6 +47,7 @@ struct rev_info {
47
left_right:1,
48
parents:1,
49
reverse:1,
50
+ cherry_pick:1,
51
first_parent_only:1;
52
53
/* Diff flags */