@matheusbsbs / matheus-bagliano / commits / 4c42aa1a13
Fork 0

http-push, http-walker: style fixes

- Use tabs to indent, instead of spaces. - Do not use curly-braces around a single statement body in if/while statement; - Do not start multi-line comment with description on the first line after "/*", i.e. /* * We prefer this over... */ /* comments like * this (notice the first line) */ Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Jun 6, 2009 at 16:43 UTC 4c42aa1a1359b2571b51c3a3093f29c7b25c54c4
2 files changed +79 -52
http-push.c
+29 -19
@@ -276,7 +276,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
276 struct transfer_request *request = (struct transfer_request *)data;
277 do {
278 ssize_t retval = xwrite(request->local_fileno,
279 - (char *) ptr + posn, size - posn);
279 + (char *) ptr + posn, size - posn);
280 if (retval < 0)
281 return posn;
282 posn += retval;
@@ -289,7 +289,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
289 request->stream.avail_out = sizeof(expn);
290 request->zret = git_inflate(&request->stream, Z_SYNC_FLUSH);
291 git_SHA1_Update(&request->c, expn,
292 - sizeof(expn) - request->stream.avail_out);
292 + sizeof(expn) - request->stream.avail_out);
293 } while (request->stream.avail_in && request->zret == Z_OK);
294 data_received++;
295 return size;
@@ -323,7 +323,8 @@ static void start_fetch_loose(struct transfer_request *request)
323 error("fd leakage in start: %d", request->local_fileno);
324 request->local_fileno = open(request->tmpfile,
325 O_WRONLY | O_CREAT | O_EXCL, 0666);
326 - /* This could have failed due to the "lazy directory creation";
326 + /*
327 + * This could have failed due to the "lazy directory creation";
328 * try to mkdir the last path component.
329 */
330 if (request->local_fileno < 0 && errno == ENOENT) {
@@ -353,8 +354,10 @@ static void start_fetch_loose(struct transfer_request *request)
354 url = get_remote_object_url(repo->url, hex, 0);
355 request->url = xstrdup(url);
356
356 - /* If a previous temp file is present, process what was already
357 - fetched. */
357 + /*
358 + * If a previous temp file is present, process what was already
359 + * fetched.
360 + */
361 prevlocal = open(prevfile, O_RDONLY);
362 if (prevlocal != -1) {
363 do {
@@ -363,19 +366,20 @@ static void start_fetch_loose(struct transfer_request *request)
366 if (fwrite_sha1_file(prev_buf,
367 1,
368 prev_read,
366 - request) == prev_read) {
369 + request) == prev_read)
370 prev_posn += prev_read;
368 - } else {
371 + else
372 prev_read = -1;
370 - }
373 }
374 } while (prev_read > 0);
375 close(prevlocal);
376 }
377 unlink_or_warn(prevfile);
378
377 - /* Reset inflate/SHA1 if there was an error reading the previous temp
378 - file; also rewind to the beginning of the local file. */
379 + /*
380 + * Reset inflate/SHA1 if there was an error reading the previous temp
381 + * file; also rewind to the beginning of the local file.
382 + */
383 if (prev_read == -1) {
384 memset(&request->stream, 0, sizeof(request->stream));
385 git_inflate_init(&request->stream);
@@ -398,8 +402,10 @@ static void start_fetch_loose(struct transfer_request *request)
402 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
403 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
404
401 - /* If we have successfully processed data from a previous fetch
402 - attempt, only fetch the data we don't already have. */
405 + /*
406 + * If we have successfully processed data from a previous fetch
407 + * attempt, only fetch the data we don't already have.
408 + */
409 if (prev_posn>0) {
410 if (push_verbosely)
411 fprintf(stderr,
@@ -514,8 +520,10 @@ static void start_fetch_packed(struct transfer_request *request)
520 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
521 slot->local = packfile;
522
517 - /* If there is data present from a previous transfer attempt,
518 - resume where it left off */
523 + /*
524 + * If there is data present from a previous transfer attempt,
525 + * resume where it left off
526 + */
527 prev_posn = ftell(packfile);
528 if (prev_posn>0) {
529 if (push_verbosely)
@@ -780,7 +788,8 @@ static void finish_request(struct transfer_request *request)
788 aborted = 1;
789 }
790 } else if (request->state == RUN_FETCH_LOOSE) {
783 - close(request->local_fileno); request->local_fileno = -1;
791 + close(request->local_fileno);
792 + request->local_fileno = -1;
793
794 if (request->curl_result != CURLE_OK &&
795 request->http_code != 416) {
@@ -803,9 +812,8 @@ static void finish_request(struct transfer_request *request)
812 move_temp_to_file(
813 request->tmpfile,
814 request->filename);
806 - if (request->rename == 0) {
815 + if (request->rename == 0)
816 request->obj->flags |= (LOCAL | REMOTE);
808 - }
817 }
818 }
819
@@ -1010,8 +1018,10 @@ static int fetch_index(unsigned char *sha1)
1018 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
1019 slot->local = indexfile;
1020
1013 - /* If there is data present from a previous transfer attempt,
1014 - resume where it left off */
1021 + /*
1022 + * If there is data present from a previous transfer attempt,
1023 + * resume where it left off
1024 + */
1025 prev_posn = ftell(indexfile);
1026 if (prev_posn>0) {
1027 if (push_verbosely)
http-walker.c
+50 -33
@@ -71,7 +71,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
71 struct object_request *obj_req = (struct object_request *)data;
72 do {
73 ssize_t retval = xwrite(obj_req->local,
74 - (char *) ptr + posn, size - posn);
74 + (char *) ptr + posn, size - posn);
75 if (retval < 0)
76 return posn;
77 posn += retval;
@@ -84,7 +84,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
84 obj_req->stream.avail_out = sizeof(expn);
85 obj_req->zret = git_inflate(&obj_req->stream, Z_SYNC_FLUSH);
86 git_SHA1_Update(&obj_req->c, expn,
87 - sizeof(expn) - obj_req->stream.avail_out);
87 + sizeof(expn) - obj_req->stream.avail_out);
88 } while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
89 data_received++;
90 return size;
@@ -119,7 +119,8 @@ static void start_object_request(struct walker *walker,
119 error("fd leakage in start: %d", obj_req->local);
120 obj_req->local = open(obj_req->tmpfile,
121 O_WRONLY | O_CREAT | O_EXCL, 0666);
122 - /* This could have failed due to the "lazy directory creation";
122 + /*
123 + * This could have failed due to the "lazy directory creation";
124 * try to mkdir the last path component.
125 */
126 if (obj_req->local < 0 && errno == ENOENT) {
@@ -158,8 +159,10 @@ static void start_object_request(struct walker *walker,
159 strcpy(posn, hex + 2);
160 strcpy(obj_req->url, url);
161
161 - /* If a previous temp file is present, process what was already
162 - fetched. */
162 + /*
163 + * If a previous temp file is present, process what was already
164 + * fetched.
165 + */
166 prevlocal = open(prevfile, O_RDONLY);
167 if (prevlocal != -1) {
168 do {
@@ -168,19 +171,20 @@ static void start_object_request(struct walker *walker,
171 if (fwrite_sha1_file(prev_buf,
172 1,
173 prev_read,
171 - obj_req) == prev_read) {
174 + obj_req) == prev_read)
175 prev_posn += prev_read;
173 - } else {
176 + else
177 prev_read = -1;
175 - }
178 }
179 } while (prev_read > 0);
180 close(prevlocal);
181 }
182 unlink_or_warn(prevfile);
183
182 - /* Reset inflate/SHA1 if there was an error reading the previous temp
183 - file; also rewind to the beginning of the local file. */
184 + /*
185 + * Reset inflate/SHA1 if there was an error reading the previous temp
186 + * file; also rewind to the beginning of the local file.
187 + */
188 if (prev_read == -1) {
189 memset(&obj_req->stream, 0, sizeof(obj_req->stream));
190 git_inflate_init(&obj_req->stream);
@@ -203,8 +207,10 @@ static void start_object_request(struct walker *walker,
207 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
208 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
209
206 - /* If we have successfully processed data from a previous fetch
207 - attempt, only fetch the data we don't already have. */
210 + /*
211 + * If we have successfully processed data from a previous fetch
212 + * attempt, only fetch the data we don't already have.
213 + */
214 if (prev_posn>0) {
215 if (walker->get_verbosely)
216 fprintf(stderr,
@@ -221,7 +227,8 @@ static void start_object_request(struct walker *walker,
227 if (!start_active_slot(slot)) {
228 obj_req->state = ABORTED;
229 obj_req->slot = NULL;
224 - close(obj_req->local); obj_req->local = -1;
230 + close(obj_req->local);
231 + obj_req->local = -1;
232 free(obj_req->url);
233 return;
234 }
@@ -231,7 +238,8 @@ static void finish_object_request(struct object_request *obj_req)
238 {
239 struct stat st;
240
234 - close(obj_req->local); obj_req->local = -1;
241 + close(obj_req->local);
242 + obj_req->local = -1;
243
244 if (obj_req->http_code == 416) {
245 fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
@@ -350,9 +358,8 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
358 object_queue_head = newreq;
359 } else {
360 tail = object_queue_head;
353 - while (tail->next != NULL) {
361 + while (tail->next != NULL)
362 tail = tail->next;
355 - }
363 tail->next = newreq;
364 }
365
@@ -401,8 +408,10 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
408 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
409 slot->local = indexfile;
410
404 - /* If there is data present from a previous transfer attempt,
405 - resume where it left off */
411 + /*
412 + * If there is data present from a previous transfer attempt,
413 + * resume where it left off
414 + */
415 prev_posn = ftell(indexfile);
416 if (prev_posn>0) {
417 if (walker->get_verbosely)
@@ -507,7 +516,8 @@ static void process_alternates_response(void *callback_data)
516 struct alt_base *newalt;
517 char *target = NULL;
518 if (data[i] == '/') {
510 - /* This counts
519 + /*
520 + * This counts
521 * http://git.host/pub/scm/linux.git/
522 * -----------here^
523 * so memcpy(dst, base, serverlen) will
@@ -520,7 +530,8 @@ static void process_alternates_response(void *callback_data)
530 okay = 1;
531 }
532 } else if (!memcmp(data + i, "../", 3)) {
523 - /* Relative URL; chop the corresponding
533 + /*
534 + * Relative URL; chop the corresponding
535 * number of subpath from base (and ../
536 * from data), and concatenate the result.
537 *
@@ -549,7 +560,7 @@ static void process_alternates_response(void *callback_data)
560 }
561 /* If the server got removed, give up. */
562 okay = strchr(base, ':') - base + 3 <
552 - serverlen;
563 + serverlen;
564 } else if (alt_req->http_specific) {
565 char *colon = strchr(data + i, ':');
566 char *slash = strchr(data + i, '/');
@@ -593,9 +604,11 @@ static void fetch_alternates(struct walker *walker, const char *base)
604 struct alternates_request alt_req;
605 struct walker_data *cdata = walker->data;
606
596 - /* If another request has already started fetching alternates,
597 - wait for them to arrive and return to processing this request's
598 - curl message */
607 + /*
608 + * If another request has already started fetching alternates,
609 + * wait for them to arrive and return to processing this request's
610 + * curl message
611 + */
612 #ifdef USE_CURL_MULTI
613 while (cdata->got_alternates == 0) {
614 step_active_slots();
@@ -615,8 +628,10 @@ static void fetch_alternates(struct walker *walker, const char *base)
628 url = xmalloc(strlen(base) + 31);
629 sprintf(url, "%s/objects/info/http-alternates", base);
630
618 - /* Use a callback to process the result, since another request
619 - may fail and need to have alternates loaded before continuing */
631 + /*
632 + * Use a callback to process the result, since another request
633 + * may fail and need to have alternates loaded before continuing
634 + */
635 slot = get_active_slot();
636 slot->callback_func = process_alternates_response;
637 alt_req.walker = walker;
@@ -762,8 +777,10 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
777 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
778 slot->local = packfile;
779
765 - /* If there is data present from a previous transfer attempt,
766 - resume where it left off */
780 + /*
781 + * If there is data present from a previous transfer attempt,
782 + * resume where it left off
783 + */
784 prev_posn = ftell(packfile);
785 if (prev_posn>0) {
786 if (walker->get_verbosely)
@@ -840,18 +857,18 @@ static int fetch_object(struct walker *walker, struct alt_base *repo, unsigned c
857 }
858
859 #ifdef USE_CURL_MULTI
843 - while (obj_req->state == WAITING) {
860 + while (obj_req->state == WAITING)
861 step_active_slots();
845 - }
862 #else
863 start_object_request(walker, obj_req);
864 #endif
865
850 - while (obj_req->state == ACTIVE) {
866 + while (obj_req->state == ACTIVE)
867 run_active_slot(obj_req->slot);
852 - }
868 +
869 if (obj_req->local != -1) {
854 - close(obj_req->local); obj_req->local = -1;
870 + close(obj_req->local);
871 + obj_req->local = -1;
872 }
873
874 if (obj_req->state == ABORTED) {