{"thread":{"id":"48423","subject":"[PATCH 5/5] lock_file: move static locks into functions","startedAt":"2018-05-06T14:11:31Z","lastAt":"2018-05-06T14:11:31Z","messageCount":1,"participants":["Martin Ågren"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"346767","messageId":"20180506141031.30204-6-martin.agren@gmail.com","threadId":"48423","inReplyTo":null,"subject":"[PATCH 5/5] lock_file: move static locks into functions","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-05-06T14:10:31Z","receivedAt":"2018-05-06T14:11:31Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Each of these `struct lock_file`s is used from within a single function.\nMove them into the respective functions to make the scope clearer. While\ndoing so, we can drop the staticness.\n\nAfter this commit, the remaing occurences of \"static struct lock_file\"\nare locks that are used from within different functions. That is, they\nneed to remain static. (Short of more intrusive changes like passing\naround pointers to non-static locks.)\n\nSigned-off-by: Martin Ågren <martin.agren@gmail.com>\n---\n t/helper/test-scrap-cache-tree.c | 4 ++--\n builtin/add.c                    | 3 +--\n builtin/mv.c                     | 2 +-\n builtin/read-tree.c              | 3 +--\n builtin/rm.c                     | 3 +--\n rerere.c                         | 3 +--\n 6 files changed, 7 insertions(+), 11 deletions(-)\n\ndiff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c\nindex d26d3e7c8b..393f1604ff 100644\n--- a/t/helper/test-scrap-cache-tree.c\n+++ b/t/helper/test-scrap-cache-tree.c\n@@ -4,10 +4,10 @@\n #include \"tree.h\"\n #include \"cache-tree.h\"\n \n-static struct lock_file index_lock;\n-\n int cmd__scrap_cache_tree(int ac, const char **av)\n {\n+\tstruct lock_file index_lock = LOCK_INIT;\n+\n \tsetup_git_directory();\n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n \tif (read_cache() < 0)\ndiff --git a/builtin/add.c b/builtin/add.c\nindex c9e2619a9a..8a155dd41e 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -265,8 +265,6 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-static struct lock_file lock_file;\n-\n static const char ignore_error[] =\n N_(\"The following paths are ignored by one of your .gitignore files:\\n\");\n \n@@ -393,6 +391,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \tint add_new_files;\n \tint require_pathspec;\n \tchar *seen = NULL;\n+\tstruct lock_file lock_file = LOCK_INIT;\n \n \tgit_config(add_config, NULL);\n \ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 6d141f7a53..b4692409e3 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -72,7 +72,6 @@ static const char *add_slash(const char *path)\n \treturn path;\n }\n \n-static struct lock_file lock_file;\n #define SUBMODULE_WITH_GITDIR ((const char *)1)\n \n static void prepare_move_submodule(const char *src, int first,\n@@ -131,6 +130,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \tenum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;\n \tstruct stat st;\n \tstruct string_list src_for_dst = STRING_LIST_INIT_NODUP;\n+\tstruct lock_file lock_file = LOCK_INIT;\n \n \tgit_config(git_default_config, NULL);\n \ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex bf87a2710b..ebc43eb805 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -107,8 +107,6 @@ static int git_read_tree_config(const char *var, const char *value, void *cb)\n \treturn git_default_config(var, value, cb);\n }\n \n-static struct lock_file lock_file;\n-\n int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n {\n \tint i, stage = 0;\n@@ -116,6 +114,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)\n \tstruct tree_desc t[MAX_UNPACK_TREES];\n \tstruct unpack_trees_options opts;\n \tint prefix_set = 0;\n+\tstruct lock_file lock_file = LOCK_INIT;\n \tconst struct option read_tree_options[] = {\n \t\t{ OPTION_CALLBACK, 0, \"index-output\", NULL, N_(\"file\"),\n \t\t  N_(\"write resulting index to <file>\"),\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 5b6fc7ee81..65b448ef8e 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -233,8 +233,6 @@ static int check_local_mod(struct object_id *head, int index_only)\n \treturn errs;\n }\n \n-static struct lock_file lock_file;\n-\n static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;\n static int ignore_unmatch = 0;\n \n@@ -251,6 +249,7 @@ static struct option builtin_rm_options[] = {\n \n int cmd_rm(int argc, const char **argv, const char *prefix)\n {\n+\tstruct lock_file lock_file = LOCK_INIT;\n \tint i;\n \tstruct pathspec pathspec;\n \tchar *seen;\ndiff --git a/rerere.c b/rerere.c\nindex 18cae2d11c..e0862e2778 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -703,10 +703,9 @@ static int merge(const struct rerere_id *id, const char *path)\n \treturn ret;\n }\n \n-static struct lock_file index_lock;\n-\n static void update_paths(struct string_list *update)\n {\n+\tstruct lock_file index_lock = LOCK_INIT;\n \tint i;\n \n \thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n-- \n2.17.0.411.g9fd64c8e46\n\n"}]}