Return the path of this object under the assumption that another path component will be appended to it.
()
| 120 | // Return the path of this object under the assumption that another |
| 121 | // path component will be appended to it. |
| 122 | func (p *Path) TreePrefix() string { |
| 123 | switch p.objectType { |
| 124 | case "blob", "tree": |
| 125 | if p.parent != nil { |
| 126 | if p.relativePath == "" { |
| 127 | // This is a top-level tree or blob. |
| 128 | return p.parent.TreePrefix() |
| 129 | } else { |
| 130 | // The parent is also a tree. |
| 131 | return p.parent.TreePrefix() + p.relativePath + "/" |
| 132 | } |
| 133 | } else { |
| 134 | return "???" |
| 135 | } |
| 136 | case "commit", "tag": |
| 137 | switch { |
| 138 | case p.parent != nil: |
| 139 | // The parent is a tag. |
| 140 | return fmt.Sprintf("%s^{%s}", p.parent.BestPath(), p.objectType) |
| 141 | case p.relativePath != "": |
| 142 | return p.relativePath + ":" |
| 143 | default: |
| 144 | return p.OID.String() + ":" |
| 145 | } |
| 146 | default: |
| 147 | return "???" |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Return a human-readable path for this object if we can do better |
| 152 | // than its OID; otherwise, return "". |