Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
apply: handle filenames with double slashes better
author
Michal Marek
<mmarek@suse.cz>
Thu, 21 May 2009 12:25:11 +0000
(14:25 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Sun, 24 May 2009 20:52:13 +0000
(13:52 -0700)
When there are duplicated slashes in pathnames, like this:
--- a/perl//Git.pm
+++ b/perl//Git.pm
@@ -1358,3 +1358,4 @@
1; # Famous last words
+# test
the paths gleaned from the patch header won't be found in the index and
cause "apply --index" and "apply --cached" to fail.
Fix this by squashing the duplicated slashes upon input.
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-apply.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
7a7eb51
)
diff --git
a/builtin-apply.c
b/builtin-apply.c
index 8a3771e87e1ef2ac7a1ee70133b8206f0f18cbb5..660aab95df2cb4520601ae212f8c3f2abba0e408 100644
(file)
--- a/
builtin-apply.c
+++ b/
builtin-apply.c
@@
-320,6
+320,20
@@
static int name_terminate(const char *name, int namelen, int c, int terminate)
return 1;
}
return 1;
}
+/* remove double slashes to make --index work with such filenames */
+static char *squash_slash(char *name)
+{
+ int i = 0, j = 0;
+
+ while (name[i]) {
+ if ((name[j++] = name[i++]) == '/')
+ while (name[i] == '/')
+ i++;
+ }
+ name[j] = '\0';
+ return name;
+}
+
static char *find_name(const char *line, char *def, int p_value, int terminate)
{
int len;
static char *find_name(const char *line, char *def, int p_value, int terminate)
{
int len;
@@
-349,7
+363,7
@@
static char *find_name(const char *line, char *def, int p_value, int terminate)
free(def);
if (root)
strbuf_insert(&name, 0, root, root_len);
free(def);
if (root)
strbuf_insert(&name, 0, root, root_len);
- return s
trbuf_detach(&name, NULL
);
+ return s
quash_slash(strbuf_detach(&name, NULL)
);
}
}
strbuf_release(&name);
}
}
strbuf_release(&name);
@@
-369,10
+383,10
@@
static char *find_name(const char *line, char *def, int p_value, int terminate)
start = line;
}
if (!start)
start = line;
}
if (!start)
- return
def
;
+ return
squash_slash(def)
;
len = line - start;
if (!len)
len = line - start;
if (!len)
- return
def
;
+ return
squash_slash(def)
;
/*
* Generally we prefer the shorter name, especially
/*
* Generally we prefer the shorter name, especially
@@
-383,7
+397,7
@@
static char *find_name(const char *line, char *def, int p_value, int terminate)
if (def) {
int deflen = strlen(def);
if (deflen < len && !strncmp(start, def, deflen))
if (def) {
int deflen = strlen(def);
if (deflen < len && !strncmp(start, def, deflen))
- return
def
;
+ return
squash_slash(def)
;
free(def);
}
free(def);
}
@@
-392,10
+406,10
@@
static char *find_name(const char *line, char *def, int p_value, int terminate)
strcpy(ret, root);
memcpy(ret + root_len, start, len);
ret[root_len + len] = '\0';
strcpy(ret, root);
memcpy(ret + root_len, start, len);
ret[root_len + len] = '\0';
- return
ret
;
+ return
squash_slash(ret)
;
}
}
- return
xmemdupz(start, len
);
+ return
squash_slash(xmemdupz(start, len)
);
}
static int count_slashes(const char *cp)
}
static int count_slashes(const char *cp)