Skip to content

Commit 320fa57

Browse files
peffgitster
authored andcommitted
tempfile: update comment describing state transitions
Back when 1a9d15d (tempfile: a new module for handling temporary files, 2015-08-10) added this comment, tempfile structs were held in memory for the life of a process, and there were various guarantees about which fields were valid in which states. Since 422a21c (tempfile: remove deactivated list entries, 2017-09-05) and 076aa2c (tempfile: auto-allocate tempfiles on heap, 2017-09-05), the flow is quite different: objects come and go from the list, and inactive ones are deallocated. And the previous commit removed the "active" flag from the struct entirely. Let's bring the comment up to date with the current code. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77a42b3 commit 320fa57

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

tempfile.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
*
1515
* The possible states of a `tempfile` object are as follows:
1616
*
17-
* - Uninitialized. In this state the object's `on_list` field must be
18-
* zero but the rest of its contents need not be initialized. As
19-
* soon as the object is used in any way, it is irrevocably
20-
* registered in `tempfile_list`, and `on_list` is set.
17+
* - Inactive/unallocated. The only way to get a tempfile is via a creation
18+
* function like create_tempfile(). Once allocated, the tempfile is on the
19+
* global tempfile_list and considered active.
2120
*
2221
* - Active, file open (after `create_tempfile()` or
2322
* `reopen_tempfile()`). In this state:
2423
*
2524
* - the temporary file exists
26-
* - `active` is set
2725
* - `filename` holds the filename of the temporary file
2826
* - `fd` holds a file descriptor open for writing to it
2927
* - `fp` holds a pointer to an open `FILE` object if and only if
@@ -35,14 +33,8 @@
3533
* `fd` is -1, and `fp` is `NULL`.
3634
*
3735
* - Inactive (after `delete_tempfile()`, `rename_tempfile()`, or a
38-
* failed attempt to create a temporary file). In this state:
39-
*
40-
* - `active` is unset
41-
* - `filename` is empty (usually, though there are transitory
42-
* states in which this condition doesn't hold). Client code should
43-
* *not* rely on the filename being empty in this state.
44-
* - `fd` is -1 and `fp` is `NULL`
45-
* - the object is removed from `tempfile_list` (but could be used again)
36+
* failed attempt to create a temporary file). The struct is removed from
37+
* the global tempfile_list and deallocated.
4638
*
4739
* A temporary file is owned by the process that created it. The
4840
* `tempfile` has an `owner` field that records the owner's PID. This

0 commit comments

Comments
 (0)