Skip to content

Commit 9202489

Browse files
matvoregitster
authored andcommitted
list-objects: refactor to process_tree_contents
This will be used in a follow-up patch to reduce indentation needed when invoking the logic conditionally. i.e. rather than: if (foo) { while (...) { /* this is very indented */ } } we will have: if (foo) process_tree_contents(...); Signed-off-by: Matthew DeVore <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f447a49 commit 9202489

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

list-objects.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,53 @@ static void process_gitlink(struct traversal_context *ctx,
9494
/* Nothing to do */
9595
}
9696

97+
static void process_tree(struct traversal_context *ctx,
98+
struct tree *tree,
99+
struct strbuf *base,
100+
const char *name);
101+
102+
static void process_tree_contents(struct traversal_context *ctx,
103+
struct tree *tree,
104+
struct strbuf *base)
105+
{
106+
struct tree_desc desc;
107+
struct name_entry entry;
108+
enum interesting match = ctx->revs->diffopt.pathspec.nr == 0 ?
109+
all_entries_interesting : entry_not_interesting;
110+
111+
init_tree_desc(&desc, tree->buffer, tree->size);
112+
113+
while (tree_entry(&desc, &entry)) {
114+
if (match != all_entries_interesting) {
115+
match = tree_entry_interesting(&entry, base, 0,
116+
&ctx->revs->diffopt.pathspec);
117+
if (match == all_entries_not_interesting)
118+
break;
119+
if (match == entry_not_interesting)
120+
continue;
121+
}
122+
123+
if (S_ISDIR(entry.mode))
124+
process_tree(ctx,
125+
lookup_tree(the_repository, entry.oid),
126+
base, entry.path);
127+
else if (S_ISGITLINK(entry.mode))
128+
process_gitlink(ctx, entry.oid->hash,
129+
base, entry.path);
130+
else
131+
process_blob(ctx,
132+
lookup_blob(the_repository, entry.oid),
133+
base, entry.path);
134+
}
135+
}
136+
97137
static void process_tree(struct traversal_context *ctx,
98138
struct tree *tree,
99139
struct strbuf *base,
100140
const char *name)
101141
{
102142
struct object *obj = &tree->object;
103143
struct rev_info *revs = ctx->revs;
104-
struct tree_desc desc;
105-
struct name_entry entry;
106-
enum interesting match = revs->diffopt.pathspec.nr == 0 ?
107-
all_entries_interesting: entry_not_interesting;
108144
int baselen = base->len;
109145
enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
110146
int gently = revs->ignore_missing_links ||
@@ -144,29 +180,7 @@ static void process_tree(struct traversal_context *ctx,
144180
if (base->len)
145181
strbuf_addch(base, '/');
146182

147-
init_tree_desc(&desc, tree->buffer, tree->size);
148-
149-
while (tree_entry(&desc, &entry)) {
150-
if (match != all_entries_interesting) {
151-
match = tree_entry_interesting(&entry, base, 0,
152-
&revs->diffopt.pathspec);
153-
if (match == all_entries_not_interesting)
154-
break;
155-
if (match == entry_not_interesting)
156-
continue;
157-
}
158-
159-
if (S_ISDIR(entry.mode))
160-
process_tree(ctx,
161-
lookup_tree(the_repository, entry.oid),
162-
base, entry.path);
163-
else if (S_ISGITLINK(entry.mode))
164-
process_gitlink(ctx, entry.oid->hash, base, entry.path);
165-
else
166-
process_blob(ctx,
167-
lookup_blob(the_repository, entry.oid),
168-
base, entry.path);
169-
}
183+
process_tree_contents(ctx, tree, base);
170184

171185
if (!(obj->flags & USER_GIVEN) && ctx->filter_fn) {
172186
r = ctx->filter_fn(LOFS_END_TREE, obj,

0 commit comments

Comments
 (0)