8
8
#include "notes.h"
9
9
#include "gpg-interface.h"
10
10
#include "mergesort.h"
11
+ #include "commit-slab.h"
11
12
12
13
static struct commit_extra_header * read_commit_extra_header_lines (const char * buf , size_t len , const char * * );
13
14
14
15
int save_commit_buffer = 1 ;
15
16
16
17
const char * commit_type = "commit" ;
18
+ static int commit_count ;
17
19
18
20
static struct commit * check_commit (struct object * obj ,
19
21
const unsigned char * sha1 ,
@@ -58,8 +60,11 @@ struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_n
58
60
struct commit * lookup_commit (const unsigned char * sha1 )
59
61
{
60
62
struct object * obj = lookup_object (sha1 );
61
- if (!obj )
62
- return create_object (sha1 , OBJ_COMMIT , alloc_commit_node ());
63
+ if (!obj ) {
64
+ struct commit * c = alloc_commit_node ();
65
+ c -> index = commit_count ++ ;
66
+ return create_object (sha1 , OBJ_COMMIT , c );
67
+ }
63
68
if (!obj -> type )
64
69
obj -> type = OBJ_COMMIT ;
65
70
return check_commit (obj , sha1 , 0 );
@@ -506,6 +511,13 @@ struct commit *pop_commit(struct commit_list **stack)
506
511
return item ;
507
512
}
508
513
514
+ /*
515
+ * Topological sort support
516
+ */
517
+
518
+ /* count number of children that have not been emitted */
519
+ define_commit_slab (indegree_slab , int );
520
+
509
521
/*
510
522
* Performs an in-place topological sort on the list supplied.
511
523
*/
@@ -514,25 +526,29 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
514
526
struct commit_list * next , * orig = * list ;
515
527
struct commit_list * work , * * insert ;
516
528
struct commit_list * * pptr ;
529
+ struct indegree_slab indegree ;
517
530
518
531
if (!orig )
519
532
return ;
520
533
* list = NULL ;
521
534
535
+ init_indegree_slab (& indegree );
536
+
522
537
/* Mark them and clear the indegree */
523
538
for (next = orig ; next ; next = next -> next ) {
524
539
struct commit * commit = next -> item ;
525
- commit -> indegree = 1 ;
540
+ * ( indegree_slab_at ( & indegree , commit )) = 1 ;
526
541
}
527
542
528
543
/* update the indegree */
529
544
for (next = orig ; next ; next = next -> next ) {
530
545
struct commit_list * parents = next -> item -> parents ;
531
546
while (parents ) {
532
547
struct commit * parent = parents -> item ;
548
+ int * pi = indegree_slab_at (& indegree , parent );
533
549
534
- if (parent -> indegree )
535
- parent -> indegree ++ ;
550
+ if (* pi )
551
+ ( * pi ) ++ ;
536
552
parents = parents -> next ;
537
553
}
538
554
}
@@ -549,7 +565,7 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
549
565
for (next = orig ; next ; next = next -> next ) {
550
566
struct commit * commit = next -> item ;
551
567
552
- if (commit -> indegree == 1 )
568
+ if (* ( indegree_slab_at ( & indegree , commit )) == 1 )
553
569
insert = & commit_list_insert (commit , insert )-> next ;
554
570
}
555
571
@@ -570,16 +586,17 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
570
586
commit = work_item -> item ;
571
587
for (parents = commit -> parents ; parents ; parents = parents -> next ) {
572
588
struct commit * parent = parents -> item ;
589
+ int * pi = indegree_slab_at (& indegree , parent );
573
590
574
- if (!parent -> indegree )
591
+ if (!* pi )
575
592
continue ;
576
593
577
594
/*
578
595
* parents are only enqueued for emission
579
596
* when all their children have been emitted thereby
580
597
* guaranteeing topological order.
581
598
*/
582
- if (-- parent -> indegree == 1 ) {
599
+ if (-- ( * pi ) == 1 ) {
583
600
if (!lifo )
584
601
commit_list_insert_by_date (parent , & work );
585
602
else
@@ -590,10 +607,12 @@ void sort_in_topological_order(struct commit_list ** list, int lifo)
590
607
* work_item is a commit all of whose children
591
608
* have already been emitted. we can emit it now.
592
609
*/
593
- commit -> indegree = 0 ;
610
+ * ( indegree_slab_at ( & indegree , commit )) = 0 ;
594
611
* pptr = work_item ;
595
612
pptr = & work_item -> next ;
596
613
}
614
+
615
+ clear_indegree_slab (& indegree );
597
616
}
598
617
599
618
/* merge-base stuff */
0 commit comments