Alex Riesen [off-list ref] writes:
Strip trailing spaces off guessed target directory in builtin clone,
and replace 'control' characters with an ASCII space.
User still can have any name by specifying it explicitely after url.
Signed-off-by: Alex Riesen <redacted>
---
This should take care of accidental pastings inside shell quotes.
At least for the local part of the operation.
Now I'm looking at the code and think I should have stripped the
heading whitespace as well. It is much less likely to happen, though.
quoted hunk
@@ -140,10 +141,21 @@ 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);
+ dir = strbuf_detach(&result, 0);
+ } else
+ dir = xstrndup(start, end - start);
+ /* replace all 'control' characters with ascii space */
+ for (start = dir; *start; ++start)
+ if (*(const unsigned char *)start < 32u)
+ dir[start - dir] = '\x20';
What's this strange mixture of 32u and '\x20'?
+ /* remove trailing spaces */
+ if (dir < start)
+ for (end = start; dir < --end; )
+ if (!isspace(*end))
+ break;
+ else
+ dir[end - dir] = '\0';
+ return dir;
}
Honestly, I regret having asked if there was a 2/2 ;-)
What's the point of this change, now that you have a fix in 1/2? Who are
you helping with this patch?
2009/5/14 Junio C Hamano [off-list ref]:
Alex Riesen [off-list ref] writes:
quoted
+ /* replace all 'control' characters with ascii space */
+ for (start = dir; *start; ++start)
+ if (*(const unsigned char *)start < 32u)
+ dir[start - dir] = '\x20';
What's this strange mixture of 32u and '\x20'?
Not sure myself. I probably wanted visibility, and somehow ended
up using different presentations.
quoted
+ /* remove trailing spaces */
+ if (dir < start)
+ for (end = start; dir < --end; )
+ if (!isspace(*end))
+ break;
+ else
+ dir[end - dir] = '\0';
+ return dir;
}
Honestly, I regret having asked if there was a 2/2 ;-)
What's the point of this change, now that you have a fix in 1/2? Who are
you helping with this patch?
Without this the _automatically_ generated names for cloned repositories
have all the whitespace around them. As you cannot sanely depend on
automatically
generated names, I thought that making them simpler will make sense.
But I should complete the patch: remove heading whitespace, and replace
multiple spaces and control characters with one space.
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 <redacted>
---
2009/5/14 Alex Riesen [off-list ref]:
But I should complete the patch: remove heading whitespace, and replace
multiple spaces and control characters with one space.
Done.
builtin-clone.c | 34 +++++++++++++++++++++++++++++-----
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)
--
1.6.3.1.37.g5d96e