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

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

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Feb 10, 2013, 15:41 UTC
Message-ID
<CALkWK0mjEmErd2A5qb8qdfNMSXG1L0dt8A=ecbSVFGPEg5MxkA@mail.gmail.com>
In-Reply-To
<7vhallw946.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 25 quoted lines
>         struct bp { const char *branch; const char *remotename; };
>
>         static int pushremote(const char *var, const char *val, void *cb)
>         {
>                 struct bp *bp = cb;
>                 const char *name, *key;
>                 int namelen;
>
>                 if (!parse_config_key(var, "branch", &name, &namelen, &key) &&
>                     namelen == strlen(bp->branch) &&
>                     !memcmp(name, bp->branch, name, namelen) &&
>                     !strcmp(key, "remotepush")) {
>                         git_config_string(&bp->remotename, var, val);
>                 }
>                 return 0;
>         }
>
>         char *find_pushremote(void) {
>                 struct bp bp;
>
>                 bp.branch = get_current_branch();
>                 bp.remotename = NULL;
>                 git_config(pushremote, &bp);
>                 return bp.remotename;
>         }

I don't get the point of your illustration. First, we never deal with a char * branch anywhere: handle_config() immediately calls make_branch() as soon as it parses the name from the config. Second, remote_name is already bundled with the branch struct: why do you need a new bp struct? This is how I would do it without relying on a global:

	static int handle_config(const char *key, const char *value, void *cb) {
		/* parse branch name here */
		/* ... */
		branch = make_branch(name);
		if (!strcmp(subkey, ".pushremote"))
			branch->pushremote_name = xstrdup(value);
	}
	struct remote *pushremote_get(struct branch *this_branch)
	{
		if (this_branch == get_current_branch())
			name = this_branch->pushremote_name;
		/* ... */
		return make_remote(name);
	}

Essentially, I need to know for which branch we're trying to get the pushremote: hence the parameter this_branch to pushremote_get().

> But there is no reason for anybody to want to know the value for the
> variables branch.$name.pushremote for all defined $name's at the
> same time, exactly because this matters only for the current branch,
> no?

Ah, yes. You are right. There's no harm in having globals because there can really be only one current branch, and only one pushremote corresponding to that. It's just that globals tend to confuse me in general, because I have to keep track of a maze of functions that are getting/ setting them.

Previous: Junio C HamanoNext: Blind
Message 13 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.