http-push: cleanup
More consistent usage string, condense push output, remove extra slashes in URLs, fix unused variables, include HTTP method name in failure messages. Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Mar 10, 2006 at 20:18 UTC
1a703cba6dac85936a5026587a90dcb827d00088
1 file changed
+33
-24
http-push.c
+33
-24
@@ -11,7 +11,7 @@
11
#include <expat.h>
12
13
static const char http_push_usage[] =
14
-"git-http-push [--complete] [--force] [--verbose] <url> <ref> [<ref>...]\n";
14
+"git-http-push [--all] [--force] [--verbose] <remote> [<head>...]\n";
15
16
#ifndef XML_STATUS_OK
17
enum XML_Status {
@@ -707,8 +707,9 @@ static void finish_request(struct transfer_request *request)
707
}
708
} else if (request->state == RUN_MOVE) {
709
if (request->curl_result == CURLE_OK) {
710
- fprintf(stderr, " sent %s\n",
711
- sha1_to_hex(request->obj->sha1));
710
+ if (push_verbosely)
711
+ fprintf(stderr, " sent %s\n",
712
+ sha1_to_hex(request->obj->sha1));
713
request->obj->flags |= REMOTE;
714
release_request(request);
715
} else {
@@ -848,7 +849,7 @@ static void add_fetch_request(struct object *obj)
849
step_active_slots();
850
}
851
851
-static void add_send_request(struct object *obj, struct remote_lock *lock)
852
+static int add_send_request(struct object *obj, struct remote_lock *lock)
853
{
854
struct transfer_request *request = request_queue_head;
855
struct packed_git *target;
@@ -863,11 +864,11 @@ static void add_send_request(struct object *obj, struct remote_lock *lock)
864
if (remote_dir_exists[obj->sha1[0]] == -1)
865
get_remote_object_list(obj->sha1[0]);
866
if (obj->flags & (REMOTE | PUSHING))
866
- return;
867
+ return 0;
868
target = find_sha1_pack(obj->sha1, remote->packs);
869
if (target) {
870
obj->flags |= REMOTE;
870
- return;
871
+ return 0;
872
}
873
874
obj->flags |= PUSHING;
@@ -884,6 +885,8 @@ static void add_send_request(struct object *obj, struct remote_lock *lock)
885
886
fill_active_slots();
887
step_active_slots();
888
+
889
+ return 1;
890
}
891
892
static int fetch_index(unsigned char *sha1)
@@ -901,8 +904,8 @@ static int fetch_index(unsigned char *sha1)
904
struct slot_results results;
905
906
/* Don't use the index if the pack isn't there */
904
- url = xmalloc(strlen(remote->url) + 65);
905
- sprintf(url, "%s/objects/pack/pack-%s.pack", remote->url, hex);
907
+ url = xmalloc(strlen(remote->url) + 64);
908
+ sprintf(url, "%sobjects/pack/pack-%s.pack", remote->url, hex);
909
slot = get_active_slot();
910
slot->results = &results;
911
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -923,9 +926,9 @@ static int fetch_index(unsigned char *sha1)
926
927
if (push_verbosely)
928
fprintf(stderr, "Getting index for pack %s\n", hex);
926
-
927
- sprintf(url, "%s/objects/pack/pack-%s.idx", remote->url, hex);
928
-
929
+
930
+ sprintf(url, "%sobjects/pack/pack-%s.idx", remote->url, hex);
931
+
932
filename = sha1_pack_index_name(sha1);
933
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
934
indexfile = fopen(tmpfile, "a");
@@ -1008,9 +1011,9 @@ static int fetch_indices(void)
1011
1012
if (push_verbosely)
1013
fprintf(stderr, "Getting pack list\n");
1011
-
1012
- url = xmalloc(strlen(remote->url) + 21);
1013
- sprintf(url, "%s/objects/info/packs", remote->url);
1014
+
1015
+ url = xmalloc(strlen(remote->url) + 20);
1016
+ sprintf(url, "%sobjects/info/packs", remote->url);
1017
1018
slot = get_active_slot();
1019
slot->results = &results;
@@ -1298,7 +1301,7 @@ static struct remote_lock *lock_remote(char *path, long timeout)
1301
return NULL;
1302
}
1303
} else {
1301
- fprintf(stderr, "Unable to start request\n");
1304
+ fprintf(stderr, "Unable to start MKCOL request\n");
1305
free(url);
1306
return NULL;
1307
}
@@ -1359,7 +1362,7 @@ static struct remote_lock *lock_remote(char *path, long timeout)
1362
}
1363
}
1364
} else {
1362
- fprintf(stderr, "Unable to start request\n");
1365
+ fprintf(stderr, "Unable to start LOCK request\n");
1366
}
1367
1368
curl_slist_free_all(dav_headers);
@@ -1673,7 +1676,7 @@ static int locking_available(void)
1676
}
1677
}
1678
} else {
1676
- fprintf(stderr, "Unable to start request\n");
1679
+ fprintf(stderr, "Unable to start PROPFIND request\n");
1680
}
1681
1682
free(out_data);
@@ -1734,16 +1737,17 @@ static struct object_list **process_tree(struct tree *tree,
1737
return p;
1738
}
1739
1737
-static void get_delta(struct rev_info *revs, struct remote_lock *lock)
1740
+static int get_delta(struct rev_info *revs, struct remote_lock *lock)
1741
{
1742
struct commit *commit;
1743
struct object_list **p = &objects, *pending;
1744
+ int count = 0;
1745
1746
while ((commit = get_revision(revs)) != NULL) {
1747
p = process_tree(commit->tree, p, NULL, "");
1748
commit->object.flags |= LOCAL;
1749
if (!(commit->object.flags & UNINTERESTING))
1746
- add_send_request(&commit->object, lock);
1750
+ count += add_send_request(&commit->object, lock);
1751
}
1752
1753
for (pending = revs->pending_objects; pending; pending = pending->next) {
@@ -1770,9 +1774,11 @@ static void get_delta(struct rev_info *revs, struct remote_lock *lock)
1774
1775
while (objects) {
1776
if (!(objects->item->flags & UNINTERESTING))
1773
- add_send_request(objects->item, lock);
1777
+ count += add_send_request(objects->item, lock);
1778
objects = objects->next;
1779
}
1780
+
1781
+ return count;
1782
}
1783
1784
static int update_remote(unsigned char *sha1, struct remote_lock *lock)
@@ -2106,6 +2112,7 @@ int main(int argc, char **argv)
2112
struct remote_lock *ref_lock = NULL;
2113
struct remote_lock *info_ref_lock = NULL;
2114
struct rev_info revs;
2115
+ int objects_to_send;
2116
int rc = 0;
2117
int i;
2118
@@ -2197,7 +2204,6 @@ int main(int argc, char **argv)
2204
return 0;
2205
}
2206
2200
- int ret = 0;
2207
int new_refs = 0;
2208
struct ref *ref;
2209
for (ref = remote_refs; ref; ref = ref->next) {
@@ -2229,14 +2235,14 @@ int main(int argc, char **argv)
2235
"need to pull first?",
2236
ref->name,
2237
ref->peer_ref->name);
2232
- ret = -2;
2238
+ rc = -2;
2239
continue;
2240
}
2241
}
2242
memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
2243
if (is_zero_sha1(ref->new_sha1)) {
2244
error("cannot happen anymore");
2239
- ret = -3;
2245
+ rc = -3;
2246
continue;
2247
}
2248
new_refs++;
@@ -2283,12 +2289,15 @@ int main(int argc, char **argv)
2289
pushing = 0;
2290
prepare_revision_walk(&revs);
2291
mark_edges_uninteresting(revs.commits);
2286
- get_delta(&revs, ref_lock);
2292
+ objects_to_send = get_delta(&revs, ref_lock);
2293
finish_all_active_slots();
2294
2295
/* Push missing objects to remote, this would be a
2296
convenient time to pack them first if appropriate. */
2297
pushing = 1;
2298
+ if (objects_to_send)
2299
+ fprintf(stderr, " sending %d objects\n",
2300
+ objects_to_send);
2301
fill_active_slots();
2302
finish_all_active_slots();
2303