revision.c: refactor add_index_objects_to_pending()
The core code is factored out and take 'struct index_state *' instead so that we can reuse it to add objects from index files other than .git/index in the next patch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Aug 23, 2017 at 19:36 UTC
6c3d818154eb74a4d5b35e786eefd297745bae1a
1 file changed
+12
-6
revision.c
+12
-6
@@ -1262,13 +1262,13 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1262
1263
}
1264
1265
-void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
1265
+static void do_add_index_objects_to_pending(struct rev_info *revs,
1266
+ struct index_state *istate)
1267
{
1268
int i;
1269
1269
- read_cache();
1270
- for (i = 0; i < active_nr; i++) {
1271
- struct cache_entry *ce = active_cache[i];
1270
+ for (i = 0; i < istate->cache_nr; i++) {
1271
+ struct cache_entry *ce = istate->cache[i];
1272
struct blob *blob;
1273
1274
if (S_ISGITLINK(ce->ce_mode))
@@ -1281,13 +1281,19 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
1281
ce->ce_mode, ce->name);
1282
}
1283
1284
- if (active_cache_tree) {
1284
+ if (istate->cache_tree) {
1285
struct strbuf path = STRBUF_INIT;
1286
- add_cache_tree(active_cache_tree, revs, &path);
1286
+ add_cache_tree(istate->cache_tree, revs, &path);
1287
strbuf_release(&path);
1288
}
1289
}
1290
1291
+void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
1292
+{
1293
+ read_cache();
1294
+ do_add_index_objects_to_pending(revs, &the_index);
1295
+}
1296
+
1297
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
1298
int exclude_parent)
1299
{