forked from jenkinsci/git-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevision.java
More file actions
97 lines (79 loc) · 2.47 KB
/
Copy pathRevision.java
File metadata and controls
97 lines (79 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package hudson.plugins.git;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import hudson.Util;
import java.util.ArrayList;
import java.util.Collection;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.eclipse.jgit.lib.ObjectId;
/**
* A Revision is a SHA1 in the object tree, and the collection of branches that
* share this ID. Unlike other SCMs, git can have >1 branches point at the
* _same_ commit.
*
* @author magnayn
*/
@ExportedBean(defaultVisibility = 999)
public class Revision implements java.io.Serializable, Cloneable {
private static final long serialVersionUID = -7203898556389073882L;
ObjectId sha1;
Collection<Branch> branches;
public Revision(ObjectId sha1) {
this.sha1 = sha1;
this.branches = new ArrayList<Branch>();
}
public Revision(ObjectId sha1, Collection<Branch> branches) {
this.sha1 = sha1;
this.branches = branches;
}
public ObjectId getSha1() {
return sha1;
}
@Exported(name = "SHA1")
public String getSha1String() {
return sha1 == null ? "" : sha1.name();
}
public void setSha1(ObjectId sha1) {
this.sha1 = sha1;
}
@Exported(name = "branch")
public Collection<Branch> getBranches() {
return branches;
}
public void setBranches(Collection<Branch> branches) {
this.branches = branches;
}
public boolean containsBranchName(String name) {
for (Branch b : branches) {
if (b.getName().equals(name)) {
return true;
}
}
return false;
}
public String toString() {
StringBuilder s = new StringBuilder("Revision " + sha1.name() + " (");
Joiner.on(", ").appendTo(s,
Iterables.transform(branches, new Function<Branch, String>() {
public String apply(Branch from) {
return Util.fixNull(from.getName());
}
}));
s.append(')');
return s.toString();
}
@Override
public Revision clone() {
Revision clone;
try {
clone = (Revision) super.clone();
}
catch (CloneNotSupportedException e) {
throw new RuntimeException("Error cloning Revision", e);
}
clone.branches = new ArrayList<Branch>(branches);
return clone;
}
}