Merge tag 'gitgui-0.21.0' of git://repo.or.cz/git-gui
[gitweb.git] / builtin / fetch-pack.c
index 0402e2756b9ad76972514153c2d49e77ce1babef..cfe9e447c27469407ab439bacb540a4d0b68d4b4 100644 (file)
@@ -10,33 +10,34 @@ static const char fetch_pack_usage[] =
 "[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
 "[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
 
-static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
-                                const char *name, int namelen)
+static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
+                            const char *name)
 {
-       struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);
+       struct ref *ref;
        struct object_id oid;
-       const int chunksz = GIT_SHA1_HEXSZ + 1;
 
-       if (namelen > chunksz && name[chunksz - 1] == ' ' &&
-               !get_oid_hex(name, &oid)) {
-               oidcpy(&ref->old_oid, &oid);
-               name += chunksz;
-               namelen -= chunksz;
+       if (!get_oid_hex(name, &oid)) {
+               if (name[GIT_SHA1_HEXSZ] == ' ') {
+                       /* <sha1> <ref>, find refname */
+                       name += GIT_SHA1_HEXSZ + 1;
+               } else if (name[GIT_SHA1_HEXSZ] == '\0') {
+                       ; /* <sha1>, leave sha1 as name */
+               } else {
+                       /* <ref>, clear cruft from oid */
+                       oidclr(&oid);
+               }
+       } else {
+               /* <ref>, clear cruft from get_oid_hex */
+               oidclr(&oid);
        }
 
-       memcpy(ref->name, name, namelen);
-       ref->name[namelen] = '\0';
+       ref = alloc_ref(name);
+       oidcpy(&ref->old_oid, &oid);
        (*nr)++;
        ALLOC_GROW(*sought, *nr, *alloc);
        (*sought)[*nr - 1] = ref;
 }
 
-static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
-                            const char *string)
-{
-       add_sought_entry_mem(sought, nr, alloc, string, strlen(string));
-}
-
 int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 {
        int i, ret;
@@ -50,6 +51,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
        struct child_process *conn;
        struct fetch_pack_args args;
        struct sha1_array shallow = SHA1_ARRAY_INIT;
+       struct string_list deepen_not = STRING_LIST_INIT_DUP;
 
        packet_trace_identity("fetch-pack");
 
@@ -108,6 +110,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                        args.deepen_since = xstrdup(arg);
                        continue;
                }
+               if (skip_prefix(arg, "--shallow-exclude=", &arg)) {
+                       string_list_append(&deepen_not, arg);
+                       continue;
+               }
+               if (!strcmp(arg, "--deepen-relative")) {
+                       args.deepen_relative = 1;
+                       continue;
+               }
                if (!strcmp("--no-progress", arg)) {
                        args.no_progress = 1;
                        continue;
@@ -135,6 +145,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                }
                usage(fetch_pack_usage);
        }
+       if (deepen_not.nr)
+               args.deepen_not = &deepen_not;
 
        if (i < argc)
                dest = argv[i++];