builtin-prune: make file-scope static struct to an argument.
I want to make the first part of 'git prune' that marks the reachable objects callable as a library, so this starts the first step toward the goal by making the callchain to pass rev_info structure as an argument. No functionality change should be in this step. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 6, 2007 at 02:16 UTC
24304816141d16aacdc63612797faa1426222ef7
1 file changed
+18
-15
builtin-prune.c
+18
-15
@@ -12,7 +12,6 @@
12
13
static const char prune_usage[] = "git-prune [-n]";
14
static int show_only;
15
-static struct rev_info revs;
15
16
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
17
{
@@ -184,45 +183,48 @@ static void walk_commit_list(struct rev_info *revs)
183
static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, char *datail, void *cb_data)
184
{
185
struct object *object;
186
+ struct rev_info *revs = (struct rev_info *)cb_data;
187
188
object = parse_object(osha1);
189
if (object)
190
- add_pending_object(&revs, object, "");
190
+ add_pending_object(revs, object, "");
191
object = parse_object(nsha1);
192
if (object)
193
- add_pending_object(&revs, object, "");
193
+ add_pending_object(revs, object, "");
194
return 0;
195
}
196
197
static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
198
{
199
struct object *object = parse_object(sha1);
200
+ struct rev_info *revs = (struct rev_info *)cb_data;
201
+
202
if (!object)
203
die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
202
- add_pending_object(&revs, object, "");
204
+ add_pending_object(revs, object, "");
205
204
- for_each_reflog_ent(path, add_one_reflog_ent, NULL);
206
+ for_each_reflog_ent(path, add_one_reflog_ent, cb_data);
207
208
return 0;
209
}
210
209
-static void add_one_tree(const unsigned char *sha1)
211
+static void add_one_tree(const unsigned char *sha1, struct rev_info *revs)
212
{
213
struct tree *tree = lookup_tree(sha1);
212
- add_pending_object(&revs, &tree->object, "");
214
+ add_pending_object(revs, &tree->object, "");
215
}
216
215
-static void add_cache_tree(struct cache_tree *it)
217
+static void add_cache_tree(struct cache_tree *it, struct rev_info *revs)
218
{
219
int i;
220
221
if (it->entry_count >= 0)
220
- add_one_tree(it->sha1);
222
+ add_one_tree(it->sha1, revs);
223
for (i = 0; i < it->subtree_nr; i++)
222
- add_cache_tree(it->down[i]->cache_tree);
224
+ add_cache_tree(it->down[i]->cache_tree, revs);
225
}
226
225
-static void add_cache_refs(void)
227
+static void add_cache_refs(struct rev_info *revs)
228
{
229
int i;
230
@@ -237,12 +239,13 @@ static void add_cache_refs(void)
239
*/
240
}
241
if (active_cache_tree)
240
- add_cache_tree(active_cache_tree);
242
+ add_cache_tree(active_cache_tree, revs);
243
}
244
245
int cmd_prune(int argc, const char **argv, const char *prefix)
246
{
247
int i;
248
+ struct rev_info revs;
249
250
for (i = 1; i < argc; i++) {
251
const char *arg = argv[i];
@@ -264,11 +267,11 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
267
revs.blob_objects = 1;
268
revs.tree_objects = 1;
269
267
- /* Add all external refs */
268
- for_each_ref(add_one_ref, NULL);
270
+ /* Add all external refs, along with its reflog info */
271
+ for_each_ref(add_one_ref, &revs);
272
273
/* Add all refs from the index file */
271
- add_cache_refs();
274
+ add_cache_refs(&revs);
275
276
/*
277
* Set up the revision walk - this will move all commits