Git fork

Merge branch 'rs/describe-with-lazy-queue-and-oidset'

Instead of scanning for the remaining items to see if there are
still commits to be explored in the queue, use khash to remember
which items are still on the queue (an unacceptable alternative is
to reserve one object flag bits).

* rs/describe-with-lazy-queue-and-oidset:
describe: use oidset in finish_depth_computation()

+22 -12
+22 -12
builtin/describe.c
··· 24 #include "commit-slab.h" 25 #include "wildmatch.h" 26 #include "prio-queue.h" 27 28 #define MAX_TAGS (FLAG_BITS - 1) 29 #define DEFAULT_CANDIDATES 10 ··· 286 queue->get_pending = false; 287 } 288 289 - static bool all_have_flag(const struct lazy_queue *queue, unsigned flag) 290 { 291 for (size_t i = queue->get_pending ? 1 : 0; i < queue->queue.nr; i++) { 292 struct commit *commit = queue->queue.array[i].data; 293 - if (!(commit->object.flags & flag)) 294 - return false; 295 } 296 - return true; 297 - } 298 299 - static unsigned long finish_depth_computation(struct lazy_queue *queue, 300 - struct possible_tag *best) 301 - { 302 - unsigned long seen_commits = 0; 303 while (!lazy_queue_empty(queue)) { 304 struct commit *c = lazy_queue_get(queue); 305 struct commit_list *parents = c->parents; 306 seen_commits++; 307 if (c->object.flags & best->flag_within) { 308 - if (all_have_flag(queue, best->flag_within)) 309 break; 310 - } else 311 best->depth++; 312 while (parents) { 313 struct commit *p = parents->item; 314 repo_parse_commit(the_repository, p); 315 - if (!(p->object.flags & SEEN)) 316 lazy_queue_put(queue, p); 317 p->object.flags |= c->object.flags; 318 parents = parents->next; 319 } 320 } 321 return seen_commits; 322 } 323
··· 24 #include "commit-slab.h" 25 #include "wildmatch.h" 26 #include "prio-queue.h" 27 + #include "oidset.h" 28 29 #define MAX_TAGS (FLAG_BITS - 1) 30 #define DEFAULT_CANDIDATES 10 ··· 287 queue->get_pending = false; 288 } 289 290 + static unsigned long finish_depth_computation(struct lazy_queue *queue, 291 + struct possible_tag *best) 292 { 293 + unsigned long seen_commits = 0; 294 + struct oidset unflagged = OIDSET_INIT; 295 + 296 for (size_t i = queue->get_pending ? 1 : 0; i < queue->queue.nr; i++) { 297 struct commit *commit = queue->queue.array[i].data; 298 + if (!(commit->object.flags & best->flag_within)) 299 + oidset_insert(&unflagged, &commit->object.oid); 300 } 301 302 while (!lazy_queue_empty(queue)) { 303 struct commit *c = lazy_queue_get(queue); 304 struct commit_list *parents = c->parents; 305 seen_commits++; 306 if (c->object.flags & best->flag_within) { 307 + if (!oidset_size(&unflagged)) 308 break; 309 + } else { 310 + oidset_remove(&unflagged, &c->object.oid); 311 best->depth++; 312 + } 313 while (parents) { 314 + unsigned seen, flag_before, flag_after; 315 struct commit *p = parents->item; 316 repo_parse_commit(the_repository, p); 317 + seen = p->object.flags & SEEN; 318 + if (!seen) 319 lazy_queue_put(queue, p); 320 + flag_before = p->object.flags & best->flag_within; 321 p->object.flags |= c->object.flags; 322 + flag_after = p->object.flags & best->flag_within; 323 + if (!seen && !flag_after) 324 + oidset_insert(&unflagged, &p->object.oid); 325 + if (seen && !flag_before && flag_after) 326 + oidset_remove(&unflagged, &p->object.oid); 327 parents = parents->next; 328 } 329 } 330 + oidset_clear(&unflagged); 331 return seen_commits; 332 } 333