Teach git-http-fetch the --stdin switch
Speeds up things quite a lot when fetching tags with Cogito. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
Petr Baudis committed
Jul 27, 2006 at 23:56 UTC
8e29f6a07e321a24f1d4f579817f5a8a43cdac05
2 files changed
+36
-17
Documentation/git-http-fetch.txt
+7
-1
@@ -8,7 +8,7 @@ git-http-fetch - downloads a remote git repository via HTTP
8
9
SYNOPSIS
10
--------
11
-'git-http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] <commit> <url>
11
+'git-http-fetch' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [--stdin] <commit> <url>
12
13
DESCRIPTION
14
-----------
@@ -33,6 +33,12 @@ commit-id::
33
Writes the commit-id into the filename under $GIT_DIR/refs/<filename> on
34
the local end after the transfer is complete.
35
36
+--stdin::
37
+ Instead of a commit id on the commandline (which is not expected in this
38
+ case), 'git-http-fetch' expects lines on stdin in the format
39
+
40
+ <commit-id>['\t'<filename-as-in--w>]
41
+
42
Author
43
------
44
Written by Linus Torvalds <torvalds@osdl.org>
http-fetch.c
+29
-16
@@ -36,6 +36,8 @@ enum XML_Status {
36
#define PREV_BUF_SIZE 4096
37
#define RANGE_HEADER_SIZE 30
38
39
+static int commits_on_stdin = 0;
40
+
41
static int got_alternates = -1;
42
static int corrupt_object_found = 0;
43
@@ -43,7 +45,7 @@ static struct curl_slist *no_pragma_header;
45
46
struct alt_base
47
{
46
- char *base;
48
+ const char *base;
49
int path_len;
50
int got_indices;
51
struct packed_git *packs;
@@ -81,7 +83,7 @@ struct object_request
83
};
84
85
struct alternates_request {
84
- char *base;
86
+ const char *base;
87
char *url;
88
struct buffer *buffer;
89
struct active_request_slot *slot;
@@ -142,7 +144,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
144
return size;
145
}
146
145
-static void fetch_alternates(char *base);
147
+static void fetch_alternates(const char *base);
148
149
static void process_object_response(void *callback_data);
150
@@ -507,7 +509,7 @@ static void process_alternates_response(void *callback_data)
509
(struct alternates_request *)callback_data;
510
struct active_request_slot *slot = alt_req->slot;
511
struct alt_base *tail = alt;
510
- char *base = alt_req->base;
512
+ const char *base = alt_req->base;
513
static const char null_byte = '\0';
514
char *data;
515
int i = 0;
@@ -612,7 +614,7 @@ static void process_alternates_response(void *callback_data)
614
got_alternates = 1;
615
}
616
615
-static void fetch_alternates(char *base)
617
+static void fetch_alternates(const char *base)
618
{
619
struct buffer buffer;
620
char *url;
@@ -1185,7 +1187,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
1187
char *url;
1188
char hex[42];
1189
struct buffer buffer;
1188
- char *base = alt->base;
1190
+ const char *base = alt->base;
1191
struct active_request_slot *slot;
1192
struct slot_results results;
1193
buffer.size = 41;
@@ -1214,11 +1216,12 @@ int fetch_ref(char *ref, unsigned char *sha1)
1216
return 0;
1217
}
1218
1217
-int main(int argc, char **argv)
1219
+int main(int argc, const char **argv)
1220
{
1219
- const char *write_ref = NULL;
1220
- char *commit_id;
1221
- char *url;
1221
+ int commits;
1222
+ const char **write_ref = NULL;
1223
+ char **commit_id;
1224
+ const char *url;
1225
char *path;
1226
int arg = 1;
1227
int rc = 0;
@@ -1238,19 +1241,26 @@ int main(int argc, char **argv)
1241
} else if (argv[arg][1] == 'v') {
1242
get_verbosely = 1;
1243
} else if (argv[arg][1] == 'w') {
1241
- write_ref = argv[arg + 1];
1244
+ write_ref = &argv[arg + 1];
1245
arg++;
1246
} else if (!strcmp(argv[arg], "--recover")) {
1247
get_recover = 1;
1248
+ } else if (!strcmp(argv[arg], "--stdin")) {
1249
+ commits_on_stdin = 1;
1250
}
1251
arg++;
1252
}
1248
- if (argc < arg + 2) {
1249
- usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] commit-id url");
1253
+ if (argc < arg + 2 - commits_on_stdin) {
1254
+ usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
1255
return 1;
1256
}
1252
- commit_id = argv[arg];
1253
- url = argv[arg + 1];
1257
+ if (commits_on_stdin) {
1258
+ commits = pull_targets_stdin(&commit_id, &write_ref);
1259
+ } else {
1260
+ commit_id = (char **) &argv[arg++];
1261
+ commits = 1;
1262
+ }
1263
+ url = argv[arg];
1264
1265
http_init();
1266
@@ -1268,13 +1278,16 @@ int main(int argc, char **argv)
1278
alt->path_len = strlen(path);
1279
}
1280
1271
- if (pull(1, &commit_id, &write_ref, url))
1281
+ if (pull(commits, commit_id, write_ref, url))
1282
rc = 1;
1283
1284
http_cleanup();
1285
1286
curl_slist_free_all(no_pragma_header);
1287
1288
+ if (commits_on_stdin)
1289
+ pull_targets_free(commits, commit_id, write_ref);
1290
+
1291
if (corrupt_object_found) {
1292
fprintf(stderr,
1293
"Some loose object were found to be corrupt, but they might be just\n"