git-fetch: rewrite another shell loop in C
Move another shell loop that canonicalizes the list of refs for underlying git-fetch-pack and fetch-native-store into C. This seems to shave the runtime for the same 1000 branch repository from 30 seconds down to 15 seconds (it used to be 2 and half minutes with the original version). Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 16, 2007 at 02:31 UTC
d1e0ef6cc89e5ef2f914c37719b9c2327e534834
2 files changed
+48
-28
builtin-fetch--tool.c
+46
@@ -283,6 +283,46 @@ static int fetch_native_store(FILE *fp,
283
return err;
284
}
285
286
+static int parse_reflist(const char *reflist)
287
+{
288
+ const char *ref;
289
+
290
+ printf("refs='");
291
+ for (ref = reflist; ref; ) {
292
+ const char *next;
293
+ while (*ref && isspace(*ref))
294
+ ref++;
295
+ if (!*ref)
296
+ break;
297
+ for (next = ref; *next && !isspace(*next); next++)
298
+ ;
299
+ printf("\n%.*s", (int)(next - ref), ref);
300
+ ref = next;
301
+ }
302
+ printf("'\n");
303
+
304
+ printf("rref='");
305
+ for (ref = reflist; ref; ) {
306
+ const char *next, *colon;
307
+ while (*ref && isspace(*ref))
308
+ ref++;
309
+ if (!*ref)
310
+ break;
311
+ for (next = ref; *next && !isspace(*next); next++)
312
+ ;
313
+ if (*ref == '.')
314
+ ref++;
315
+ if (*ref == '+')
316
+ ref++;
317
+ colon = strchr(ref, ':');
318
+ putchar('\n');
319
+ printf("%.*s", (int)((colon ? colon : next) - ref), ref);
320
+ ref = next;
321
+ }
322
+ printf("'\n");
323
+ return 0;
324
+}
325
+
326
int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
327
{
328
int verbose = 0;
@@ -335,5 +375,11 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
375
fclose(fp);
376
return result;
377
}
378
+ if (!strcmp("parse-reflist", argv[1])) {
379
+ if (argc != 3)
380
+ return error("parse-reflist takes 1 arg");
381
+ return parse_reflist(argv[2]);
382
+ }
383
+
384
return error("Unknown subcommand: %s", argv[1]);
385
}
git-fetch.sh
+2
-28
@@ -155,35 +155,9 @@ then
155
fi
156
157
fetch_native () {
158
- reflist="$1"
159
- refs=
160
- rref=
161
-
162
- for ref in $reflist
163
- do
164
- refs="$refs$LF$ref"
165
-
166
- # These are relative path from $GIT_DIR, typically starting at refs/
167
- # but may be HEAD
168
- if expr "z$ref" : 'z\.' >/dev/null
169
- then
170
- not_for_merge=t
171
- ref=$(expr "z$ref" : 'z\.\(.*\)')
172
- else
173
- not_for_merge=
174
- fi
175
- if expr "z$ref" : 'z+' >/dev/null
176
- then
177
- single_force=t
178
- ref=$(expr "z$ref" : 'z+\(.*\)')
179
- else
180
- single_force=
181
- fi
182
- remote_name=$(expr "z$ref" : 'z\([^:]*\):')
183
- local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
158
185
- rref="$rref$LF$remote_name"
186
- done
159
+ eval=$(git-fetch--tool parse-reflist "$1")
160
+ eval "$eval"
161
162
( : subshell because we muck with IFS
163
IFS=" $LF"