Skip to content

Commit 5e7f01c

Browse files
peffgitster
authored andcommitted
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>
1 parent 076aa2c commit 5e7f01c

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

lockfile.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
*
3838
* The caller:
3939
*
40-
* * Allocates a `struct lock_file` either as a static variable or on
41-
* the heap, initialized to zeros. Once you use the structure to
42-
* call the `hold_lock_file_for_*()` family of functions, it belongs
43-
* to the lockfile subsystem and its storage must remain valid
44-
* throughout the life of the program (i.e. you cannot use an
45-
* on-stack variable to hold this structure).
40+
* * Allocates a `struct lock_file` with whatever storage duration you
41+
* desire. The struct does not have to be initialized before being
42+
* used, but it is good practice to do so using by setting it to
43+
* all-zeros (or using the LOCK_INIT macro). This puts the object in a
44+
* consistent state that allows you to call rollback_lock_file() even
45+
* if the lock was never taken (in which case it is a noop).
4646
*
4747
* * Attempts to create a lockfile by calling `hold_lock_file_for_update()`.
4848
*
@@ -73,10 +73,8 @@
7373
* `commit_lock_file()`, `commit_lock_file_to()`,
7474
* `rollback_lock_file()`, or `reopen_lock_file()`.
7575
*
76-
* Even after the lockfile is committed or rolled back, the
77-
* `lock_file` object must not be freed or altered by the caller.
78-
* However, it may be reused; just pass it to another call of
79-
* `hold_lock_file_for_update()`.
76+
* After the lockfile is committed or rolled back, the `lock_file`
77+
* object can be discarded or reused.
8078
*
8179
* If the program exits before `commit_lock_file()`,
8280
* `commit_lock_file_to()`, or `rollback_lock_file()` is called, the
@@ -114,6 +112,8 @@ struct lock_file {
114112
struct tempfile *tempfile;
115113
};
116114

115+
#define LOCK_INIT { NULL }
116+
117117
/* String appended to a filename to derive the lockfile name: */
118118
#define LOCK_SUFFIX ".lock"
119119
#define LOCK_SUFFIX_LEN 5

0 commit comments

Comments
 (0)