static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const char *prefix) { struct rev_info check_rev; struct commit *commit; struct object *o1, *o2; unsigned flags1, flags2; if (rev->pending.nr != 2) die("Need exactly one range."); o1 = rev->pending.objects[0].item; flags1 = o1->flags; o2 = rev->pending.objects[1].item; flags2 = o2->flags; if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die("Not a range."); init_patch_ids(ids); /* given a range a..b get all patch ids for b..a */ init_revisions(&check_rev, prefix); o1->flags ^= UNINTERESTING; o2->flags ^= UNINTERESTING; add_pending_object(&check_rev, o1, "o1"); add_pending_object(&check_rev, o2, "o2"); if (prepare_revision_walk(&check_rev)) die("revision walk setup failed"); while ((commit = get_revision(&check_rev)) != NULL) { /* ignore merges */ if (commit->parents && commit->parents->next) continue; add_commit_patch_id(commit, ids); } /* reset for next revision walk */ clear_commit_marks((struct commit *)o1, SEEN | UNINTERESTING | SHOWN | ADDED); clear_commit_marks((struct commit *)o2, SEEN | UNINTERESTING | SHOWN | ADDED); o1->flags = flags1; o2->flags = flags2; }
static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) { struct rev_info check_rev; struct commit *commit, *c1, *c2; struct object *o1, *o2; unsigned flags1, flags2; if (rev->pending.nr != 2) die(_("Need exactly one range.")); o1 = rev->pending.objects[0].item; o2 = rev->pending.objects[1].item; flags1 = o1->flags; flags2 = o2->flags; c1 = lookup_commit_reference(o1->oid.hash); c2 = lookup_commit_reference(o2->oid.hash); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); init_patch_ids(ids); /* given a range a..b get all patch ids for b..a */ init_revisions(&check_rev, rev->prefix); check_rev.max_parents = 1; o1->flags ^= UNINTERESTING; o2->flags ^= UNINTERESTING; add_pending_object(&check_rev, o1, "o1"); add_pending_object(&check_rev, o2, "o2"); if (prepare_revision_walk(&check_rev)) die(_("revision walk setup failed")); while ((commit = get_revision(&check_rev)) != NULL) { add_commit_patch_id(commit, ids); } /* reset for next revision walk */ clear_commit_marks(c1, SEEN | UNINTERESTING | SHOWN | ADDED); clear_commit_marks(c2, SEEN | UNINTERESTING | SHOWN | ADDED); o1->flags = flags1; o2->flags = flags2; }
static void cherry_pick_list(struct commit_list *list, struct rev_info *revs) { struct commit_list *p; int left_count = 0, right_count = 0; int left_first; struct patch_ids ids; /* First count the commits on the left and on the right */ for (p = list; p; p = p->next) { struct commit *commit = p->item; unsigned flags = commit->object.flags; if (flags & BOUNDARY) ; else if (flags & SYMMETRIC_LEFT) left_count++; else right_count++; } left_first = left_count < right_count; init_patch_ids(&ids); if (revs->diffopt.nr_paths) { ids.diffopts.nr_paths = revs->diffopt.nr_paths; ids.diffopts.paths = revs->diffopt.paths; ids.diffopts.pathlens = revs->diffopt.pathlens; } /* Compute patch-ids for one side */ for (p = list; p; p = p->next) { struct commit *commit = p->item; unsigned flags = commit->object.flags; if (flags & BOUNDARY) continue; /* * If we have fewer left, left_first is set and we omit * commits on the right branch in this loop. If we have * fewer right, we skip the left ones. */ if (left_first != !!(flags & SYMMETRIC_LEFT)) continue; commit->util = add_commit_patch_id(commit, &ids); } /* Check the other side */ for (p = list; p; p = p->next) { struct commit *commit = p->item; struct patch_id *id; unsigned flags = commit->object.flags; if (flags & BOUNDARY) continue; /* * If we have fewer left, left_first is set and we omit * commits on the left branch in this loop. */ if (left_first == !!(flags & SYMMETRIC_LEFT)) continue; /* * Have we seen the same patch id? */ id = has_commit_patch_id(commit, &ids); if (!id) continue; id->seen = 1; commit->object.flags |= SHOWN; } /* Now check the original side for seen ones */ for (p = list; p; p = p->next) { struct commit *commit = p->item; struct patch_id *ent; ent = commit->util; if (!ent) continue; if (ent->seen) commit->object.flags |= SHOWN; commit->util = NULL; } free_patch_ids(&ids); }