From: Junio C Hamano <gitster@pobox.com>
To: Aleksei Sviridkin <f@lex.la>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] push: fix --force-if-includes when remote-tracking ref has no reflog
Date: Fri, 04 Sep 2026 08:42:07 -0700 [thread overview]
Message-ID: <xmqqzexx58hc.fsf@gitster.g> (raw)
In-Reply-To: <20260904124433.12840-1-f@lex.la> (Aleksei Sviridkin's message of "Fri, 4 Sep 2026 15:44:33 +0300")
Aleksei Sviridkin <f@lex.la> writes:
> static int is_reachable_in_reflog(const char *local, const struct ref *remote)
> {
> - timestamp_t date;
> + timestamp_t date = 0;
> struct commit *commit;
> struct commit **chunk;
> struct check_and_collect_until_cb_data cb;
This gives a known value to the "date" variable, solving the issue
of using an uninitialized variable. But how do we know if "0" a
reasonable fall-back value? Why is it better than "now" or perhaps
"2 weeks ago"?
We pretend that the latest entry of the remote-tracking ref was from
year 1970. And then that timestamp is used as a cut-off time for
check_and_collect_until(). What's the ramification of that?
> Since 99a1f9ae10 (push: add reflog check for "--force-if-includes",
> 2020-10-03), is_reachable_in_reflog() stops walking the reflog of the
> local branch at entries older than the newest reflog entry of the
> remote-tracking ref. That timestamp is read by a callback of
> refs_for_each_reflog_ent_reverse() into a variable that is never
> initialized, so when the remote-tracking ref has no reflog the walk
> is cut off at whatever happens to be on the stack.
This is almost good as-is. I'd end the above with "... has no reflog,
the variable that holds the timestamp stays uninitialized".
> With the files backend a remote-tracking ref created by "git clone"
> has no reflog and does not get one until it moves. On my machine the
> leftover value exceeds any real timestamp: the walk stops at the very
> first entry, never reaches the "Created from" entry that "checkout
> --track" wrote, and the push is rejected with "remote ref updated
> since checkout" although nothing on the remote has changed.
That describes what happens (eh, rather, what does not happen) when
that uninitialized timestamp is more recent than the current time.
It does not explain why it is sensible to set it to year 1970, which
would force everything to be inspected.
next prev parent reply other threads:[~2026-09-04 15:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 1:05 [PATCH] push: fix --force-if-includes when remote-tracking ref has no reflog Aleksei Sviridkin
2026-09-03 16:16 ` Junio C Hamano
2026-09-03 20:00 ` Aleksei Sviridkin
2026-09-03 20:11 ` Junio C Hamano
2026-09-03 21:45 ` Aleksei Sviridkin
2026-09-04 1:03 ` Kristoffer Haugsbakk
2026-09-04 16:48 ` Junio C Hamano
2026-09-05 17:13 ` Aleksei Sviridkin
2026-09-06 9:39 ` Kristoffer Haugsbakk
2026-09-06 17:14 ` Junio C Hamano
2026-09-07 4:54 ` Thomas Bachem
2026-09-07 6:23 ` Weijie Yuan
2026-09-04 12:44 ` [PATCH v2] " Aleksei Sviridkin
2026-09-04 15:42 ` Junio C Hamano [this message]
2026-09-06 0:45 ` Junio C Hamano
2026-09-06 16:50 ` Aleksei Sviridkin
2026-09-08 3:47 ` Junio C Hamano
2026-09-09 6:56 ` Aleksei Sviridkin
2026-09-10 0:57 ` Junio C Hamano
2026-09-10 8:31 ` Aleksei Sviridkin
2026-09-05 17:13 ` [PATCH v3] " Aleksei Sviridkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzexx58hc.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=f@lex.la \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox