summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-07-13 21:00:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-13 21:00:28 (GMT)
commit721f5bb8968ed6a6ec126fe28f679c17a6998e87 (patch)
tree02c5a8100b8a3c81d08efdf1b61dd2b50dd5a12e /builtin
parent313f52334b2b2b40ab0cedadaf081203de4284d7 (diff)
parent7e837c6477b59cc51756e241ccfee76068e5e379 (diff)
downloadgit-721f5bb8968ed6a6ec126fe28f679c17a6998e87.zip
git-721f5bb8968ed6a6ec126fe28f679c17a6998e87.tar.gz
git-721f5bb8968ed6a6ec126fe28f679c17a6998e87.tar.bz2
Merge branch 'ss/clone-guess-dir-name-simplify'
Code simplification. * ss/clone-guess-dir-name-simplify: clone: simplify string handling in guess_dir_name()
Diffstat (limited to 'builtin')
-rw-r--r--builtin/clone.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 00535d0..a72ff7e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -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.