Re: [RFC] branch: list branches by single remote
- From
Jeff King <peff@peff.net>
- Date
- Aug 4, 2011, 04:06 UTC
- Message-ID
- <20110804040646.GA5104@sigill.intra.peff.net>
- In-Reply-To
- <4E383132.3040907@elegosoft.com>
On Tue, Aug 02, 2011 at 07:17:38PM +0200, Michael Schubert wrote:
Show 7 quoted lines
> @@ -297,6 +298,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags, > if ((kind & ref_list->kinds) == 0) > return 0; > > + if (cb->remote && strncmp(cb->remote, refname, strlen(cb->remote))) > + return 0; > +
This isn't right. You are assuming that a remote called "foo" will have all of its branches in refs/remotes/foo. That's true under the default configuration, but technically speaking, the remote tracking branches of "foo" are defined by the right-hand side of foo's fetch refspecs.
So I think you want something more like this:
int i;
struct remote *remote = remote_get("foo"); for (i = 0; i < remote->fetch_refspec_nr; i++) {
struct refspec *rs = remote->fetch + i; /* if it's not a wildcard, then take the rhs verbatim */
if (!rs->pattern)
append_ref(rs->dst);
else {
/* it's a wildcard like refs/remotes/foo/*; glob in
* the ref list appropriately. Or we can cheat, noting
* that git's only allowed wildcard is "/*" at the
* end, and do this: */
char *prefix = xstrndup(rs->dst, strlen(rs->dst) - 1);
for_each_ref_in(prefix, append_ref, NULL);
}
}instead of the call to "for_each_rawref(append_ref, ...)" that would normally be used. You could even pretty easily allow selecting branches from multiple remotes, too, though I don't know if that is actually useful.
-Peff