fetch-pack: output refs in the order they were given on the command line.
Currently, fetched refs are output in the order the remote side happened to send them. This changes the order to match the order of refs that were given on the command line. To the existing core callers (git-fetch and git-clone) this does not make any difference, but for other Porcelain use, it would be more intuitive. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
May 11, 2006 at 15:28 UTC
9546010b7bbc25e037029a7dd83de9c57b7a935c
2 files changed
+52
-16
connect.c
+1
-1
@@ -100,7 +100,7 @@ int path_match(const char *path, int nr, char **match)
100
if (pathlen > len && path[pathlen - len - 1] != '/')
101
continue;
102
*s = 0;
103
- return 1;
103
+ return (i + 1);
104
}
105
return 0;
106
}
fetch-pack.c
+51
-15
@@ -262,22 +262,58 @@ static void mark_recent_complete_commits(unsigned long cutoff)
262
263
static void filter_refs(struct ref **refs, int nr_match, char **match)
264
{
265
- struct ref *prev, *current, *next;
266
-
267
- for (prev = NULL, current = *refs; current; current = next) {
268
- next = current->next;
269
- if ((!memcmp(current->name, "refs/", 5) &&
270
- check_ref_format(current->name + 5)) ||
271
- (!fetch_all &&
272
- !path_match(current->name, nr_match, match))) {
273
- if (prev == NULL)
274
- *refs = next;
275
- else
276
- prev->next = next;
277
- free(current);
278
- } else
279
- prev = current;
265
+ struct ref **return_refs;
266
+ struct ref *newlist = NULL;
267
+ struct ref **newtail = &newlist;
268
+ struct ref *ref, *next;
269
+ struct ref *fastarray[32];
270
+
271
+ if (nr_match && !fetch_all) {
272
+ if (ARRAY_SIZE(fastarray) < nr_match)
273
+ return_refs = xcalloc(nr_match, sizeof(struct ref *));
274
+ else {
275
+ return_refs = fastarray;
276
+ memset(return_refs, 0, sizeof(struct ref *) * nr_match);
277
+ }
278
+ }
279
+ else
280
+ return_refs = NULL;
281
+
282
+ for (ref = *refs; ref; ref = next) {
283
+ next = ref->next;
284
+ if (!memcmp(ref->name, "refs/", 5) &&
285
+ check_ref_format(ref->name + 5))
286
+ ; /* trash */
287
+ else if (fetch_all) {
288
+ *newtail = ref;
289
+ ref->next = NULL;
290
+ newtail = &ref->next;
291
+ continue;
292
+ }
293
+ else {
294
+ int order = path_match(ref->name, nr_match, match);
295
+ if (order) {
296
+ return_refs[order-1] = ref;
297
+ continue; /* we will link it later */
298
+ }
299
+ }
300
+ free(ref);
301
+ }
302
+
303
+ if (!fetch_all) {
304
+ int i;
305
+ for (i = 0; i < nr_match; i++) {
306
+ ref = return_refs[i];
307
+ if (ref) {
308
+ *newtail = ref;
309
+ ref->next = NULL;
310
+ newtail = &ref->next;
311
+ }
312
+ }
313
+ if (return_refs != fastarray)
314
+ free(return_refs);
315
}
316
+ *refs = newlist;
317
}
318
319
static int everything_local(struct ref **refs, int nr_match, char **match)