Skip to content

Commit 1302ed6

Browse files
pks-tgitster
authored andcommitted
reftable/stack: reorder swapping in the reloaded stack contents
The code flow of how we swap in the reloaded stack contents is somewhat convoluted because we switch back and forth between swapping in different parts of the stack. Reorder the code to simplify it. We now first close and unlink the old tables which do not get reused before we update the stack to point to the new stack. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89eada4 commit 1302ed6

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

reftable/stack.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,30 +273,34 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
273273
if (err < 0)
274274
goto done;
275275

276-
st->readers_len = new_readers_len;
277-
if (st->merged)
278-
reftable_merged_table_free(st->merged);
279-
if (st->readers) {
280-
reftable_free(st->readers);
281-
}
282-
st->readers = new_readers;
283-
new_readers = NULL;
284-
new_readers_len = 0;
285-
286-
new_merged->suppress_deletions = 1;
287-
st->merged = new_merged;
276+
/*
277+
* Close the old, non-reused readers and proactively try to unlink
278+
* them. This is done for systems like Windows, where the underlying
279+
* file of such an open reader wouldn't have been possible to be
280+
* unlinked by the compacting process.
281+
*/
288282
for (i = 0; i < cur_len; i++) {
289283
if (cur[i]) {
290284
const char *name = reader_name(cur[i]);
291285
stack_filename(&table_path, st, name);
292-
293286
reftable_reader_decref(cur[i]);
294-
295-
/* On Windows, can only unlink after closing. */
296287
unlink(table_path.buf);
297288
}
298289
}
299290

291+
/* Update the stack to point to the new tables. */
292+
if (st->merged)
293+
reftable_merged_table_free(st->merged);
294+
new_merged->suppress_deletions = 1;
295+
st->merged = new_merged;
296+
297+
if (st->readers)
298+
reftable_free(st->readers);
299+
st->readers = new_readers;
300+
st->readers_len = new_readers_len;
301+
new_readers = NULL;
302+
new_readers_len = 0;
303+
300304
done:
301305
for (i = 0; i < new_readers_len; i++)
302306
reftable_reader_decref(new_readers[i]);

0 commit comments

Comments
 (0)