Merge branch 'ss/clone-guess-dir-name-simplify' into maint

Code simplification.

* ss/clone-guess-dir-name-simplify:
  clone: simplify string handling in guess_dir_name()
This commit is contained in:
Junio C Hamano 2015-08-03 10:41:33 -07:00
commit de67af4a8f

View 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) static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
{ {
const char *end = repo + strlen(repo), *start; const char *end = repo + strlen(repo), *start;
size_t len;
char *dir; char *dir;
/* /*
@ -173,20 +174,12 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
/* /*
* Strip .{bundle,git}. * Strip .{bundle,git}.
*/ */
if (is_bundle) { strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len);
if (end - start > 7 && !strncmp(end - 7, ".bundle", 7))
end -= 7;
} else {
if (end - start > 4 && !strncmp(end - 4, ".git", 4))
end -= 4;
}
if (is_bare) { if (is_bare)
struct strbuf result = STRBUF_INIT; dir = xstrfmt("%.*s.git", (int)len, start);
strbuf_addf(&result, "%.*s.git", (int)(end - start), start); else
dir = strbuf_detach(&result, NULL); dir = xstrndup(start, len);
} else
dir = xstrndup(start, end - start);
/* /*
* Replace sequences of 'control' characters and whitespace * Replace sequences of 'control' characters and whitespace
* with one ascii space, remove leading and trailing spaces. * with one ascii space, remove leading and trailing spaces.