lockfile.h: extract new header file for the functions in lockfile.c
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:42 +0000 (12:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2014 20:56:14 +0000 (13:56 -0700)
Move the interface declaration for the functions in lockfile.c from
cache.h to a new file, lockfile.h. Add #includes where necessary (and
remove some redundant includes of cache.h by files that already
include builtin.h).

Move the documentation of the lock_file state diagram from lockfile.c
to the new header file.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
35 files changed:
builtin/add.c
builtin/apply.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/describe.c
builtin/diff.c
builtin/gc.c
builtin/merge.c
builtin/mv.c
builtin/read-tree.c
builtin/receive-pack.c
builtin/reflog.c
builtin/reset.c
builtin/rm.c
builtin/update-index.c
bundle.c
cache-tree.c
cache.h
config.c
credential-store.c
fast-import.c
fetch-pack.c
lockfile.c
lockfile.h [new file with mode: 0644]
merge-recursive.c
merge.c
read-cache.c
refs.c
rerere.c
sequencer.c
sha1_file.c
shallow.c
test-scrap-cache-tree.c
index 352b85e8db19e1b4fa05ca37804f0c625e582912..ae6d3e262bcbb3dc57c0ddf146791380259b31be 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "exec_cmd.h"
index 8714a887203acd84ad08f3e0917fc72b2c7a3138..69efb0e4df1514cf20830d180165fd58dc633fd7 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "quote.h"
 #include "blob.h"
index 05edd9e1df52e63a1644cddc0fb0e6a0d764d90b..383dccf93ef4eceb873eee4cd63e6781854b295c 100644 (file)
@@ -5,7 +5,7 @@
  *
  */
 #include "builtin.h"
-#include "cache.h"
+#include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "parse-options.h"
index 8afdf2b5c4bfbd53e7315afe9d8ae3d88f93dd57..570bb09c4f176ff21d593361261ec008c3a89739 100644 (file)
@@ -1,5 +1,5 @@
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "commit.h"
index 3927edfb6ede269929dc704cbb928a7516a8a0a7..d3bf9532d60fd52dfb440fc991e91544e8353fbe 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
 #include "refs.h"
index f55e80986ba1787145690a8831baa632e6dec2fc..c2300185ec99ee26fdebba0197f24c23001552c9 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
 #include "dir.h"
index ee6a3b998f2c22b1d131a180e77079117e598136..9103193b4f65dc9e224051fb1e19eda6d9c7ae6a 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
index 0f247d24008a4dc7ba5958e716c13f7582a820f1..4326fa56bfa2021c6518c225eaa3f89b8b852e11 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "color.h"
 #include "commit.h"
 #include "blob.h"
index ced1456e1e3b71af05e382fcd505cc269391bb88..005adbebea80a83a8d0dbb1de744cb50bf689de6 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #include "builtin.h"
-#include "cache.h"
+#include "lockfile.h"
 #include "parse-options.h"
 #include "run-command.h"
 #include "sigchain.h"
index be07f27487bf839444f8e2a6c1af117bad42a0e5..4513fadc5fc3c631591d1a9b65ec939ada5d2de3 100644 (file)
@@ -9,6 +9,7 @@
 #include "cache.h"
 #include "parse-options.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "run-command.h"
 #include "diff.h"
 #include "refs.h"
index 8883baa903e92093cabcc3dbaac7ccec3eecd64a..563d05ba1af21c9ae73edceba060161969434c76 100644 (file)
@@ -3,8 +3,8 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
 #include "string-list.h"
index e7e1c33a7fb1f1eb7828f4d632fb492f128f66fe..43b47f72f1deffa8fa5e3fa5ac403d4c4a819355 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "lockfile.h"
 #include "object.h"
 #include "tree.h"
 #include "tree-walk.h"
index daf0600ca30eb3969e0583cc1096e6f33291d4aa..10fa25d7b5632abd245bfbeaee56363552498c6c 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
 #include "pkt-line.h"
index 7c78b15c149bb61d2e572fdfeda1c65bf08f8806..b6388f75b0cffcce03b9eee03be966ce67806310 100644 (file)
@@ -1,5 +1,5 @@
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
index 855d478e3b9d2a815ecdcfbf39c261f98ad0994b..4c08ddc1cacc29f2098bb81b434d76f315346dd4 100644 (file)
@@ -8,6 +8,7 @@
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
 #include "builtin.h"
+#include "lockfile.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
index 2b61d3bd41164286fcca3e5fe3c807387d946ff2..d8a9c86dd135e62583f4aeeb3885012da385960a 100644 (file)
@@ -3,8 +3,8 @@
  *
  * Copyright (C) Linus Torvalds 2006
  */
-#include "cache.h"
 #include "builtin.h"
+#include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
index 6c9598891da80994bce3fd20712cc960d1df925b..b0e3dc91055ec7e7579fb5f1964879a99fd71606 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
index b2b89fe8628eb29b613754ee8e837fd56de185da..891a3cacda457fcb83b511ad0f7d07e7feb64cf4 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "bundle.h"
 #include "object.h"
 #include "commit.h"
index 75a54fdc7232e5693b042aa06540d51a99f01551..215202c42d2243ebf704ac083937d65aa8497929 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "tree.h"
 #include "tree-walk.h"
 #include "cache-tree.h"
diff --git a/cache.h b/cache.h
index d19e57ff64d2b4ef1601f2486877c4f4043c9fdd..b71ceb2d8de07f77a6385025c5d154acf529ada5 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -570,36 +570,11 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 #define REFRESH_IN_PORCELAIN   0x0020  /* user friendly output, not "needs update" */
 extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
 
-/* String appended to a filename to derive the lockfile name: */
-#define LOCK_SUFFIX ".lock"
-#define LOCK_SUFFIX_LEN 5
-
-struct lock_file {
-       struct lock_file *volatile next;
-       volatile sig_atomic_t active;
-       volatile int fd;
-       volatile pid_t owner;
-       char on_list;
-       struct strbuf filename;
-};
-#define LOCK_DIE_ON_ERROR 1
-#define LOCK_NO_DEREF 2
-extern int unable_to_lock_error(const char *path, int err);
-extern void unable_to_lock_message(const char *path, int err,
-                                  struct strbuf *buf);
-extern NORETURN void unable_to_lock_die(const char *path, int err);
-extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
-extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
-extern char *get_locked_file_path(struct lock_file *);
-extern int commit_lock_file_to(struct lock_file *, const char *path);
-extern int commit_lock_file(struct lock_file *);
-extern int reopen_lock_file(struct lock_file *);
 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 close_lock_file(struct lock_file *);
-extern void rollback_lock_file(struct lock_file *);
+
 extern int delete_ref(const char *, const unsigned char *sha1, int delopt);
 
 /* Environment bits from configuration mechanism */
index 21107797d31c8a92c923dc91bb9cf02db4ba75c4..c31d4d2486c7f11ae31c841ed95157426dbf11c0 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
 #include "quote.h"
index f9146e576f82cd774f697420e2bb456f56ad65dd..d435514cbe29aa01d9cebadb947a6c6c8a1e2527 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
 #include "parse-options.h"
index 783c6840b5962d82ccce05f20dd921f67ab6006a..deadc33f942276af95b2c71bdf3f403a1751de77 100644 (file)
@@ -153,6 +153,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "lockfile.h"
 #include "object.h"
 #include "blob.h"
 #include "tree.h"
index 7487aa730630e8b45874e3487db8e71c05e1968c..655ee642564e3ada5b782dd6fa2d2c799f340978 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "commit.h"
index 63f4e94bce4f84bcd10094a61033c2faa9975422..d27e61cafcfd2a8277e67edddaf41c29065babee 100644 (file)
@@ -2,59 +2,9 @@
  * Copyright (c) 2005, Junio C Hamano
  */
 #include "cache.h"
+#include "lockfile.h"
 #include "sigchain.h"
 
-/*
- * File write-locks as used by Git.
- *
- * For an overview of how to use the lockfile API, please see
- *
- *     Documentation/technical/api-lockfile.txt
- *
- * This module keeps track of all locked files in lock_file_list for
- * use at cleanup. This list and the lock_file objects that comprise
- * it must be kept in self-consistent states at all time, because the
- * program can be interrupted any time by a signal, in which case the
- * signal handler will walk through the list attempting to clean up
- * any open lock files.
- *
- * A lockfile is owned by the process that created it. The lock_file
- * object has an "owner" field that records its owner. This field is
- * used to prevent a forked process from closing a lockfile created by
- * its parent.
- *
- * The possible states of a lock_file object are as follows:
- *
- * - Uninitialized.  In this state the object's on_list field must be
- *   zero but the rest of its contents need not be initialized.  As
- *   soon as the object is used in any way, it is irrevocably
- *   registered in the lock_file_list, and on_list is set.
- *
- * - Locked, lockfile open (after hold_lock_file_for_update(),
- *   hold_lock_file_for_append(), or reopen_lock_file()). In this
- *   state:
- *   - the lockfile exists
- *   - active is set
- *   - filename holds the filename of the lockfile
- *   - fd holds a file descriptor open for writing to the lockfile
- *   - owner holds the PID of the process that locked the file
- *
- * - Locked, lockfile closed (after successful close_lock_file()).
- *   Same as the previous state, except that the lockfile is closed
- *   and fd is -1.
- *
- * - Unlocked (after commit_lock_file(), commit_lock_file_to(),
- *   rollback_lock_file(), a failed attempt to lock, or a failed
- *   close_lock_file()).  In this state:
- *   - active is unset
- *   - filename is empty (usually, though there are transitory
- *     states in which this condition doesn't hold). Client code should
- *     *not* rely on the filename being empty in this state.
- *   - fd is -1
- *   - the object is left registered in the lock_file_list, and
- *     on_list is set.
- */
-
 static struct lock_file *volatile lock_file_list;
 
 static void remove_lock_files(void)
diff --git a/lockfile.h b/lockfile.h
new file mode 100644 (file)
index 0000000..9059e89
--- /dev/null
@@ -0,0 +1,84 @@
+#ifndef LOCKFILE_H
+#define LOCKFILE_H
+
+/*
+ * File write-locks as used by Git.
+ *
+ * For an overview of how to use the lockfile API, please see
+ *
+ *     Documentation/technical/api-lockfile.txt
+ *
+ * This module keeps track of all locked files in lock_file_list for
+ * use at cleanup. This list and the lock_file objects that comprise
+ * it must be kept in self-consistent states at all time, because the
+ * program can be interrupted any time by a signal, in which case the
+ * signal handler will walk through the list attempting to clean up
+ * any open lock files.
+ *
+ * A lockfile is owned by the process that created it. The lock_file
+ * object has an "owner" field that records its owner. This field is
+ * used to prevent a forked process from closing a lockfile created by
+ * its parent.
+ *
+ * The possible states of a lock_file object are as follows:
+ *
+ * - Uninitialized.  In this state the object's on_list field must be
+ *   zero but the rest of its contents need not be initialized.  As
+ *   soon as the object is used in any way, it is irrevocably
+ *   registered in the lock_file_list, and on_list is set.
+ *
+ * - Locked, lockfile open (after hold_lock_file_for_update(),
+ *   hold_lock_file_for_append(), or reopen_lock_file()). In this
+ *   state:
+ *   - the lockfile exists
+ *   - active is set
+ *   - filename holds the filename of the lockfile
+ *   - fd holds a file descriptor open for writing to the lockfile
+ *   - owner holds the PID of the process that locked the file
+ *
+ * - Locked, lockfile closed (after successful close_lock_file()).
+ *   Same as the previous state, except that the lockfile is closed
+ *   and fd is -1.
+ *
+ * - Unlocked (after commit_lock_file(), commit_lock_file_to(),
+ *   rollback_lock_file(), a failed attempt to lock, or a failed
+ *   close_lock_file()).  In this state:
+ *   - active is unset
+ *   - filename is empty (usually, though there are transitory
+ *     states in which this condition doesn't hold). Client code should
+ *     *not* rely on the filename being empty in this state.
+ *   - fd is -1
+ *   - the object is left registered in the lock_file_list, and
+ *     on_list is set.
+ */
+
+struct lock_file {
+       struct lock_file *volatile next;
+       volatile sig_atomic_t active;
+       volatile int fd;
+       volatile pid_t owner;
+       char on_list;
+       struct strbuf filename;
+};
+
+/* String appended to a filename to derive the lockfile name: */
+#define LOCK_SUFFIX ".lock"
+#define LOCK_SUFFIX_LEN 5
+
+#define LOCK_DIE_ON_ERROR 1
+#define LOCK_NO_DEREF 2
+
+extern int unable_to_lock_error(const char *path, int err);
+extern void unable_to_lock_message(const char *path, int err,
+                                  struct strbuf *buf);
+extern NORETURN void unable_to_lock_die(const char *path, int err);
+extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
+extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
+extern char *get_locked_file_path(struct lock_file *);
+extern int commit_lock_file_to(struct lock_file *, const char *path);
+extern int commit_lock_file(struct lock_file *);
+extern int reopen_lock_file(struct lock_file *);
+extern int close_lock_file(struct lock_file *);
+extern void rollback_lock_file(struct lock_file *);
+
+#endif /* LOCKFILE_H */
index 8ad4be897d88c691d43c30afb698a1ae952b8596..4b0884b7bbdf177d6cfa2d07d3888cd212ec8a62 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "advice.h"
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "commit.h"
 #include "blob.h"
diff --git a/merge.c b/merge.c
index 74ced7f70b5beec045c134b5719c926fc791f1e2..fcff632bd63a113ca78b0bd86da1e6af8bc6f7dc 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "run-command.h"
 #include "resolve-undo.h"
index 9f137e7f27fa8db36c7bb3cfb0848b4595331dea..8f3e9eb31498d708acf63bf3fc6de3d34562d42e 100644 (file)
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "lockfile.h"
 #include "cache-tree.h"
 #include "refs.h"
 #include "dir.h"
diff --git a/refs.c b/refs.c
index e40c47edce9cf3b2b93b801b7a64ebe7d170441d..1d73f1daf514ae02fb7dddb2120252b7dbd82600 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "refs.h"
 #include "object.h"
 #include "tag.h"
index 20b18add42d2551a227eaac8125fe806006d2856..1b0555f1a5a0233e931b13a088c052a56aef3977 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
 #include "xdiff-interface.h"
index 5e8a207474bc6971a0de4f9ff6160a5681ac7b6d..1b9a35e5875683c9bd6ae7dba8e849201fdc0a42 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
 #include "object.h"
index c08c0cbea805b38104504b9b51266949affb6991..46ff273e272b8253c3349a64a47083ca7da84fa3 100644 (file)
@@ -8,6 +8,7 @@
  */
 #include "cache.h"
 #include "string-list.h"
+#include "lockfile.h"
 #include "delta.h"
 #include "pack.h"
 #include "blob.h"
index 4919baf7727bd25f35d76de5f40e27f6725d6881..bd7569e815273b93b5862391c64694e141cc668d 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
 #include "pkt-line.h"
index 9ebcbca9d25150e9bfca77a73ca45d2a06423f49..6efee31a4867b4ff8493161376e5a9cfdd48fe44 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "lockfile.h"
 #include "tree.h"
 #include "cache-tree.h"