Re: [PATCH v2 1/6] remote: fix tear down of struct branch and struct remote
- From
Lidong Yan <yldhome2d2@gmail.com>
- Date
- Jun 18, 2025, 02:44 UTC
- Message-ID
- <16C5347A-3EB4-4629-9C7A-575F60B86CA3@gmail.com>
- In-Reply-To
- <d72fb411-2e05-441e-aee4-d8a26d652fea@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 9 quoted lines
> > We initialize branch->merge with set_merge() which is called by > branch_get() and which is the only way for callers external to remote.c > of getting a branch structure. > > The issue is that merge_nr can be non-zero because if no caller has done > a branch_get() on the given branch, we still have merge_nr is non-zero > and merge is NULL. I suspect you're right that merge_name will never be > NULL while merge_nr is non-zero.
Maybe we can initialize each branch->merge in read_config(). Then branch->merge will always as large as branch->merge_nr. Do you think this would be a good idea?
---
diff --git a/remote.c b/remote.c index 4099183cac..835939c59e 100644 --- a/remote.c +++ b/remote.c @@ -596,6 +596,8 @@ static void alias_all_urls(struct remote_state *remote_state) static void read_config(struct repository *repo, int early) { + struct hashmap_iter iter; + struct branch *b; int flag; if (repo->remote_state->initialized) @@ -614,6 +616,9 @@ static void read_config(struct repository *repo, int early) } repo_config(repo, handle_config, repo->remote_state); alias_all_urls(repo->remote_state); + hashmap_for_each_entry(&repo->remote_state->branches_hash, &item, b, ent) { + set_merge(repo->remote_state, b); + } } #ifndef WITH_BREAKING_CHANGES ---