]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository.c: replace hold_locked_index() with repo_hold_locked_index()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 12 Jan 2019 02:13:24 +0000 (09:13 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2019 20:13:04 +0000 (12:13 -0800)
hold_locked_index() assumes the index path at $GIT_DIR/index. This is
not good for places that take an arbitrary index_state instead of
the_index, which is basically everywhere except builtin/.

Replace it with repo_hold_locked_index(). hold_locked_index() remains
as a wrapper around repo_hold_locked_index() to reduce changes in builtin/

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
apply.c
cache.h
merge-recursive.c
merge.c
read-cache.c
repository.c
repository.h
rerere.c
sequencer.c
wt-status.c

diff --git a/apply.c b/apply.c
index 01793d612620246b14fa57f6ce3ed6c33df65d0f..08cde3c4bf1ea6e6a5d855ea37de34a23130d638 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -4712,7 +4712,8 @@ static int apply_patch(struct apply_state *state,
                                                  state->index_file,
                                                  LOCK_DIE_ON_ERROR);
                else
-                       hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
+                       repo_hold_locked_index(state->repo, &state->lock_file,
+                                              LOCK_DIE_ON_ERROR);
        }
 
        if (state->check_index && read_apply_cache(state) < 0) {
diff --git a/cache.h b/cache.h
index ca36b44ee0b5851f837616c322a201ac420a90d2..634c9ce3254565d9f3f05f803604b4c6adddc501 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);
 #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
 #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
 #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
+#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
 #endif
 
 #define TYPE_BITS 3
@@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach
  */
 extern void update_index_if_able(struct index_state *, struct lock_file *);
 
-extern int hold_locked_index(struct lock_file *, int);
 extern void set_alternate_index_output(const char *);
 
 extern int verify_index_checksum;
index ecf8db0b716ff20305425937c26ab6b8e69d33ed..8dba939d8f8393151a4ba2c1865c59f5c7a101fd 100644 (file)
@@ -3643,7 +3643,7 @@ int merge_recursive_generic(struct merge_options *o,
                }
        }
 
-       hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
+       repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
        clean = merge_recursive(o, head_commit, next_commit, ca,
                                result);
        if (clean < 0) {
diff --git a/merge.c b/merge.c
index 91008f760223e4f6c65a5d344bb6403dd5885d28..dbbc9d9f802fef2781b9b60b798700f49229f84f 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,
 
        refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
 
-       if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
        memset(&trees, 0, sizeof(trees));
index 48c1797a4a4225ae3e0d13da2a761a2cc2f8131a..1030e1105159f09f8a548176ed585963fb95eb47 100644 (file)
@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,
        return 0;
 }
 
-int hold_locked_index(struct lock_file *lk, int lock_flags)
-{
-       return hold_lock_file_for_update(lk, get_index_file(), lock_flags);
-}
-
 int read_index(struct index_state *istate)
 {
        return read_index_from(istate, get_index_file(), get_git_dir());
index 7b02e1dffac077d0c21ecaef915f4ea33abc57bc..9411c4baee2f49e7ce561bc3e142e4bffd521733 100644 (file)
@@ -3,6 +3,7 @@
 #include "object-store.h"
 #include "config.h"
 #include "object.h"
+#include "lockfile.h"
 #include "submodule-config.h"
 
 /* The main repository */
@@ -263,3 +264,12 @@ int repo_read_index(struct repository *repo)
 
        return read_index_from(repo->index, repo->index_file, repo->gitdir);
 }
+
+int repo_hold_locked_index(struct repository *repo,
+                          struct lock_file *lf,
+                          int flags)
+{
+       if (!repo->index_file)
+               BUG("the repo hasn't been setup");
+       return hold_lock_file_for_update(lf, repo->index_file, flags);
+}
index 9f16c42c1ed04af3bf2e7767c4fd6c05b28ccf9c..968330218fd81a2f424f12142dfa40af790bdaa4 100644 (file)
@@ -6,6 +6,7 @@
 struct config_set;
 struct git_hash_algo;
 struct index_state;
+struct lock_file;
 struct raw_object_store;
 struct submodule_cache;
 
@@ -130,5 +131,8 @@ void repo_clear(struct repository *repo);
  * populated then the number of entries will simply be returned.
  */
 int repo_read_index(struct repository *repo);
+int repo_hold_locked_index(struct repository *repo,
+                          struct lock_file *lf,
+                          int flags);
 
 #endif /* REPOSITORY_H */
index 13624038e66c2084c478711599ed9f005cf2e53d..fb0fdb23927b544c7221cd5c1b78e5314310066d 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)
        struct lock_file index_lock = LOCK_INIT;
        int i;
 
-       hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
+       repo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR);
 
        for (i = 0; i < update->nr; i++) {
                struct string_list_item *item = &update->items[i];
index 1a92a5d678e2a846c3fb36d1ed169ac439ba25f5..668c232b05d5bfd9ee2369dbbf68eb444eb5824c 100644 (file)
@@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r,
        char **xopt;
        struct lock_file index_lock = LOCK_INIT;
 
-       if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
        read_index(r->index);
@@ -1992,8 +1992,8 @@ static int read_and_refresh_cache(struct repository *r,
                                  struct replay_opts *opts)
 {
        struct lock_file index_lock = LOCK_INIT;
-       int index_fd = hold_locked_index(&index_lock, 0);
-       if (read_index(r->index) < 0) {
+       int index_fd = repo_hold_locked_index(r, &index_lock, 0);
+       if (repo_read_index(r) < 0) {
                rollback_lock_file(&index_lock);
                return error(_("git %s: failed to read the index"),
                        _(action_name(opts)));
@@ -2978,7 +2978,7 @@ static int do_reset(struct repository *r,
        struct unpack_trees_options unpack_tree_opts;
        int ret = 0;
 
-       if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)
+       if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)
                return -1;
 
        if (len == 10 && !strncmp("[new root]", name, len)) {
@@ -3096,7 +3096,7 @@ static int do_merge(struct repository *r,
        static struct lock_file lock;
        const char *p;
 
-       if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
+       if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {
                ret = -1;
                goto leave_merge;
        }
index 0fe3bcd4cd057b72a61cfc6d46e892ac890f0634..becf78b04f50608a0f0dadc4a10b8b6300ddbf1d 100644 (file)
@@ -2375,7 +2375,7 @@ int require_clean_work_tree(struct repository *r,
        struct lock_file lock_file = LOCK_INIT;
        int err = 0, fd;
 
-       fd = hold_locked_index(&lock_file, 0);
+       fd = repo_hold_locked_index(r, &lock_file, 0);
        refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
        if (0 <= fd)
                update_index_if_able(r->index, &lock_file);