From: Jeff King <peff@peff.net>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 3/3] remote: introduce and fill branch->pushremote
Date: Mon, 13 Jan 2014 03:34:21 -0500 [thread overview]
Message-ID: <20140113083421.GA18531@sigill.intra.peff.net> (raw)
In-Reply-To: <1389546666-17438-4-git-send-email-artagnon@gmail.com>
On Sun, Jan 12, 2014 at 10:41:06PM +0530, Ramkumar Ramachandra wrote:
> When a caller uses branch_get() to retrieve a "struct branch", they get
> the per-branch remote name and a pointer to the remote struct. However,
> they have no way of knowing about the per-branch pushremote from this
> interface. So, let's expose that information via fields similar to
> "remote" and "remote_name"; "pushremote" and "pushremote_name".
Makes sense. This is similar to what I posted before, but stops short of
setting branch->pushremote based on "default.pushremote". I think that's
a good thing. Your patch matches branch->remote better, and the logic
for doing that fallback should probably stay outside of the "struct
branch" construct.
All 3 patches look like sane building blocks to me.
One comment on this hunk, though:
> } else if (!strcmp(subkey, ".pushremote")) {
> + if (git_config_string(&branch->pushremote_name, key, value))
> + return -1;
> if (branch == current_branch)
> - if (git_config_string(&pushremote_name, key, value))
> - return -1;
> + pushremote_name = branch->pushremote_name;
In this code (both before and after your patch), pushremote_name does
double-duty for storing both "remote.pushdefault", and the current
branch's "branch.*.pushremote". I introduced an extra variable in my
version of the patch to store "remote.pushdefault" directly, and turned
pushremote_name into an alias (either to the current branch config, or
to the global config).
I did that for two reasons, one minor and one that I think will come up
further in the topic:
1. After your patch "pushremote_name" sometimes owns its memory (if
allocated for remote.pushdefault), and sometimes not (if an alias to
branch.*.pushremote). This isn't a problem in the current code,
because we never actually free() the string, meaning that if you
set push.default twice, we leak. But that probably does not matter
too much, and we have many such minor leaks of global config.
2. If the current branch has a branch.*.pushremote set, but we want to
know where a _different_ branch would be pushed, we have no way to
access remote.pushdefault (it gets overwritten in the hunk above).
@{upstream} does not have this problem, because it is _only_
defined if branch.*.remote is set. There is no such thing as
defaulting to a "remote.default" (or "origin") there, and we never
need to look at default_remote_name.
For @{publish}, though, I think we will want that default. The
common config will be to simply set "remote.pushdefault", rather
than setting up "branch.*.pushremote" for each branch, and we would
want @{publish} to handle that properly.
So I think your patch is OK as-is, as the problem in (2) does not show
up until later in the series. But I suspect you will need to do
something to address it (and I think it is fine as a patch that comes
later to do that refactoring).
-Peff
next prev parent reply other threads:[~2014-01-13 8:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-12 17:11 [PATCH 0/3] Minor preparation for @{publish} Ramkumar Ramachandra
2014-01-12 17:11 ` [PATCH 1/3] t1507 (rev-parse-upstream): fix typo in test title Ramkumar Ramachandra
2014-01-12 17:11 ` [PATCH 2/3] interpret_branch_name: factor out upstream handling Ramkumar Ramachandra
2014-01-12 17:11 ` [PATCH 3/3] remote: introduce and fill branch->pushremote Ramkumar Ramachandra
2014-01-13 8:34 ` Jeff King [this message]
2014-01-13 11:22 ` Ramkumar Ramachandra
2014-01-13 18:59 ` Jeff King
2014-01-13 20:15 ` Junio C Hamano
2014-01-13 20:27 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140113083421.GA18531@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).