summaryrefslogtreecommitdiff
path: root/builtin-clone.c
diff options
context:
space:
mode:
authorAlex Riesen <raa.lkml@gmail.com>2009-05-13 16:32:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-05-17 02:43:29 (GMT)
commit8a94bc7bdc54db0d77058e63baf173ff932cba7c (patch)
treea4b4665570f762bc3987d4932179411e3e7a9b89 /builtin-clone.c
parent39d404d13774fac5ce4b7b180d2b8988eb6fd6c7 (diff)
downloadgit-8a94bc7bdc54db0d77058e63baf173ff932cba7c.zip
git-8a94bc7bdc54db0d77058e63baf173ff932cba7c.tar.gz
git-8a94bc7bdc54db0d77058e63baf173ff932cba7c.tar.bz2
Improve the naming of guessed target repository for git clone
Strip leading and trailing spaces off guessed target directory, and replace sequences of whitespace and 'control' characters with one space character. User still can have any name by specifying it explicitely after url. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-clone.c')
-rw-r--r--builtin-clone.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/builtin-clone.c b/builtin-clone.c
index 880373f..d068b7e 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -104,11 +104,12 @@ 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;
+ char *dir;
/*
- * Strip trailing slashes and /.git
+ * Strip trailing spaces, slashes and /.git
*/
- while (repo < end && is_dir_sep(end[-1]))
+ while (repo < end && (is_dir_sep(end[-1]) || isspace(end[-1])))
end--;
if (end - repo > 5 && is_dir_sep(end[-5]) &&
!strncmp(end - 4, ".git", 4)) {
@@ -140,10 +141,33 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
if (is_bare) {
struct strbuf result = STRBUF_INIT;
strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
- return strbuf_detach(&result, 0);
+ dir = strbuf_detach(&result, 0);
+ } else
+ dir = xstrndup(start, end - start);
+ /*
+ * Replace sequences of 'control' characters and whitespace
+ * with one ascii space, remove leading and trailing spaces.
+ */
+ if (*dir) {
+ char *out = dir;
+ int prev_space = 1 /* strip leading whitespace */;
+ for (end = dir; *end; ++end) {
+ char ch = *end;
+ if ((unsigned char)ch < '\x20')
+ ch = '\x20';
+ if (isspace(ch)) {
+ if (prev_space)
+ continue;
+ prev_space = 1;
+ } else
+ prev_space = 0;
+ *out++ = ch;
+ }
+ *out = '\0';
+ if (out > dir && prev_space)
+ out[-1] = '\0';
}
-
- return xstrndup(start, end - start);
+ return dir;
}
static void strip_trailing_slashes(char *dir)