Merge branch 'ss/clone-guess-dir-name-simplify'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2015 21:00:28 +0000 (14:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2015 21:00:28 +0000 (14:00 -0700)
Code simplification.

* ss/clone-guess-dir-name-simplify:
clone: simplify string handling in guess_dir_name()

1  2 
builtin/clone.c
diff --combined builtin/clone.c
index 00535d0178f1a0ee562bf008e8b072f68410dc3d,e18839d1077aaa383f601429541f2fc25972f36c..a72ff7e0098da9c89f6000e724ea097e3403601f
@@@ -147,6 -147,7 +147,7 @@@ static char *get_repo_path(const char *
  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;
  
        /*
        /*
         * 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,17 -277,16 +277,17 @@@ static void copy_alternates(struct strb
        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);