ParseQualifiedHeadRef takes strings of the form : or and returns a QualifiedHeadRef. If the form : is used, the owner is set to the value of , and the branch name is set to the value of . If the form is used, the owner is set to None, an
(ref string)
| 53 | // it is not safe to assume the ref is truly a valid ref, e.g. "my~bad:ref?" |
| 54 | // is going to result in a nonsense result. |
| 55 | func ParseQualifiedHeadRef(ref string) (QualifiedHeadRef, error) { |
| 56 | if !strings.Contains(ref, ":") { |
| 57 | return NewQualifiedHeadRefWithoutOwner(ref), nil |
| 58 | } |
| 59 | |
| 60 | parts := strings.Split(ref, ":") |
| 61 | if len(parts) != 2 { |
| 62 | return QualifiedHeadRef{}, fmt.Errorf("invalid qualified head ref format '%s'", ref) |
| 63 | } |
| 64 | |
| 65 | return NewQualifiedHeadRef(parts[0], parts[1]), nil |
| 66 | } |
| 67 | |
| 68 | // A QualifiedHeadRef without an owner returns <branch>, while a QualifiedHeadRef |
| 69 | // with an owner returns <owner>:<branch>. |