aboutsummaryrefslogtreecommitdiff
path: root/reftable/stack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-04-02 09:31:17 +0200
committerJunio C Hamano <gitster@pobox.com>2026-04-02 10:45:43 -0700
commitcb0882de1979522b2fc3dc4c3064b0ad21d50b06 (patch)
treef7469680d2cddd98eeea1955d934555ca1d4347b /reftable/stack.c
parentaa8938573050e6ab44a46e3b9f26c0e442f835aa (diff)
downloadgit-cb0882de1979522b2fc3dc4c3064b0ad21d50b06.tar.xz
reftable/system: add abstraction to retrieve time in milliseconds
We directly call gettimeofday(3p), which may not be available on some platforms. Provide the infrastructure to let projects easily use their own implementations of this function. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/stack.c')
-rw-r--r--reftable/stack.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/reftable/stack.c b/reftable/stack.c
index fa87b46c37..1fba96ddb3 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -365,45 +365,26 @@ done:
return err;
}
-/* return negative if a before b. */
-static int tv_cmp(struct timeval *a, struct timeval *b)
-{
- time_t diff = a->tv_sec - b->tv_sec;
- int udiff = a->tv_usec - b->tv_usec;
-
- if (diff != 0)
- return diff;
-
- return udiff;
-}
-
static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
int reuse_open)
{
char **names = NULL, **names_after = NULL;
- struct timeval deadline;
+ uint64_t deadline;
int64_t delay = 0;
int tries = 0, err;
int fd = -1;
- err = gettimeofday(&deadline, NULL);
- if (err < 0)
- goto out;
- deadline.tv_sec += 3;
+ deadline = reftable_time_ms() + 3000;
while (1) {
- struct timeval now;
-
- err = gettimeofday(&now, NULL);
- if (err < 0)
- goto out;
+ uint64_t now = reftable_time_ms();
/*
* Only look at deadlines after the first few times. This
* simplifies debugging in GDB.
*/
tries++;
- if (tries > 3 && tv_cmp(&now, &deadline) >= 0)
+ if (tries > 3 && now >= deadline)
goto out;
fd = open(st->list_file, O_RDONLY);