mirror of
https://github.com/git/git.git
synced 2026-02-04 23:16:38 +00:00
Refactor skipping DOS drive prefixes
Junio Hamano pointed out that there is an implicit assumption in pretty much all the code calling has_dos_drive_prefix(): it assumes 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. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
14
path.c
14
path.c
@@ -782,13 +782,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;
|
||||
}
|
||||
|
||||
@@ -943,11 +940,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)) {
|
||||
|
||||
Reference in New Issue
Block a user