Return a human-readable path for this object if we can do better than its OID; otherwise, return "".
()
| 151 | // Return a human-readable path for this object if we can do better |
| 152 | // than its OID; otherwise, return "". |
| 153 | func (p *Path) Path() string { |
| 154 | switch p.objectType { |
| 155 | case "blob", "tree": |
| 156 | if p.parent != nil { |
| 157 | if p.relativePath == "" { |
| 158 | // This is a top-level tree or blob. |
| 159 | return fmt.Sprintf("%s^{%s}", p.parent.BestPath(), p.objectType) |
| 160 | } else { |
| 161 | // The parent is also a tree. |
| 162 | return p.parent.TreePrefix() + p.relativePath |
| 163 | } |
| 164 | } else { |
| 165 | return "" |
| 166 | } |
| 167 | case "commit", "tag": |
| 168 | switch { |
| 169 | case p.parent != nil: |
| 170 | // The parent is a tag. |
| 171 | return fmt.Sprintf("%s^{%s}", p.parent.BestPath(), p.objectType) |
| 172 | case p.relativePath != "": |
| 173 | return p.relativePath |
| 174 | default: |
| 175 | return "" |
| 176 | } |
| 177 | default: |
| 178 | return "" |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Return some human-readable path for this object, even if it's just |
| 183 | // the OID. |
no test coverage detected