Documentation: add missing article in rev-list-options.txt
[gitweb.git] / fetch-pack.c
index 90d47da8a902f24bb6a7ae63654a104626751b1e..655ee642564e3ada5b782dd6fa2d2c799f340978 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "commit.h"
@@ -26,6 +27,7 @@ static int agent_supported;
 static struct lock_file shallow_lock;
 static const char *alternate_shallow_file;
 
+/* Remember to update object flag allocation in object.h */
 #define COMPLETE       (1U << 0)
 #define COMMON         (1U << 1)
 #define COMMON_REF     (1U << 2)
@@ -188,20 +190,23 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
        int len;
        char *line = packet_read_line(fd, &len);
+       const char *arg;
 
        if (!len)
                die("git fetch-pack: expected ACK/NAK, got EOF");
        if (!strcmp(line, "NAK"))
                return NAK;
-       if (starts_with(line, "ACK ")) {
-               if (!get_sha1_hex(line+4, result_sha1)) {
-                       if (len < 45)
+       if (skip_prefix(line, "ACK ", &arg)) {
+               if (!get_sha1_hex(arg, result_sha1)) {
+                       arg += 40;
+                       len -= arg - line;
+                       if (len < 1)
                                return ACK;
-                       if (strstr(line+45, "continue"))
+                       if (strstr(arg, "continue"))
                                return ACK_continue;
-                       if (strstr(line+45, "common"))
+                       if (strstr(arg, "common"))
                                return ACK_common;
-                       if (strstr(line+45, "ready"))
+                       if (strstr(arg, "ready"))
                                return ACK_ready;
                        return ACK;
                }
@@ -318,18 +323,19 @@ static int find_common(struct fetch_pack_args *args,
 
        if (args->depth > 0) {
                char *line;
+               const char *arg;
                unsigned char sha1[20];
 
                send_request(args, fd[1], &req_buf);
                while ((line = packet_read_line(fd[0], NULL))) {
-                       if (starts_with(line, "shallow ")) {
-                               if (get_sha1_hex(line + 8, sha1))
+                       if (skip_prefix(line, "shallow ", &arg)) {
+                               if (get_sha1_hex(arg, sha1))
                                        die("invalid shallow line: %s", line);
                                register_shallow(sha1);
                                continue;
                        }
-                       if (starts_with(line, "unshallow ")) {
-                               if (get_sha1_hex(line + 10, sha1))
+                       if (skip_prefix(line, "unshallow ", &arg)) {
+                               if (get_sha1_hex(arg, sha1))
                                        die("invalid unshallow line: %s", line);
                                if (!lookup_object(sha1))
                                        die("object not found: %s", line);
@@ -506,7 +512,7 @@ static void filter_refs(struct fetch_pack_args *args,
                int keep = 0;
                next = ref->next;
 
-               if (!memcmp(ref->name, "refs/", 5) &&
+               if (starts_with(ref->name, "refs/") &&
                    check_refname_format(ref->name, 0))
                        ; /* trash */
                else {
@@ -661,7 +667,7 @@ static int get_pack(struct fetch_pack_args *args,
        char hdr_arg[256];
        const char **av, *cmd_name;
        int do_keep = args->keep_pack;
-       struct child_process cmd;
+       struct child_process cmd = CHILD_PROCESS_INIT;
        int ret;
 
        memset(&demux, 0, sizeof(demux));
@@ -680,7 +686,6 @@ static int get_pack(struct fetch_pack_args *args,
        else
                demux.out = xd[0];
 
-       memset(&cmd, 0, sizeof(cmd));
        cmd.argv = argv;
        av = argv;
        *hdr_arg = 0;
@@ -864,34 +869,15 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        return ref;
 }
 
-static int fetch_pack_config(const char *var, const char *value, void *cb)
+static void fetch_pack_config(void)
 {
-       if (strcmp(var, "fetch.unpacklimit") == 0) {
-               fetch_unpack_limit = git_config_int(var, value);
-               return 0;
-       }
-
-       if (strcmp(var, "transfer.unpacklimit") == 0) {
-               transfer_unpack_limit = git_config_int(var, value);
-               return 0;
-       }
-
-       if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
-               prefer_ofs_delta = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "fetch.fsckobjects")) {
-               fetch_fsck_objects = git_config_bool(var, value);
-               return 0;
-       }
-
-       if (!strcmp(var, "transfer.fsckobjects")) {
-               transfer_fsck_objects = git_config_bool(var, value);
-               return 0;
-       }
+       git_config_get_int("fetch.unpacklimit", &fetch_unpack_limit);
+       git_config_get_int("transfer.unpacklimit", &transfer_unpack_limit);
+       git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta);
+       git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects);
+       git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects);
 
-       return git_default_config(var, value, cb);
+       git_config(git_default_config, NULL);
 }
 
 static void fetch_pack_setup(void)
@@ -899,7 +885,7 @@ static void fetch_pack_setup(void)
        static int did_setup;
        if (did_setup)
                return;
-       git_config(fetch_pack_config, NULL);
+       fetch_pack_config();
        if (0 <= transfer_unpack_limit)
                unpack_limit = transfer_unpack_limit;
        else if (0 <= fetch_unpack_limit)