path.c: Use vsnpath() in the implementation of git_path()

The current implementation of git_path() is essentially the same as that of vsnpath(), with two minor differences. First, git_path() currently insists that the git directory path is no longer than PATH_MAX-100 characters in length. However, vsnpath() does not attempt this arbitrary 100 character reservation for the remaining path components. Second, vsnpath() uses the "is_dir_sep()" macro, rather than comparing directly to '/', to determine if the git_dir path component ends with a path separator. In order to benefit from the above improvements, along with increased compatability with git_snpath() and git_pathdup(), we reimplement the git_path() function using vsnpath(). Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Sep 4, 2012 at 18:29 UTC 5c44252e13db2324d7c79d2b498886a925055111
1 file changed +3 -12
path.c
+3 -12
@@ -119,23 +119,14 @@ char *mkpath(const char *fmt, ...)
119
120 char *git_path(const char *fmt, ...)
121 {
122 - const char *git_dir = get_git_dir();
122 char *pathname = get_pathname();
123 va_list args;
125 - unsigned len;
124 + char *ret;
125
127 - len = strlen(git_dir);
128 - if (len > PATH_MAX-100)
129 - return bad_path;
130 - memcpy(pathname, git_dir, len);
131 - if (len && git_dir[len-1] != '/')
132 - pathname[len++] = '/';
126 va_start(args, fmt);
134 - len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
127 + ret = vsnpath(pathname, PATH_MAX, fmt, args);
128 va_end(args);
136 - if (len >= PATH_MAX)
137 - return bad_path;
138 - return cleanup_path(pathname);
129 + return ret;
130 }
131
132 void home_config_paths(char **global, char **xdg, char *file)