summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-01-12 07:57:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-01-12 18:39:40 (GMT)
commit2f36eed936f70105e80681aafac645ff34acc667 (patch)
tree5a226a4147e6f56a021d0492b713c39907a7b4da /path.c
parent833e48259e23aea76f3765d28d1b2200332301f7 (diff)
downloadgit-2f36eed936f70105e80681aafac645ff34acc667.zip
git-2f36eed936f70105e80681aafac645ff34acc667.tar.gz
git-2f36eed936f70105e80681aafac645ff34acc667.tar.bz2
Refactor skipping DOS drive prefixes
Junio noticed that there is an implicit assumption in pretty much all the code calling has_dos_drive_prefix(): it forces all of its callsites to hardcode the knowledge that the DOS drive prefix is always two bytes long. While this assumption is pretty safe, we can still make the code more readable and less error-prone by introducing a function that skips the DOS drive prefix safely. While at it, we change the has_dos_drive_prefix() return value: it now returns the number of bytes to be skipped if there is a DOS drive prefix. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/path.c b/path.c
index 38f2ebd..747d6da 100644
--- a/path.c
+++ b/path.c
@@ -544,13 +544,10 @@ const char *relative_path(const char *in, const char *prefix,
else if (!prefix_len)
return in;
- if (have_same_root(in, prefix)) {
+ if (have_same_root(in, prefix))
/* bypass dos_drive, for "c:" is identical to "C:" */
- if (has_dos_drive_prefix(in)) {
- i = 2;
- j = 2;
- }
- } else {
+ i = j = has_dos_drive_prefix(in);
+ else {
return in;
}
@@ -703,11 +700,10 @@ const char *remove_leading_path(const char *in, const char *prefix)
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
{
char *dst0;
+ int i;
- if (has_dos_drive_prefix(src)) {
+ for (i = has_dos_drive_prefix(src); i > 0; i--)
*dst++ = *src++;
- *dst++ = *src++;
- }
dst0 = dst;
if (is_dir_sep(*src)) {