@@ -42,9 +42,13 @@ The caller:
4242 of the final destination (e.g. `$GIT_DIR/index`) to
4343 `hold_lock_file_for_update` or `hold_lock_file_for_append`.
4444
45- * Writes new content for the destination file by writing to the file
46- descriptor returned by those functions (also available via
47- `lock->fd`).
45+ * Writes new content for the destination file by either:
46+
47+ * writing to the file descriptor returned by the `hold_lock_file_*`
48+ functions (also available via `lock->fd`).
49+
50+ * calling `fdopen_lock_file` to get a `FILE` pointer for the open
51+ file and writing to the file using stdio.
4852
4953When finished writing, the caller can:
5054
@@ -70,10 +74,10 @@ any uncommitted changes.
7074
7175If you need to close the file descriptor you obtained from a
7276`hold_lock_file_*` function yourself, do so by calling
73- `close_lock_file`. You should never call `close(2)` yourself!
74- Otherwise the `struct lock_file` structure would still think that the
75- file descriptor needs to be closed, and a commit or rollback would
76- result in duplicate calls to `close(2)`. Worse yet, if you ` close(2)`
77+ `close_lock_file`. You should never call `close(2)` or `fclose(3)`
78+ yourself! Otherwise the `struct lock_file` structure would still think
79+ that the file descriptor needs to be closed, and a commit or rollback
80+ would result in duplicate calls to `close(2)`. Worse yet, if you close
7781and then later open another file descriptor for a completely different
7882purpose, then a commit or rollback might close that unrelated file
7983descriptor.
@@ -143,6 +147,13 @@ hold_lock_file_for_append::
143147 the existing contents of the file (if any) to the lockfile and
144148 position its write pointer at the end of the file.
145149
150+ fdopen_lock_file::
151+
152+ Associate a stdio stream with the lockfile. Return NULL
153+ (*without* rolling back the lockfile) on error. The stream is
154+ closed automatically when `close_lock_file` is called or when
155+ the file is committed or rolled back.
156+
146157get_locked_file_path::
147158
148159 Return the path of the file that is locked by the specified
@@ -179,10 +190,11 @@ close_lock_file::
179190
180191 Take a pointer to the `struct lock_file` initialized with an
181192 earlier call to `hold_lock_file_for_update` or
182- `hold_lock_file_for_append`, and close the file descriptor.
183- Return 0 upon success. On failure to `close(2)`, return a
184- negative value and roll back the lock file. Usually
185- `commit_lock_file`, `commit_lock_file_to`, or
193+ `hold_lock_file_for_append`. Close the file descriptor (and
194+ the file pointer if it has been opened using
195+ `fdopen_lock_file`). Return 0 upon success. On failure to
196+ `close(2)`, return a negative value and roll back the lock
197+ file. Usually `commit_lock_file`, `commit_lock_file_to`, or
186198 `rollback_lock_file` should eventually be called if
187199 `close_lock_file` succeeds.
188200
0 commit comments