expose latest changeset id of branch

This commit is contained in:
Sebastian Sdorra
2015-06-13 19:56:16 +02:00
parent ee0278b893
commit 0f1ac3f952
3 changed files with 46 additions and 4 deletions

View File

@@ -73,12 +73,28 @@ public final class Branch implements Serializable
*
*
* @param name name of the branch
*
* @deprecated use {@link Branch#Branch(String, String)} instead
*/
@Deprecated
public Branch(String name)
{
this.name = name;
}
/**
* Constructs a new branch.
*
*
* @param name name of the branch
* @param revision latest revision of the branch
*/
public Branch(String name, String revision)
{
this.name = name;
this.revision = revision;
}
//~--- methods --------------------------------------------------------------
/**
@@ -104,7 +120,8 @@ public final class Branch implements Serializable
final Branch other = (Branch) obj;
return Objects.equal(name, other.name);
return Objects.equal(name, other.name)
&& Objects.equal(revision, other.revision);
}
/**
@@ -116,7 +133,7 @@ public final class Branch implements Serializable
@Override
public int hashCode()
{
return Objects.hashCode(name);
return Objects.hashCode(name, revision);
}
/**
@@ -131,6 +148,7 @@ public final class Branch implements Serializable
//J-
return Objects.toStringHelper(this)
.add("name", name)
.add("revision", revision)
.toString();
//J+
}
@@ -148,8 +166,21 @@ public final class Branch implements Serializable
return name;
}
/**
* Returns the latest revision of the branch.
*
* @return latest revision of branch
*/
public String getRevision()
{
return revision;
}
//~--- fields ---------------------------------------------------------------
/** name of the branch */
private String name;
/** Field description */
private String revision;
}

View File

@@ -105,7 +105,7 @@ public class GitBranchesCommand extends AbstractGitCommand
if (branchName != null)
{
branch = new Branch(branchName);
branch = new Branch(branchName, GitUtil.getId(ref.getObjectId()));
}
return branch;

View File

@@ -30,10 +30,13 @@
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.aragost.javahg.Changeset;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
@@ -92,7 +95,15 @@ public class HgBranchesCommand extends AbstractCommand
@Override
public Branch apply(com.aragost.javahg.commands.Branch hgBranch)
{
return new Branch(hgBranch.getName());
String node = null;
Changeset changeset = hgBranch.getBranchTip();
if (changeset != null)
{
node = changeset.getNode();
}
return new Branch(hgBranch.getName(), node);
}
});