[prev in list] [next in list] [prev in thread] [next in thread]
List: git
Subject: Re: [PATCH] builtin-clone: Use is_dir_sep() instead of '/'
From: Johannes Sixt <johannes.sixt () telecom ! at>
Date: 2008-07-19 13:49:56
Message-ID: 200807191549.56402.johannes.sixt () telecom ! at
[Download RAW message or body]
On Samstag, 19. Juli 2008, Johannes Sixt wrote:
> On Samstag, 19. Juli 2008, Junio C Hamano wrote:
> > Ok, but the surrounding code in this function look very suspicious.
>
> How about this then?
>
> -- snip --
> builtin-clone: Rewrite guess_dir_name()
>
> The function has to do three small and independent tasks, but all of them
> were crammed into a single loop. This rewrites the function entirely by
> unrolling these tasks.
Sigh. I knew it, I knew it. If it had been that trivial, then Daniel had done
it this way in the first place. :-(
This needs to be squashed in. It makes sure that we handle 'foo/.git';
and .git was not stripped if we cloned from 'foo.git/'.
diff --git a/builtin-clone.c b/builtin-clone.c
index 91667d5..88616b3 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -98,10 +98,16 @@ static char *guess_dir_name(const char *repo, int is_bundle)
const char *end = repo + strlen(repo), *start, *dot;
/*
- * Strip trailing slashes
+ * Strip trailing slashes and /.git
*/
while (repo < end && is_dir_sep(end[-1]))
end--;
+ if (end - repo > 5 && is_dir_sep(end[-5]) &&
+ !strncmp(end - 4, ".git", 4)) {
+ end -= 5;
+ while (repo < end && is_dir_sep(end[-1]))
+ end--;
+ }
/*
* Find last component, but be prepared that repo could have
@@ -116,10 +122,10 @@ static char *guess_dir_name(const char *repo, int is_bundle)
* Strip .{bundle,git}.
*/
if (is_bundle) {
- if (end - start > 7 && !strcmp(end - 7, ".bundle"))
+ if (end - start > 7 && !strncmp(end - 7, ".bundle", 7))
end -= 7;
} else {
- if (end - start > 4 && !strcmp(end - 4, ".git"))
+ if (end - start > 4 && !strncmp(end - 4, ".git", 4))
end -= 4;
}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic