git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH] Introduce branch.<name>.pushremote

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2013, 20:04 UTC
Message-ID
<7v8v6y1sih.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1360307982-20027-1-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 13 quoted lines
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 9b11597..0b3b1f8 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -727,6 +727,12 @@ branch.<name>.remote::
>  	remote to fetch from/push to.  It defaults to `origin` if no remote is
>  	configured. `origin` is also used if you are not on any branch.
>  
> +branch.<name>.pushremote::
> +	When in branch <name>, it tells 'git push' which remote to
> +	push to.  It falls back to `branch.<name>.remote`, and
> +	defaults to `origin` if no remote is configured. `origin` is
> +	also used if you are not on any branch.

Sounds sensible (modulo the missing "default location to push to that is not per remote" bit, obviously). I think "When _on_ branch" is more correct, to match "if you are not on any branch" at the end, though.

Show 20 quoted lines
> diff --git a/remote.c b/remote.c
> index e53a6eb..d6fcfc0 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -48,6 +48,7 @@ static int branches_nr;
>  
>  static struct branch *current_branch;
>  static const char *default_remote_name;
> +static const char *pushremote_name;
>  static int explicit_default_remote_name;
>  
>  static struct rewrites rewrites;
> @@ -363,6 +364,12 @@ static int handle_config(const char *key, const char *value, void *cb)
>  				default_remote_name = branch->remote_name;
>  				explicit_default_remote_name = 1;
>  			}
> +		} else if (!strcmp(subkey, ".pushremote")) {
> +			if (!value)
> +				return config_error_nonbool(key);
> +			branch->pushremote_name = xstrdup(value);
Perhaps use git_config_string()?

I also notice that git_config_string() should free (*dest) if there already is some value, and that has to be done after auditing all existing callers.

> +			if (branch == current_branch)
> +				pushremote_name = branch->pushremote_name;
Why is this global only when current_branch is involved?

In other words, does it make sense to read branch.$name.pushremote for all the other irrelevant branches?

In yet other words, perhaps adding pushremote_name to the branch structure is unneeded, and you only need this single global variable?

(The remainder of the patch unsnipped for others' reference.)
Show 61 quoted lines
> @@ -700,6 +707,40 @@ struct remote *remote_get(const char *name)
>  	return ret;
>  }
>  
> +struct remote *pushremote_get(const char *name)
> +{
> +	struct remote *ret;
> +	int name_given = 0;
> +
> +	read_config();
> +	if (name)
> +		name_given = 1;
> +	else {
> +		if (pushremote_name) {
> +			name = pushremote_name;
> +			name_given = 1;
> +		} else {
> +			name = default_remote_name;
> +			name_given = explicit_default_remote_name;
> +		}
> +	}
> +
> +	ret = make_remote(name, 0);
> +	if (valid_remote_nick(name)) {
> +		if (!valid_remote(ret))
> +			read_remotes_file(ret);
> +		if (!valid_remote(ret))
> +			read_branches_file(ret);
> +	}
> +	if (name_given && !valid_remote(ret))
> +		add_url_alias(ret, name);
> +	if (!valid_remote(ret))
> +		return NULL;
> +	ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);
> +	ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);
> +	return ret;
> +}
> +
>  int remote_is_configured(const char *name)
>  {
>  	int i;
> diff --git a/remote.h b/remote.h
> index 251d8fd..aa42ff5 100644
> --- a/remote.h
> +++ b/remote.h
> @@ -51,6 +51,7 @@ struct remote {
>  };
>  
>  struct remote *remote_get(const char *name);
> +struct remote *pushremote_get(const char *name);
>  int remote_is_configured(const char *name);
>  
>  typedef int each_remote_fn(struct remote *remote, void *priv);
> @@ -130,6 +131,7 @@ struct branch {
>  	const char *refname;
>  
>  	const char *remote_name;
> +	const char *pushremote_name;
>  	struct remote *remote;
>  
>  	const char **merge_name;
Previous: Junio C HamanoNext: Ramkumar Ramachandra
Message 10 of 18 in “Introduce branch.<name>.pushremote”
  1. Introduce branch.<name>.pushremoteRamkumar Ramachandra, Feb 8, 2013
  2. Junio C HamanoFeb 8, 2013
  3. Introduce remote.pushdefaultRamkumar Ramachandra, Feb 8, 2013
  4. Junio C HamanoFeb 8, 2013
  5. Ramkumar RamachandraFeb 9, 2013
  6. Ramkumar RamachandraMar 17, 2013
  7. Jeff KingMar 17, 2013
  8. Ramkumar RamachandraMar 18, 2013
  9. Junio C HamanoMar 17, 2013
  10. Junio C HamanoFeb 8, 2013
  11. Ramkumar RamachandraFeb 9, 2013
  12. Junio C HamanoFeb 9, 2013
  13. Ramkumar RamachandraFeb 10, 2013
  14. BlindFeb 11, 2013
  15. Ramkumar RamachandraFeb 19, 2013
  16. BlindFeb 19, 2013
  17. Ramkumar RamachandraFeb 19, 2013
  18. BlindFeb 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.