Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] What's the best way of checking if a local branch has a remote counterpart?

Thanks for the reply Shawn.

Do you mind to continue the discussion on
http://egit.eclipse.org/r/#change,4022 where I applied some part of your
comment?
--
Tomek



From:	Shawn Pearce <spearce@xxxxxxxxxxx>
To:	Tomasz Zarna/Poland/IBM@IBMPL
Cc:	jgit-dev@xxxxxxxxxxx
Date:	2011-08-18 23:38
Subject:	Re: [jgit-dev] What's the best way of checking if a local
            branch has a remote counterpart?



On Thu, Aug 18, 2011 at 02:36, Tomasz Zarna <TomaszZarna@xxxxxxxxxx> wrote:
> On http://egit.eclipse.org/r/#change,4022 I'm trying to figure out a
proper
> set of RefSpec for the PushCommand. What I don't like about the current
> implementation is that it doesn't push changes on local branches which
have
> existing remote counterparts. The code I'm using for this looks like
that:
>
> Map<String, Ref> headsRefList = repo.getRefDatabase().getRefs(
> Constants.R_HEADS);
> Map<String, Ref> remotesRefList = repo.getRefDatabase().getRefs
> (Constants.R_REMOTES);
> for (Iterator<Entry<String, Ref>> iterator = headsRefList.entrySet
> ().iterator(); iterator.hasNext();) {
>   Entry<String, Ref> entry = iterator.next();
>   for (String remoteKey : remotesRefList.keySet()) {
>      if (remoteKey.endsWith(entry.getKey()))
>         refSpecs.add(new RefSpec(entry.getValue().getLeaf().getName()));
>      }
>   }
> }
>
> This makes the test I prepared pass, but it doesn't feel right. Could you
> give me some tips how it should look like? Pointing to a better impl in
> JGit source code would be enough. Thanks.

Aiiiiiiieeee. You are trying to map from local branch to remote branch?

One part of that mapping would be to grab the "branch.$name.merge"
value from the repository's Config object. If its non-null, that is
the remote branch name. Its probably a short name like "master", with
the refs/heads/ bit assumed.

But this can be null and not filled in. If its not filled in, we don't
know where this matches. C Git has a fallback where its looking at the
remote branches in the advertisement to see what matches. JGit's
transport code doesn't currently support this well. You need to do
this part from PushProcess:

  		 		 		 connection = transport.openPush();
		 		 		 try {
		 		 		 		 connection.getRefsMap()

and then match against that returned map. Which means you need to
delay the matching process until PushProcess. Which may mean breaking
the API in Transport, the current

		 public PushResult push(final ProgressMonitor monitor,
		 		 		 Collection<RemoteRefUpdate> toPush)
throws NotSupportedException,
		 		 		 TransportException {

allows the caller to be very specific, but doesn't really support the
notion of deferring the matching until the connection has been opened.

--
Shawn.




Back to the top