t7063: use --force-untracked-cache to speed up a bit
[gitweb.git] / builtin / clone.c
index 4646922d6e1284c31dfdbd54d4042e065ade18a9..a72ff7e0098da9c89f6000e724ea097e3403601f 100644 (file)
@@ -147,6 +147,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
 static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
 {
        const char *end = repo + strlen(repo), *start;
+       size_t len;
        char *dir;
 
        /*
@@ -173,20 +174,12 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
        /*
         * Strip .{bundle,git}.
         */
-       if (is_bundle) {
-               if (end - start > 7 && !strncmp(end - 7, ".bundle", 7))
-                       end -= 7;
-       } else {
-               if (end - start > 4 && !strncmp(end - 4, ".git", 4))
-                       end -= 4;
-       }
+       strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len);
 
-       if (is_bare) {
-               struct strbuf result = STRBUF_INIT;
-               strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
-               dir = strbuf_detach(&result, NULL);
-       } else
-               dir = xstrndup(start, end - start);
+       if (is_bare)
+               dir = xstrfmt("%.*s.git", (int)len, start);
+       else
+               dir = xstrndup(start, len);
        /*
         * Replace sequences of 'control' characters and whitespace
         * with one ascii space, remove leading and trailing spaces.
@@ -284,16 +277,17 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
        struct strbuf line = STRBUF_INIT;
 
        while (strbuf_getline(&line, in, '\n') != EOF) {
-               char *abs_path, abs_buf[PATH_MAX];
+               char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
                if (is_absolute_path(line.buf)) {
                        add_to_alternates_file(line.buf);
                        continue;
                }
-               abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
-               normalize_path_copy(abs_buf, abs_path);
-               add_to_alternates_file(abs_buf);
+               abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
+               normalize_path_copy(abs_path, abs_path);
+               add_to_alternates_file(abs_path);
+               free(abs_path);
        }
        strbuf_release(&line);
        fclose(in);