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 <matvore@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthew DeVore committed
Aug 13, 2018 at 11:14 UTC
9202489174a110f82867edbac601f12480a4e284
1 file changed
+41
-27
list-objects.c
+41
-27
@@ -94,6 +94,46 @@ static void process_gitlink(struct traversal_context *ctx,
94
/* Nothing to do */
95
}
96
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
+
137
static void process_tree(struct traversal_context *ctx,
138
struct tree *tree,
139
struct strbuf *base,
@@ -101,10 +141,6 @@ static void process_tree(struct traversal_context *ctx,
141
{
142
struct object *obj = &tree->object;
143
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;
144
int baselen = base->len;
145
enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
146
int gently = revs->ignore_missing_links ||
@@ -144,29 +180,7 @@ static void process_tree(struct traversal_context *ctx,
180
if (base->len)
181
strbuf_addch(base, '/');
182
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);
184
185
if (!(obj->flags & USER_GIVEN) && ctx->filter_fn) {
186
r = ctx->filter_fn(LOFS_END_TREE, obj,