Skip to content

Commit

Permalink
Merge branch 'sk/windows-unc-path'
Browse files Browse the repository at this point in the history
* sk/windows-unc-path:
  Windows: allow using UNC path for git repository
  • Loading branch information
Junio C Hamano committed Jun 16, 2014
2 parents 4a43d4f + c2369bd commit b831636
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
1 change: 0 additions & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ int normalize_path_copy(char *dst, const char *src);
int longest_ancestor_length(const char *path, struct string_list *prefixes);
char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path);
int offset_1st_component(const char *path);

/* object replacement */
#define LOOKUP_REPLACE_OBJECT 1
Expand Down
24 changes: 24 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)
errno = EINVAL;
return -1;
}

int mingw_offset_1st_component(const char *path)
{
int offset = 0;
if (has_dos_drive_prefix(path))
offset = 2;

/* unc paths */
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {

/* skip server name */
char *pos = strpbrk(path + 2, "\\/");
if (!pos)
return 0; /* Error: malformed unc path */

do {
pos++;
} while (*pos && !is_dir_sep(*pos));

offset = pos - path;
}

return offset + is_dir_sep(path[offset]);
}
2 changes: 2 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
return ret;
}
#define find_last_dir_sep mingw_find_last_dir_sep
int mingw_offset_1st_component(const char *path);
#define offset_1st_component mingw_offset_1st_component
#define PATH_SEP ';'
#define PRIuMAX "I64u"
#define PRId64 "I64d"
Expand Down
4 changes: 4 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ extern char *gitbasename(char *);
#define has_dos_drive_prefix(path) 0
#endif

#ifndef offset_1st_component
#define offset_1st_component(path) (is_dir_sep((path)[0]))
#endif

#ifndef is_dir_sep
#define is_dir_sep(c) ((c) == '/')
#endif
Expand Down
7 changes: 0 additions & 7 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)
}
}
}

int offset_1st_component(const char *path)
{
if (has_dos_drive_prefix(path))
return 2 + is_dir_sep(path[2]);
return is_dir_sep(path[0]);
}

0 comments on commit b831636

Please sign in to comment.