Re: [PATCH] builtin-branch.c: optimize --merged and --no-merged
- From
- Lars Hjemli <lh@elementstorage.no>
- Date
- Jul 24, 2008, 07:16 UTC
- Message-ID
- <8c5c35580807240016y75b69f69h4af47844f57f4539@mail.gmail.com>
- In-Reply-To
- <7vtzeg9rhh.fsf_-_@gitster.siamese.dyndns.org>
On Thu, Jul 24, 2008 at 12:15 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
> Instead, we can let the revision machinery traverse the history as if we > are running: > > $ git rev-list --branches --not $commit > > by queueing the tips of branches we encounter as positive refs (this > mimicks the "--branches" option in the above command line) and then > appending the merge_filter_ref commit as a negative one, and finally > calling prepare_revision_walk() to limit the list..
Nice.
Show 8 quoted lines
> @@ -213,6 +211,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
> {
> struct ref_list *ref_list = (struct ref_list*)(cb_data);
> struct ref_item *newitem;
> + struct commit *commit;
> int kind;
> int len;
> static struct commit_list branch;I think you can drop the 'branch' here.
> @@ -239,12 +242,8 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
> branch.item = lookup_commit_reference_gently(sha1, 1);
> if (!branch.item)
> die("Unable to lookup tip of branch %s", refname);..and here.
- if (merge_filter == SHOW_NOT_MERGED && - has_commit(merge_filter_ref, &branch)) - return 0; - if (merge_filter == SHOW_MERGED && - !has_commit(merge_filter_ref, &branch)) - return 0; + add_pending_object(&ref_list->revs, + (struct object *)branch.item, refname);
..and use 'commit' instead of 'branch.item' here.
Show 12 quoted lines
> @@ -305,7 +304,13 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
> {
> char c;
> int color;
> - struct commit *commit;
> + struct commit *commit = item->commit;
> +
> + if (merge_filter != NO_FILTER) {
> + int is_merged = !!(item->commit->object.flags & UNINTERESTING);
> + if (is_merged != (merge_filter == SHOW_MERGED))
> + return;
> + }A possible issue here is that `git branch -v --[no]-merged` might use a wrong maxwidth, but I'm not sure if it's even worth fixing.
Thanks for cleaning up my mess. -- larsh