Skip to content

Commit 2f76ebc

Browse files
committed
Merge branch 'ma/lockfile-cleanup'
Code clean-up to adjust to a more recent lockfile API convention that allows lockfile instances kept on the stack. * ma/lockfile-cleanup: lock_file: move static locks into functions lock_file: make function-local locks non-static refs.c: do not die if locking fails in `delete_pseudoref()` refs.c: do not die if locking fails in `write_pseudoref()` t/helper/test-write-cache: clean up lock-handling
2 parents 0e7af5f + 0fa5a2e commit 2f76ebc

18 files changed

+32
-38
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
40584058
{
40594059
struct patch *patch;
40604060
struct index_state result = { NULL };
4061-
static struct lock_file lock;
4061+
struct lock_file lock = LOCK_INIT;
40624062
int res;
40634063

40644064
/* Once we start supporting the reverse patch, it may be

builtin/add.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
265265
return 0;
266266
}
267267

268-
static struct lock_file lock_file;
269-
270268
static const char ignore_error[] =
271269
N_("The following paths are ignored by one of your .gitignore files:\n");
272270

@@ -393,6 +391,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
393391
int add_new_files;
394392
int require_pathspec;
395393
char *seen = NULL;
394+
struct lock_file lock_file = LOCK_INIT;
396395

397396
git_config(add_config, NULL);
398397

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
612612
suffix = broken;
613613
}
614614
} else if (dirty) {
615-
static struct lock_file index_lock;
615+
struct lock_file index_lock = LOCK_INIT;
616616
struct rev_info revs;
617617
struct argv_array args = ARGV_ARRAY_INIT;
618618
int fd, result;

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
610610
continue;
611611

612612
if (!indices_loaded) {
613-
static struct lock_file lock;
613+
struct lock_file lock = LOCK_INIT;
614614
strbuf_reset(&buf);
615615
strbuf_addf(&buf, "%s/wtindex", tmpdir);
616616
if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static int need_to_gc(void)
373373
/* return NULL on success, else hostname running the gc */
374374
static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
375375
{
376-
static struct lock_file lock;
376+
struct lock_file lock = LOCK_INIT;
377377
char my_host[HOST_NAME_MAX + 1];
378378
struct strbuf sb = STRBUF_INIT;
379379
struct stat st;

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
647647
struct commit_list *remoteheads,
648648
struct commit *head)
649649
{
650-
static struct lock_file lock;
650+
struct lock_file lock = LOCK_INIT;
651651
const char *head_arg = "HEAD";
652652

653653
hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
@@ -805,7 +805,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
805805
{
806806
struct object_id result_tree, result_commit;
807807
struct commit_list *parents, **pptr = &parents;
808-
static struct lock_file lock;
808+
struct lock_file lock = LOCK_INIT;
809809

810810
hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
811811
refresh_cache(REFRESH_QUIET);

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static const char *add_slash(const char *path)
7272
return path;
7373
}
7474

75-
static struct lock_file lock_file;
7675
#define SUBMODULE_WITH_GITDIR ((const char *)1)
7776

7877
static void prepare_move_submodule(const char *src, int first,
@@ -131,6 +130,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
131130
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
132131
struct stat st;
133132
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
133+
struct lock_file lock_file = LOCK_INIT;
134134

135135
git_config(git_default_config, NULL);
136136

builtin/read-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ static int git_read_tree_config(const char *var, const char *value, void *cb)
107107
return git_default_config(var, value, cb);
108108
}
109109

110-
static struct lock_file lock_file;
111-
112110
int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
113111
{
114112
int i, stage = 0;
115113
struct object_id oid;
116114
struct tree_desc t[MAX_UNPACK_TREES];
117115
struct unpack_trees_options opts;
118116
int prefix_set = 0;
117+
struct lock_file lock_file = LOCK_INIT;
119118
const struct option read_tree_options[] = {
120119
{ OPTION_CALLBACK, 0, "index-output", NULL, N_("file"),
121120
N_("write resulting index to <file>"),

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ static void refuse_unconfigured_deny_delete_current(void)
876876
static int command_singleton_iterator(void *cb_data, struct object_id *oid);
877877
static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
878878
{
879-
static struct lock_file shallow_lock;
879+
struct lock_file shallow_lock = LOCK_INIT;
880880
struct oid_array extra = OID_ARRAY_INIT;
881881
struct check_connected_options opt = CHECK_CONNECTED_INIT;
882882
uint32_t mask = 1 << (cmd->index % 32);

builtin/rm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ static int check_local_mod(struct object_id *head, int index_only)
233233
return errs;
234234
}
235235

236-
static struct lock_file lock_file;
237-
238236
static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
239237
static int ignore_unmatch = 0;
240238

@@ -251,6 +249,7 @@ static struct option builtin_rm_options[] = {
251249

252250
int cmd_rm(int argc, const char **argv, const char *prefix)
253251
{
252+
struct lock_file lock_file = LOCK_INIT;
254253
int i;
255254
struct pathspec pathspec;
256255
char *seen;

0 commit comments

Comments
 (0)