lockfile: update lifetime requirements in documentation

Now that the tempfile system we rely on has loosened the
lifetime requirements for storage, we can adjust our
documentation to match.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2017-09-05 08:15:12 -04:00 committed by Junio C Hamano
parent 076aa2cbda
commit 5e7f01c93e

View File

@ -37,12 +37,12 @@
* *
* The caller: * The caller:
* *
* * Allocates a `struct lock_file` either as a static variable or on * * Allocates a `struct lock_file` with whatever storage duration you
* the heap, initialized to zeros. Once you use the structure to * desire. The struct does not have to be initialized before being
* call the `hold_lock_file_for_*()` family of functions, it belongs * used, but it is good practice to do so using by setting it to
* to the lockfile subsystem and its storage must remain valid * all-zeros (or using the LOCK_INIT macro). This puts the object in a
* throughout the life of the program (i.e. you cannot use an * consistent state that allows you to call rollback_lock_file() even
* on-stack variable to hold this structure). * if the lock was never taken (in which case it is a noop).
* *
* * Attempts to create a lockfile by calling `hold_lock_file_for_update()`. * * Attempts to create a lockfile by calling `hold_lock_file_for_update()`.
* *
@ -73,10 +73,8 @@
* `commit_lock_file()`, `commit_lock_file_to()`, * `commit_lock_file()`, `commit_lock_file_to()`,
* `rollback_lock_file()`, or `reopen_lock_file()`. * `rollback_lock_file()`, or `reopen_lock_file()`.
* *
* Even after the lockfile is committed or rolled back, the * After the lockfile is committed or rolled back, the `lock_file`
* `lock_file` object must not be freed or altered by the caller. * object can be discarded or reused.
* However, it may be reused; just pass it to another call of
* `hold_lock_file_for_update()`.
* *
* If the program exits before `commit_lock_file()`, * If the program exits before `commit_lock_file()`,
* `commit_lock_file_to()`, or `rollback_lock_file()` is called, the * `commit_lock_file_to()`, or `rollback_lock_file()` is called, the
@ -114,6 +112,8 @@ struct lock_file {
struct tempfile *tempfile; struct tempfile *tempfile;
}; };
#define LOCK_INIT { NULL }
/* String appended to a filename to derive the lockfile name: */ /* String appended to a filename to derive the lockfile name: */
#define LOCK_SUFFIX ".lock" #define LOCK_SUFFIX ".lock"
#define LOCK_SUFFIX_LEN 5 #define LOCK_SUFFIX_LEN 5