All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Daniel Barkalow <barkalow@iabervon.org>,
	Hugo Mildenberger <Hugo.Mildenberger@namir.de>
Subject: Re: [PATCH 2/2] Improve the naming of guessed target repository for  git clone
Date: Thu, 14 May 2009 10:33:02 +0200	[thread overview]
Message-ID: <81b0412b0905140133l78def06kae0cb4798feaa4a9@mail.gmail.com> (raw)
In-Reply-To: <81b0412b0905132254n5046666t24f3887f1fd4e4d9@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2218 bytes --]

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>
---

2009/5/14 Alex Riesen <raa.lkml@gmail.com>:
> 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

[-- Attachment #2: 0002-Improve-the-naming-of-guessed-target-repository-for-.patch --]
[-- Type: application/octet-stream, Size: 2269 bytes --]

From 6d6075130afbdd35260e3e33c099f57d9faebe98 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Wed, 13 May 2009 18:32:06 +0200
Subject: [PATCH 2/2] 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>
---
 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


  parent reply	other threads:[~2009-05-14  8:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-11 20:08 git fails with control characters in trunk directory name Hugo Mildenberger
2009-05-12  6:51 ` Alex Riesen
2009-05-12  9:02   ` Hugo Mildenberger
2009-05-12 10:54     ` Alex Riesen
2009-05-12 13:57       ` Hugo Mildenberger
2009-05-12 14:59         ` Alex Riesen
2009-05-12 16:59           ` Hugo Mildenberger
2009-05-12 17:18             ` Alex Riesen
2009-05-12 17:24               ` [PATCH] Quote LF in urls git fetch saves in FETCH_HEAD Alex Riesen
2009-05-12 23:16                 ` Junio C Hamano
2009-05-13  6:06                   ` Alex Riesen
     [not found]                     ` <200905131340.31509.Hugo.Mildenberger@namir.de>
2009-05-13 12:10                       ` Alex Riesen
2009-05-13 14:49                         ` Hugo Mildenberger
2009-05-13 12:39                     ` Hugo Mildenberger
2009-05-13 15:18                     ` Daniel Barkalow
2009-05-13 16:09                       ` Alex Riesen
2009-05-13 17:07                         ` Alex Riesen
2009-05-13 17:12                         ` Daniel Barkalow
2009-05-13 18:11                           ` Alex Riesen
2009-05-13 18:23                       ` Junio C Hamano
2009-05-13 18:08                 ` [PATCH 1/2] " Alex Riesen
2009-05-13 20:53                   ` [PATCH 2/2] Improve the naming of guessed target repository for git clone Alex Riesen
2009-05-14  0:41                     ` Junio C Hamano
2009-05-14  5:54                       ` Alex Riesen
2009-05-14  6:35                         ` Junio C Hamano
2009-05-14  8:45                           ` Alex Riesen
2009-05-14 12:50                             ` Hugo Mildenberger
2009-05-14  8:33                         ` Alex Riesen [this message]
2009-05-16 17:49                           ` Junio C Hamano
2009-05-12 17:41             ` git fails with control characters in trunk directory name Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81b0412b0905140133l78def06kae0cb4798feaa4a9@mail.gmail.com \
    --to=raa.lkml@gmail.com \
    --cc=Hugo.Mildenberger@namir.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.