Re: [JGIT PATCH 05/11] Don't advertise HEAD from ReceivePack
- From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
- Date
- Jul 21, 2009, 15:22 UTC
- Message-ID
- <200907211722.09631.robin.rosenberg.lists@dewire.com>
- In-Reply-To
- <1247343566-19025-6-git-send-email-spearce@spearce.org>
lördag 11 juli 2009 22:19:20 skrev "Shawn O. Pearce" <spearce@spearce.org>:
Show 27 quoted lines
> The HEAD ref cannot be pushed to by a client, if it is a detached HEAD
> the client shouldn't be permitted to change it, if it is a symref to
> another ref then the client should update the destination ref and not
> the symref. Instead offer the HEAD ref as a ".have" line, which is an
> invalid ref that the client can't update but still lets the client know
> we have its target object reachable.
>
> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
> ---
> .../org/spearce/jgit/transport/ReceivePack.java | 5 ++++-
> .../org/spearce/jgit/transport/RefAdvertiser.java | 15 +++++++++++++++
> 2 files changed, 19 insertions(+), 1 deletions(-)
>
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
> index fd8aa86..1c490af 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
> @@ -509,8 +509,11 @@ private void sendAdvertisedRefs() throws IOException {
> adv.advertiseCapability(CAPABILITY_REPORT_STATUS);
> if (allowOfsDelta)
> adv.advertiseCapability(CAPABILITY_OFS_DELTA);
> - refs = db.getAllRefs();
> + refs = new HashMap<String, Ref>(db.getAllRefs());
> + final Ref head = refs.remove(Constants.HEAD);
> adv.send(refs.values());
> + if (head != null && head.getName() == head.getOrigName())
> + adv.advertiseHave(head.getObjectId());This relies on an implicit guarantee that == works here. Would equals cost too much? Or perhaps we should document this guarantee as part of the interface.
-- robin