1818#include "commit-slab.h"
1919#include "date.h"
2020#include "wildmatch.h"
21+ #include "prio-queue.h"
2122
2223static const char * const show_branch_usage [] = {
2324 N_ ("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -59,11 +60,10 @@ static const char *get_color_reset_code(void)
5960 return "" ;
6061}
6162
62- static struct commit * interesting (struct commit_list * list )
63+ static struct commit * interesting (struct prio_queue * queue )
6364{
64- while (list ) {
65- struct commit * commit = list -> item ;
66- list = list -> next ;
65+ for (size_t i = 0 ; i < queue -> nr ; i ++ ) {
66+ struct commit * commit = queue -> array [i ].data ;
6767 if (commit -> object .flags & UNINTERESTING )
6868 continue ;
6969 return commit ;
@@ -222,17 +222,18 @@ static int mark_seen(struct commit *commit, struct commit_list **seen_p)
222222 return 0 ;
223223}
224224
225- static void join_revs (struct commit_list * * list_p ,
225+ static void join_revs (struct prio_queue * queue ,
226226 struct commit_list * * seen_p ,
227227 int num_rev , int extra )
228228{
229229 int all_mask = ((1u << (REV_SHIFT + num_rev )) - 1 );
230230 int all_revs = all_mask & ~((1u << REV_SHIFT ) - 1 );
231231
232- while (* list_p ) {
232+ while (queue -> nr ) {
233233 struct commit_list * parents ;
234- int still_interesting = !!interesting (* list_p );
235- struct commit * commit = pop_commit (list_p );
234+ int still_interesting = !!interesting (queue );
235+ struct commit * commit = prio_queue_peek (queue );
236+ bool get_pending = true;
236237 int flags = commit -> object .flags & all_mask ;
237238
238239 if (!still_interesting && extra <= 0 )
@@ -253,8 +254,14 @@ static void join_revs(struct commit_list **list_p,
253254 if (mark_seen (p , seen_p ) && !still_interesting )
254255 extra -- ;
255256 p -> object .flags |= flags ;
256- commit_list_insert_by_date (p , list_p );
257+ if (get_pending )
258+ prio_queue_replace (queue , p );
259+ else
260+ prio_queue_put (queue , p );
261+ get_pending = false;
257262 }
263+ if (get_pending )
264+ prio_queue_get (queue );
258265 }
259266
260267 /*
@@ -639,7 +646,8 @@ int cmd_show_branch(int ac,
639646{
640647 struct commit * rev [MAX_REVS ], * commit ;
641648 char * reflog_msg [MAX_REVS ] = {0 };
642- struct commit_list * list = NULL , * seen = NULL ;
649+ struct commit_list * seen = NULL ;
650+ struct prio_queue queue = { compare_commits_by_commit_date };
643651 unsigned int rev_mask [MAX_REVS ];
644652 int num_rev , i , extra = 0 ;
645653 int all_heads = 0 , all_remotes = 0 ;
@@ -883,14 +891,14 @@ int cmd_show_branch(int ac,
883891 */
884892 commit -> object .flags |= flag ;
885893 if (commit -> object .flags == flag )
886- commit_list_insert_by_date ( commit , & list );
894+ prio_queue_put ( & queue , commit );
887895 rev [num_rev ] = commit ;
888896 }
889897 for (i = 0 ; i < num_rev ; i ++ )
890898 rev_mask [i ] = rev [i ]-> object .flags ;
891899
892900 if (0 <= extra )
893- join_revs (& list , & seen , num_rev , extra );
901+ join_revs (& queue , & seen , num_rev , extra );
894902
895903 commit_list_sort_by_date (& seen );
896904
@@ -1001,7 +1009,7 @@ int cmd_show_branch(int ac,
10011009 for (size_t i = 0 ; i < ARRAY_SIZE (reflog_msg ); i ++ )
10021010 free (reflog_msg [i ]);
10031011 free_commit_list (seen );
1004- free_commit_list ( list );
1012+ clear_prio_queue ( & queue );
10051013 free (args_copy );
10061014 free (head );
10071015 return ret ;
0 commit comments