Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
clone: simplify string handling in guess_dir_name()
author
Sebastian Schuberth
<sschuberth@gmail.com>
Thu, 9 Jul 2015 18:24:08 +0000
(18:24 +0000)
committer
Junio C Hamano
<gitster@pobox.com>
Thu, 9 Jul 2015 21:21:29 +0000
(14:21 -0700)
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
351d06d
)
diff --git
a/builtin/clone.c
b/builtin/clone.c
index 4646922d6e1284c31dfdbd54d4042e065ade18a9..e18839d1077aaa383f601429541f2fc25972f36c 100644
(file)
--- 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;
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;
/*
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) {
- 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.
/*
* Replace sequences of 'control' characters and whitespace
* with one ascii space, remove leading and trailing spaces.