12
12
#include "commit-slab.h"
13
13
#include "revision.h"
14
14
#include "list-objects.h"
15
+ #include "commit-slab.h"
15
16
16
17
static int is_shallow = -1 ;
17
18
static struct stat_validity shallow_stat ;
@@ -74,6 +75,11 @@ int is_repository_shallow(void)
74
75
return is_shallow ;
75
76
}
76
77
78
+ /*
79
+ * TODO: use "int" elemtype instead of "int *" when/if commit-slab
80
+ * supports a "valid" flag.
81
+ */
82
+ define_commit_slab (commit_depth , int * );
77
83
struct commit_list * get_shallow_commits (struct object_array * heads , int depth ,
78
84
int shallow_flag , int not_shallow_flag )
79
85
{
@@ -82,25 +88,29 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
82
88
struct object_array stack = OBJECT_ARRAY_INIT ;
83
89
struct commit * commit = NULL ;
84
90
struct commit_graft * graft ;
91
+ struct commit_depth depths ;
85
92
93
+ init_commit_depth (& depths );
86
94
while (commit || i < heads -> nr || stack .nr ) {
87
95
struct commit_list * p ;
88
96
if (!commit ) {
89
97
if (i < heads -> nr ) {
98
+ int * * depth_slot ;
90
99
commit = (struct commit * )
91
100
deref_tag (heads -> objects [i ++ ].item , NULL , 0 );
92
101
if (!commit || commit -> object .type != OBJ_COMMIT ) {
93
102
commit = NULL ;
94
103
continue ;
95
104
}
96
- if (!commit -> util )
97
- commit -> util = xmalloc (sizeof (int ));
98
- * (int * )commit -> util = 0 ;
105
+ depth_slot = commit_depth_at (& depths , commit );
106
+ if (!* depth_slot )
107
+ * depth_slot = xmalloc (sizeof (int ));
108
+ * * depth_slot = 0 ;
99
109
cur_depth = 0 ;
100
110
} else {
101
111
commit = (struct commit * )
102
112
object_array_pop (& stack );
103
- cur_depth = * ( int * ) commit -> util ;
113
+ cur_depth = * * commit_depth_at ( & depths , commit ) ;
104
114
}
105
115
}
106
116
parse_commit_or_die (commit );
@@ -116,25 +126,31 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
116
126
}
117
127
commit -> object .flags |= not_shallow_flag ;
118
128
for (p = commit -> parents , commit = NULL ; p ; p = p -> next ) {
119
- if (! p -> item -> util ) {
120
- int * pointer = xmalloc ( sizeof ( int ));
121
- p -> item -> util = pointer ;
122
- * pointer = cur_depth ;
129
+ int * * depth_slot = commit_depth_at ( & depths , p -> item );
130
+ if (! * depth_slot ) {
131
+ * depth_slot = xmalloc ( sizeof ( int )) ;
132
+ * * depth_slot = cur_depth ;
123
133
} else {
124
- int * pointer = p -> item -> util ;
125
- if (cur_depth >= * pointer )
134
+ if (cur_depth >= * * depth_slot )
126
135
continue ;
127
- * pointer = cur_depth ;
136
+ * * depth_slot = cur_depth ;
128
137
}
129
138
if (p -> next )
130
139
add_object_array (& p -> item -> object ,
131
140
NULL , & stack );
132
141
else {
133
142
commit = p -> item ;
134
- cur_depth = * ( int * ) commit -> util ;
143
+ cur_depth = * * commit_depth_at ( & depths , commit ) ;
135
144
}
136
145
}
137
146
}
147
+ for (i = 0 ; i < depths .slab_count ; i ++ ) {
148
+ int j ;
149
+
150
+ for (j = 0 ; j < depths .slab_size ; j ++ )
151
+ free (depths .slab [i ][j ]);
152
+ }
153
+ clear_commit_depth (& depths );
138
154
139
155
return result ;
140
156
}
0 commit comments