git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtin-branch.c: optimize --merged and --no-merged

From
LHLars 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

Previous: Junio C HamanoNext: Nanako Shiraishi
Message 18 of 32 in “q: faster way to integrate/merge lots of topic branches?”
  1. Ingo MolnarJul 23, 2008
  2. Ingo MolnarJul 23, 2008
  3. Ingo MolnarJul 23, 2008
  4. Jay SoffianJul 23, 2008
  5. Ingo MolnarJul 23, 2008
  6. Ingo MolnarJul 23, 2008
  7. Andreas EricssonJul 23, 2008
  8. Ingo MolnarJul 23, 2008
  9. Miklos VajnaJul 23, 2008
  10. Sergey VlasovJul 23, 2008
  11. Ingo MolnarJul 23, 2008
  12. Ingo MolnarJul 23, 2008
  13. SZEDER GáborJul 23, 2008
  14. Ingo MolnarJul 23, 2008
  15. Junio C HamanoJul 23, 2008
  16. 1/2 builtin-branch.c: remove unused code in append_ref() callback functionJunio C Hamano, Jul 23, 2008
  17. builtin-branch.c: optimize --merged and --no-mergedJunio C Hamano, Jul 23, 2008
  18. Lars HjemliJul 24, 2008
  19. Nanako ShiraishiJul 24, 2008
  20. Lars HjemliJul 24, 2008
  21. Ingo MolnarJul 24, 2008
  22. Linus TorvaldsJul 23, 2008
  23. Linus TorvaldsJul 23, 2008
  24. Junio C HamanoJul 23, 2008
  25. Ingo MolnarJul 24, 2008
  26. Junio C HamanoJul 25, 2008
  27. Björn SteinbrinkJul 23, 2008
  28. Santi BéjarJul 23, 2008
  29. Linus TorvaldsJul 23, 2008
  30. Pierre HabouzitJul 23, 2008
  31. Pierre HabouzitJul 23, 2008
  32. Pierre HabouzitJul 23, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.