mirror of
https://github.com/git/git
synced 2024-10-01 06:05:20 +00:00
mv: replace src_dir with a strvec
We manually manage the src_dir array with ALLOC_GROW. Using a strvec is
a little more ergonomic, and makes the memory ownership more clear. It
does mean that we copy the strings (which were otherwise just pointers
into the "sources" strvec), but using the same rationale as 9fcd9e4e72
(builtin/mv duplicate string list memory, 2024-05-27), it's just not
enough to be worth worrying about here.
As a bonus, this gets rid of some "int"s used for allocation management
(though in practice these were limited to command-line sizes and thus
not overflowable).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d58a687705
commit
64f8502b40
10
builtin/mv.c
10
builtin/mv.c
|
@ -197,8 +197,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||||
struct strvec submodule_gitfiles_to_free = STRVEC_INIT;
|
struct strvec submodule_gitfiles_to_free = STRVEC_INIT;
|
||||||
const char **submodule_gitfiles;
|
const char **submodule_gitfiles;
|
||||||
char *dst_w_slash = NULL;
|
char *dst_w_slash = NULL;
|
||||||
const char **src_dir = NULL;
|
struct strvec src_dir = STRVEC_INIT;
|
||||||
int src_dir_nr = 0, src_dir_alloc = 0;
|
|
||||||
enum update_mode *modes, dst_mode = 0;
|
enum update_mode *modes, dst_mode = 0;
|
||||||
struct stat st, dest_st;
|
struct stat st, dest_st;
|
||||||
struct string_list src_for_dst = STRING_LIST_INIT_DUP;
|
struct string_list src_for_dst = STRING_LIST_INIT_DUP;
|
||||||
|
@ -344,8 +343,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||||
/* last - first >= 1 */
|
/* last - first >= 1 */
|
||||||
modes[i] |= WORKING_DIRECTORY;
|
modes[i] |= WORKING_DIRECTORY;
|
||||||
|
|
||||||
ALLOC_GROW(src_dir, src_dir_nr + 1, src_dir_alloc);
|
strvec_push(&src_dir, src);
|
||||||
src_dir[src_dir_nr++] = src;
|
|
||||||
|
|
||||||
n = argc + last - first;
|
n = argc + last - first;
|
||||||
REALLOC_ARRAY(modes, n);
|
REALLOC_ARRAY(modes, n);
|
||||||
|
@ -559,7 +557,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_empty_src_dirs(src_dir, src_dir_nr);
|
remove_empty_src_dirs(src_dir.v, src_dir.nr);
|
||||||
|
|
||||||
if (dirty_paths.nr)
|
if (dirty_paths.nr)
|
||||||
advise_on_moving_dirty_path(&dirty_paths);
|
advise_on_moving_dirty_path(&dirty_paths);
|
||||||
|
@ -574,7 +572,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(src_dir);
|
strvec_clear(&src_dir);
|
||||||
free(dst_w_slash);
|
free(dst_w_slash);
|
||||||
string_list_clear(&src_for_dst, 0);
|
string_list_clear(&src_for_dst, 0);
|
||||||
string_list_clear(&dirty_paths, 0);
|
string_list_clear(&dirty_paths, 0);
|
||||||
|
|
Loading…
Reference in a new issue