<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/remote.h, branch main</title>
<subtitle>Fork of git SCM with my patches.</subtitle>
<id>http://git.kilabit.info/git/atom?h=main</id>
<link rel='self' href='http://git.kilabit.info/git/atom?h=main'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/'/>
<updated>2026-01-20T00:24:02Z</updated>
<entry>
<title>remote: always allocate branch.push_tracking_ref</title>
<updated>2026-01-20T00:24:02Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2026-01-19T05:23:20Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=d79fff4a11a527f57516c62fe00777852bab719a'/>
<id>urn:sha1:d79fff4a11a527f57516c62fe00777852bab719a</id>
<content type='text'>
In branch_get_push(), we usually allocate a new string for the @{push}
ref, but will not do so in push.default=upstream mode, where we just
pass back the result of branch_get_upstream() directly.

This led to a hacky memory management scheme in e291c75a95 (remote.c:
add branch_get_push, 2015-05-21): we store the result in the
push_tracking_ref field of a "struct branch", under the assumption that
the branch struct will last until the end of the program. So even though
the struct doesn't know if it has an allocated string or not, it doesn't
matter because we hold on to it either way.

But that assumption was violated by f5ccb535cc (remote: fix leaking
config strings, 2024-08-22), which added a function to free branch
structs. Any struct which is fed to branch_release() is at risk of
leaking its push_tracking_ref member.

I don't think this can actually be triggered in practice. We rarely
actually free the branch structs, and we only fill in the
push_tracking_ref string lazily when it is needed. So triggering the
leak would require a code path that does both, and I couldn't find one.

Still, this is an ugly trap that may eventually spring on us. Since
there is only one code path in branch_get_push() that doesn't allocate,
let's just have it copy the string. And then we know that
push_tracking_ref is always allocated, and we can free it in
branch_release().

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>submodule: look up remotes by URL first</title>
<updated>2025-06-23T23:38:57Z</updated>
<author>
<name>Jacob Keller</name>
<email>jacob.keller@gmail.com</email>
</author>
<published>2025-06-23T23:11:35Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=ca62f524c1eaef606b5c312de53ef7c4d9eefa4f'/>
<id>urn:sha1:ca62f524c1eaef606b5c312de53ef7c4d9eefa4f</id>
<content type='text'>
The get_default_remote_submodule() function performs a lookup to find
the appropriate remote to use within a submodule. The function first
checks to see if it can find the remote for the current branch. If this
fails, it then checks to see if there is exactly one remote. It will use
this, before finally falling back to "origin" as the default.

If a user happens to rename their default remote from origin, either
manually or by setting something like clone.defaultRemoteName, this
fallback will not work.

In such cases, the submodule logic will try to use a non-existent
remote. This usually manifests as a failure to trigger the submodule
update.

The parent project already knows and stores the submodule URL in either
.gitmodules or its .git/config.

Add a new repo_remote_from_url() helper which will iterate over all the
remotes in a repository and return the first remote which has a matching
URL.

Refactor get_default_remote_submodule to find the submodule and get its
URL. If a valid URL exists, first try to obtain a remote using the new
repo_remote_from_url(). Fall back to the repo_default_remote()
otherwise.

The fallback logic is kept in case for some reason the user has manually
changed the URL within the submodule. Additionally, we still try to use
a remote rather than directly passing the URL in the
fetch_in_submodule() logic. This ensures that an update will properly
update the remote refs within the submodule as expected, rather than
just fetching into FETCH_HEAD.

Signed-off-by: Jacob Keller &lt;jacob.keller@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>submodule--helper: improve logic for fallback remote name</title>
<updated>2025-06-23T23:38:57Z</updated>
<author>
<name>Jacob Keller</name>
<email>jacob.keller@gmail.com</email>
</author>
<published>2025-06-23T23:11:33Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=e759275c8fbf76e380600a87f72d6857d3b48ba3'/>
<id>urn:sha1:e759275c8fbf76e380600a87f72d6857d3b48ba3</id>
<content type='text'>
The repo_get_default_remote() function in submodule--helper currently
tries to figure out the proper remote name to use for a submodule based
on a few factors.

First, it tries to find the remote for the currently checked out branch.
This works if the submodule is configured to checkout to a branch
instead of a detached HEAD state.

In the detached HEAD state, the code calls back to using "origin", on
the assumption that this is the default remote name. Some users may
change this, such as by setting clone.defaultRemoteName, or by changing
the remote name manually within the submodule repository.

As a first step to improving this situation, refactor to reuse the logic
from remotes_remote_for_branch(). This function uses the remote from the
branch if it has one. If it doesn't then it checks to see if there is
exactly one remote. It uses this remote first before attempting to fall
back to "origin".

To allow using this helper function, introduce a repo_default_remote()
helper to remote.c which takes a repository structure. This helper will
load the remote configuration and get the "HEAD" branch. Then it will
call remotes_remote_for_branch to find the default remote.

Replace calls of repo_get_default_remote() with the calls to this new
function. To maintain consistency with the existing callers, continue
copying the returned string with xstrdup.

This isn't a perfect solution for users who change remote names, but it
should help in cases where the remote name is changed but users haven't
added any additional remotes.

Signed-off-by: Jacob Keller &lt;jacob.keller@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>remote: remove branch-&gt;merge_name and fix branch_release()</title>
<updated>2025-06-23T23:38:55Z</updated>
<author>
<name>Jacob Keller</name>
<email>jacob.keller@gmail.com</email>
</author>
<published>2025-06-23T23:11:29Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=f62dcc7f30d16af29c0f707005aceb5eb6119279'/>
<id>urn:sha1:f62dcc7f30d16af29c0f707005aceb5eb6119279</id>
<content type='text'>
The branch structure has both branch-&gt;merge_name and branch-&gt;merge for
tracking the merge information. The former is allocated by add_merge()
and stores the names read from the configuration file. The latter is
allocated by set_merge() which is called by branch_get() when an
external caller requests a branch.

This leads to the confusing situation where branch-&gt;merge_nr tracks both
the size of branch-&gt;merge (once its allocated) and branch-&gt;merge_name.
The branch_release() function incorrectly assumes that branch-&gt;merge is
always set when branch-&gt;merge_nr is non-zero, and can potentially crash
if read_config() is called without branch_get() being called on every
branch.

In addition, branch_release() fails to free some of the memory
associated with the structure including:

 * Failure to free the refspec_item containers in branch-&gt;merge[i]
 * Failure to free the strings in branch-&gt;merge_name[i]
 * Failure to free the branch-&gt;merge_name parent array.

The set_merge() function sets branch-&gt;merge_nr to 0 when there is no
valid remote_name, to avoid external callers seeing a non-zero merge_nr
but a NULL merge array. This results in failure to release most of the
merge data as well.

These issues could be fixed directly, and indeed I initially proposed
such a change at [1] in the past. While this works, there was some
confusion during review because of the inconsistencies.

Instead, its time to clean up the situation properly. Remove
branch-&gt;merge_name entirely. Instead, allocate branch-&gt;merge earlier
within add_merge() instead of within set_merge(). Instead of having
set_merge() copy from merge_name[i] to merge[i]-&gt;src, just have
add_merge() directly initialize merge[i]-&gt;src.

Modify the add_merge() to call xstrdup() itself, instead of having
the caller of add_merge() do so. This makes it more obvious which code
owns the memory.

Update all callers which use branch-&gt;merge_name[i] to use
branch-&gt;merge[i]-&gt;src instead.

Add a merge_clear() function which properly releases all of the
merge-related memory, and which sets branch-&gt;merge_nr to zero. Use this
both in branch_release() and in set_merge(), fixing the leak when
set_merge() finds no valid remote_name.

Add a set_merge variable to the branch structure, which indicates
whether set_merge() has been called. This replaces the previous use of a
NULL check against the branch-&gt;merge array.

With these changes, the merge array is always allocated when merge_nr is
non-zero.

This use of refspec_item to store the names should be safe. External
callers should be using branch_get() to obtain a pointer to the branch,
which will call set_merge(), and the callers internal to remote.c
already handle the partially initialized refpsec_item structure safely.

This end result is cleaner, and avoids duplicating the merge names
twice.

Signed-off-by: Jacob Keller &lt;jacob.keller@gmail.com&gt;
Link: [1] https://lore.kernel.org/git/20250617-jk-submodule-helper-use-url-v2-1-04cbb003177d@gmail.com/
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>remote: allow `guess_remote_head()` to suppress advice</title>
<updated>2025-03-25T23:09:27Z</updated>
<author>
<name>Justin Tobler</name>
<email>jltobler@gmail.com</email>
</author>
<published>2025-03-25T00:51:46Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=d5d284df910b5f03681b480ae061bb1435b3b4b2'/>
<id>urn:sha1:d5d284df910b5f03681b480ae061bb1435b3b4b2</id>
<content type='text'>
The `repo_default_branch_name()` invoked through `guess_remote_head()`
is configured to always display the default branch advice message.

Adapt `guess_remote_head()` to accept flags and convert the `all`
parameter to a flag. Add the `REMOTE_GUESS_HEAD_QUIET` flag to to enable
suppression of advice messages. Call sites are updated accordingly.

Signed-off-by: Justin Tobler &lt;jltobler@gmail.com&gt;
Acked-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'tc/clone-single-revision'</title>
<updated>2025-02-15T01:53:48Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2025-02-15T01:53:47Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=5785d9143bcb3ef19452a83bc2e870ff3d5ed95a'/>
<id>urn:sha1:5785d9143bcb3ef19452a83bc2e870ff3d5ed95a</id>
<content type='text'>
"git clone" learned to make a shallow clone for a single commit
that is not necessarily be at the tip of any branch.

* tc/clone-single-revision:
  builtin/clone: teach git-clone(1) the --revision= option
  parse-options: introduce die_for_incompatible_opt2()
  clone: introduce struct clone_opts in builtin/clone.c
  clone: add tags refspec earlier to fetch refspec
  clone: refactor wanted_peer_refs()
  clone: make it possible to specify --tags
  clone: cut down on global variables in clone.c
</content>
</entry>
<entry>
<title>Merge branch 'ms/remote-valid-remote-name'</title>
<updated>2025-02-12T18:08:54Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2025-02-12T18:08:54Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=0a99ffb4d6645142e68517c59db61b7e58a4f7cc'/>
<id>urn:sha1:0a99ffb4d6645142e68517c59db61b7e58a4f7cc</id>
<content type='text'>
Code shuffling.

* ms/remote-valid-remote-name:
  remote: relocate valid_remote_name
</content>
</entry>
<entry>
<title>Merge branch 'ms/refspec-cleanup'</title>
<updated>2025-02-12T18:08:54Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2025-02-12T18:08:54Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=998c5f0c7554f511bafff587292f986a42fa2944'/>
<id>urn:sha1:998c5f0c7554f511bafff587292f986a42fa2944</id>
<content type='text'>
Code clean-up.  cf. &lt;Z6G-toOJjMmK8iJG@pks.im&gt;

* ms/refspec-cleanup:
  refspec: relocate apply_refspecs and related funtions
  refspec: relocate matching related functions
  remote: rename query_refspecs functions
  refspec: relocate refname_matches_negative_refspec_item
  remote: rename function omit_name_by_refspec
</content>
</entry>
<entry>
<title>clone: introduce struct clone_opts in builtin/clone.c</title>
<updated>2025-02-06T20:23:54Z</updated>
<author>
<name>Toon Claes</name>
<email>toon@iotcl.com</email>
</author>
<published>2025-02-06T06:33:33Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=7a52a8c7d855d3ed779059af160248934ac2c6b0'/>
<id>urn:sha1:7a52a8c7d855d3ed779059af160248934ac2c6b0</id>
<content type='text'>
There is a lot of state stored in global variables in builtin/clone.c.
In the long run we'd like to remove many of those.

Introduce `struct clone_opts` in this file. This struct will be used to
contain all details needed to perform the clone. The struct object can
be thrown around to all the functions that need these details.

The first field we're adding is `wants_head`. In some scenarios
(specifically when both `--single-branch` and `--branch` are given) we
are not interested in `HEAD` on the remote. The field `wants_head` in
`struct clone_opts` will hold this information. We could have put
`option_branch` and `option_single_branch` into that struct instead, but
in a following commit we'll be using `wants_head` as well.

Signed-off-by: Toon Claes &lt;toon@iotcl.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>remote: relocate valid_remote_name</title>
<updated>2025-02-04T17:55:59Z</updated>
<author>
<name>Meet Soni</name>
<email>meetsoni3017@gmail.com</email>
</author>
<published>2025-02-04T14:28:52Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=f21ea69d945f958704f2fe143c2638ecae6e0d12'/>
<id>urn:sha1:f21ea69d945f958704f2fe143c2638ecae6e0d12</id>
<content type='text'>
Move the `valid_remote_name()` function from the refspec subsystem to
the remote subsystem to better align with the separation of concerns.

Signed-off-by: Meet Soni &lt;meetsoni3017@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
