Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'ss/clone-guess-dir-name-simplify'
Code simplification.

* ss/clone-guess-dir-name-simplify:
  clone: simplify string handling in guess_dir_name()
  • Loading branch information
Junio C Hamano committed Jul 13, 2015
2 parents 313f523 + 7e837c6 commit 721f5bb
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions builtin/clone.c
Expand Up @@ -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;

/*
Expand All @@ -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.
Expand Down

0 comments on commit 721f5bb

Please sign in to comment.