Skip to contentSkip to conversation

Ignore duplicated slashes in git-log

PATCH In review Andi Kleen 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Ignore duplicated slashes in git-log

When I use git-log ... path/name I seem to regularly typo path/name as path//name (with duplicated slashes) The normal kernel ignores these duplicated slashes according to POSIX so it's typically no problem, but git fails and cannot find the correct file name when this happens.

This patch fixes this case for git-log at least, by handling duplicated slashes as a single slash. I probably didn't change all places where file names are parsed in the source base, but this seems to be a relatively common place used by several sub commands. And at least for me fixing git-log is the most important case anyways.

Patch against git 1.5.4

-Andi

setup.c renamed from setup.c-o +5 -0
diff -u git-1.5.4/setup.c-o git-1.5.4/setup.c
@@ -7,6 +7,11 @@
 const char *prefix_path(const char *prefix, int len, const char *path)
 {
 	const char *orig = path;
+	char *s;
+
+	while ((s = strstr(path, "//")) != NULL)
+		memmove(s, s + 1, strlen(s));
+
 	for (;;) {
 		char c;
 		if (*path != '.')
#1 lore raw

Hi,

Quoted 4 lines · Andi Kleen

When I use git-log ... path/name I seem to regularly typo path/name as path//name (with duplicated slashes) The normal kernel ignores these duplicated slashes according to POSIX so it's typically no problem, but git fails and cannot find the correct file name when this happens.

This is only one case you want to fix. There are absolute paths, too, and series of "../".

Alas, Junio was quicker than you:

http://repo.or.cz/w/git.git?a=commitdiff;h=d089ebaad5315325d67db30176df1bbd7754fda9

Hth,
Dscho

author
#2 lore raw
Quoted 11 lines · Johannes Schindelin

Hi,

Quoted 4 lines · Andi Kleen

When I use git-log ... path/name I seem to regularly typo path/name as path//name (with duplicated slashes) The normal kernel ignores these duplicated slashes according to POSIX so it's typically no problem, but git fails and cannot find the correct file name when this happens.

This is only one case you want to fix. There are absolute paths, too, and series of "../".

It's hard to imagine anyone typoing sequences of ../ or ./, so at least I personally didn't feel the need to handle that.

Quoted 4 lines

Alas, Junio was quicker than you:

http://repo.or.cz/w/git.git?a=commitdiff;h=d089ebaad5315325d67db30176df1bbd7754fda9

Great.

-Andi