summaryrefslogtreecommitdiff
path: root/refs.go
diff options
context:
space:
mode:
Diffstat (limited to 'refs.go')
-rw-r--r--refs.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/refs.go b/refs.go
new file mode 100644
index 0000000..aec9c91
--- /dev/null
+++ b/refs.go
@@ -0,0 +1,22 @@
+package syw
+
+import "strings"
+
+type Ref struct {
+ Repo *Repository
+ Name string
+ Hash string
+}
+
+func (r Ref) IsBranch() bool { return strings.HasPrefix(r.Name, "refs/heads/") }
+func (r Ref) IsTag() bool { return strings.HasPrefix(r.Name, "refs/tags/") }
+
+func (r Ref) ShortName() string {
+ if r.IsBranch() {
+ return r.Name[11:]
+ } else if r.IsTag() {
+ return r.Name[10:]
+ } else {
+ return r.Name
+ }
+}