Skip to content

Commit 8c11b25

Browse files
committed
Merge branch 'rj/path-cleanup'
* rj/path-cleanup: Call mkpathdup() rather than xstrdup(mkpath(...)) Call git_pathdup() rather than xstrdup(git_path("...")) path.c: Use vsnpath() in the implementation of git_path() path.c: Don't discard the return value of vsnpath() path.c: Remove the 'git_' prefix from a file scope function
2 parents 0ca416f + 4e2d094 commit 8c11b25

File tree

7 files changed

+24
-30
lines changed

7 files changed

+24
-30
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ static int check_ancestors(const char *prefix)
833833
*/
834834
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
835835
{
836-
char *filename = xstrdup(git_path("BISECT_ANCESTORS_OK"));
836+
char *filename = git_pathdup("BISECT_ANCESTORS_OK");
837837
struct stat st;
838838
int fd;
839839

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
260260

261261
static int edit_patch(int argc, const char **argv, const char *prefix)
262262
{
263-
char *file = xstrdup(git_path("ADD_EDIT.patch"));
263+
char *file = git_pathdup("ADD_EDIT.patch");
264264
const char *apply_argv[] = { "apply", "--recount", "--cached",
265265
NULL, NULL };
266266
struct child_process child;
@@ -303,6 +303,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
303303
die (_("Could not apply '%s'"), file);
304304

305305
unlink(file);
306+
free(file);
306307
return 0;
307308
}
308309

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
197197

198198
free(name);
199199

200-
name = xstrdup(mkpath(fmt, bname.buf));
200+
name = mkpathdup(fmt, bname.buf);
201201
if (read_ref(name, sha1)) {
202202
error(remote_branch
203203
? _("remote branch '%s' not found.")

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
236236
/* Beware: real_path() and mkpath() return static buffer */
237237
ref_git = xstrdup(real_path(item->string));
238238
if (is_directory(mkpath("%s/.git/objects", ref_git))) {
239-
char *ref_git_git = xstrdup(mkpath("%s/.git", ref_git));
239+
char *ref_git_git = mkpathdup("%s/.git", ref_git);
240240
free(ref_git);
241241
ref_git = ref_git_git;
242242
} else if (!is_directory(mkpath("%s/objects", ref_git)))
@@ -700,7 +700,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
700700
git_dir = xstrdup(dir);
701701
else {
702702
work_tree = dir;
703-
git_dir = xstrdup(mkpath("%s/.git", dir));
703+
git_dir = mkpathdup("%s/.git", dir);
704704
}
705705

706706
if (!option_bare) {

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
169169

170170
prune_packed_objects(show_only);
171171
remove_temporary_files(get_object_directory());
172-
s = xstrdup(mkpath("%s/pack", get_object_directory()));
172+
s = mkpathdup("%s/pack", get_object_directory());
173173
remove_temporary_files(s);
174174
free(s);
175175
return 0;

merge-recursive.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,14 @@ static int merge_3way(struct merge_options *o,
844844
if (strcmp(a->path, b->path) ||
845845
(o->ancestor != NULL && strcmp(a->path, one->path) != 0)) {
846846
base_name = o->ancestor == NULL ? NULL :
847-
xstrdup(mkpath("%s:%s", o->ancestor, one->path));
848-
name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
849-
name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
847+
mkpathdup("%s:%s", o->ancestor, one->path);
848+
name1 = mkpathdup("%s:%s", branch1, a->path);
849+
name2 = mkpathdup("%s:%s", branch2, b->path);
850850
} else {
851851
base_name = o->ancestor == NULL ? NULL :
852-
xstrdup(mkpath("%s", o->ancestor));
853-
name1 = xstrdup(mkpath("%s", branch1));
854-
name2 = xstrdup(mkpath("%s", branch2));
852+
mkpathdup("%s", o->ancestor);
853+
name1 = mkpathdup("%s", branch1);
854+
name2 = mkpathdup("%s", branch2);
855855
}
856856

857857
read_mmblob(&orig, one->sha1);
@@ -861,6 +861,7 @@ static int merge_3way(struct merge_options *o,
861861
merge_status = ll_merge(result_buf, a->path, &orig, base_name,
862862
&src1, name1, &src2, name2, &ll_opts);
863863

864+
free(base_name);
864865
free(name1);
865866
free(name2);
866867
free(orig.ptr);

path.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
4848
return cleanup_path(buf);
4949
}
5050

51-
static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)
51+
static char *vsnpath(char *buf, size_t n, const char *fmt, va_list args)
5252
{
5353
const char *git_dir = get_git_dir();
5454
size_t len;
@@ -70,21 +70,22 @@ static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)
7070

7171
char *git_snpath(char *buf, size_t n, const char *fmt, ...)
7272
{
73+
char *ret;
7374
va_list args;
7475
va_start(args, fmt);
75-
(void)git_vsnpath(buf, n, fmt, args);
76+
ret = vsnpath(buf, n, fmt, args);
7677
va_end(args);
77-
return buf;
78+
return ret;
7879
}
7980

8081
char *git_pathdup(const char *fmt, ...)
8182
{
82-
char path[PATH_MAX];
83+
char path[PATH_MAX], *ret;
8384
va_list args;
8485
va_start(args, fmt);
85-
(void)git_vsnpath(path, sizeof(path), fmt, args);
86+
ret = vsnpath(path, sizeof(path), fmt, args);
8687
va_end(args);
87-
return xstrdup(path);
88+
return xstrdup(ret);
8889
}
8990

9091
char *mkpathdup(const char *fmt, ...)
@@ -118,23 +119,14 @@ char *mkpath(const char *fmt, ...)
118119

119120
char *git_path(const char *fmt, ...)
120121
{
121-
const char *git_dir = get_git_dir();
122122
char *pathname = get_pathname();
123123
va_list args;
124-
unsigned len;
124+
char *ret;
125125

126-
len = strlen(git_dir);
127-
if (len > PATH_MAX-100)
128-
return bad_path;
129-
memcpy(pathname, git_dir, len);
130-
if (len && git_dir[len-1] != '/')
131-
pathname[len++] = '/';
132126
va_start(args, fmt);
133-
len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args);
127+
ret = vsnpath(pathname, PATH_MAX, fmt, args);
134128
va_end(args);
135-
if (len >= PATH_MAX)
136-
return bad_path;
137-
return cleanup_path(pathname);
129+
return ret;
138130
}
139131

140132
void home_config_paths(char **global, char **xdg, char *file)

0 commit comments

Comments
 (0)