"Glen Choo via GitGitGadget" [off-list ref] writes:
-static void add_pushurl_alias(struct remote *remote, const char *url)
+static void add_pushurl_alias(struct remote_state *remote_state,
+ struct remote *remote, const char *url)
{
I am not sure if this is a good interface. It allows a caller to
obtain "struct remote *" instance from somewhere, and feed it with
an instance of "struct remote_state *" that has nothing to do with
the "struct remote *", no?
quoted hunk
-static struct remote *make_remote(const char *name, int len)
+static struct remote *make_remote(struct remote_state *remote_state,
+ const char *name, int len)
{
struct remote *ret;
struct remotes_hash_key lookup;@@ -147,7 +119,7 @@ static struct remote *make_remote(const char *name, int len)
if (!len)
len = strlen(name);
- init_remotes_hash();
+ init_remotes_hash(remote_state);
lookup.str = name;
lookup.len = len;
hashmap_entry_init(&lookup_entry, memhash(name, len));
@@ -173,6 +145,28 @@ static struct remote *make_remote(const char *name, int len)
return ret;
Instead, shouldn't "struct remote *" _know_ which remote-state it
came from?
I didn't look, but I suspect that there may be similar problems with
other structures like "branch" in this change.
Thanks.
Junio C Hamano [off-list ref] writes:
quoted
-static void add_pushurl_alias(struct remote *remote, const char *url)
+static void add_pushurl_alias(struct remote_state *remote_state,
+ struct remote *remote, const char *url)
{
I am not sure if this is a good interface. It allows a caller to
obtain "struct remote *" instance from somewhere, and feed it with
an instance of "struct remote_state *" that has nothing to do with
the "struct remote *", no?
Valid point, this interface should not be so easy to misuse.
Instead, shouldn't "struct remote *" _know_ which remote-state it
came from?
I am less certain about this. The pattern of
container->contained->container is convenient for callers, but requires
very deliberate maintenance and the reduced separation might promote
thoughtless use of the interfaces e.g. "Should I use struct remote_state
+ name or struct remote? Eh doesn't matter, they're equivalent."
Instead, we could converge on a pattern of:
* struct remote_state + name when the caller does something in the
context of the remote's repository.
* struct remote when the caller doesn't need the remote's repository
I think we might do this in slightly different ways for branches vs
remotes.
I didn't look, but I suspect that there may be similar problems with
other structures like "branch" in this change.
Looking into it, it appears that only static functions pass struct
remote_state and struct remote at the same time. That gives us a lot of
leeway to clean things up inside of remote.c.
The same cannot be said for struct branch, that will be much harder to
clean up. In fact, rereading patch 2, I missed many implicit references
to the_repository in the branch functions, so the pattern of struct
remote_state + struct branch would actually more pervasive than it seems.
However, I suspect that we don't need to pass around struct branch very
often. We may be able to maintain referential integrity by passing the
branch name instead.