@@ -32,38 +32,35 @@ const scheme = "git"
3232const refPrefix = "refs/"
3333
3434// changeIDFormat is the expected format for change IDs, included in error messages.
35- const changeIDFormat = "git://{host }/{repo-path }/{ref}/{commit_sha}"
35+ const changeIDFormat = "git://{remote }/{repo}/{ref}/{commit_sha}"
3636
3737// shaLength is the length of a git commit SHA.
3838const shaLength = 40
3939
4040// ChangeID represents a parsed git:// change identifier.
41- // Format: git://{host }/{repo-path }/{ref}/{commit_sha}
41+ // Format: git://{remote }/{repo}/{ref}/{commit_sha}
4242//
4343// Ref is a fully-qualified, percent-encoded git ref so that branches, tags, and
4444// ref names containing slashes all fit a single path segment unambiguously.
4545type ChangeID struct {
4646 // Scheme captures the URI scheme (always "git" in current implementation).
4747 Scheme string
48- // Host is the git remote authority, "host" or "host:port" (e.g.
49- // "git.example.com" or "git.example.com:9418"). Unlike a forge "org", git
50- // addresses a repository by the remote it lives on.
51- Host string
52- // RepoPath is the path to the repository on the remote and may contain
53- // slashes (e.g. "uber/monorepo" or "team/group/repo.git").
54- RepoPath string
48+ // Remote is the host (or host:port) of the git remote the repository lives
49+ // on (e.g. "git.example.com" or "git.example.com:9418").
50+ Remote string
51+ // Repo is the path to the repository on the remote and may contain slashes
52+ // (e.g. "uber/monorepo" or "team/group/repo.git").
53+ Repo string
5554 // Ref is the fully-qualified git ref the change landed on, decoded from the
5655 // URI (e.g. "refs/heads/main", "refs/tags/v1.0").
5756 Ref string
58- // CommitSHA is the commit Ref pointed at, captured at a point in time. It is
59- // not necessarily a branch head; it records the commit Ref resolved to when
60- // the change entered the pipeline.
57+ // CommitSHA is a commit that ref has pointed to at some point in time.
6158 CommitSHA string
6259}
6360
6461// ParseChangeID parses a raw change ID string into a ChangeID.
65- // Expected format: git://{host }/{repo-path }/{commit_sha} with a fully-qualified,
66- // percent-encoded ref as the second-to-last path segment .
62+ // Expected format: git://{remote }/{repo}/{ref}/{ commit_sha}, where {ref} is a
63+ // fully-qualified, percent-encoded git ref (e.g. "refs%2Fheads%2Fmain") .
6764func ParseChangeID (raw string ) (ChangeID , error ) {
6865 u , err := url .Parse (raw )
6966 if err != nil {
@@ -73,20 +70,20 @@ func ParseChangeID(raw string) (ChangeID, error) {
7370 return ChangeID {}, fmt .Errorf ("invalid change ID %q: scheme must be %q, got %q (expected format: %s)" , raw , scheme , u .Scheme , changeIDFormat )
7471 }
7572 if u .Host == "" {
76- return ChangeID {}, fmt .Errorf ("invalid change ID %q: missing remote host (expected format: %s)" , raw , changeIDFormat )
73+ return ChangeID {}, fmt .Errorf ("invalid change ID %q: missing remote (expected format: %s)" , raw , changeIDFormat )
7774 }
7875
7976 // Split on the escaped path so the percent-encoded ref stays a single
8077 // segment (url.URL.Path decodes %2F to "/", which would split it apart).
8178 segments := strings .Split (strings .TrimPrefix (u .EscapedPath (), "/" ), "/" )
82- // Need at least 3 segments: {repo-path }/{ref}/{commit_sha}.
79+ // Need at least 3 segments: {repo}/{ref}/{commit_sha}.
8380 if len (segments ) < 3 {
84- return ChangeID {}, fmt .Errorf ("invalid change ID %q: need at least repo-path /ref/sha, got %d path segments (expected format: %s)" , raw , len (segments ), changeIDFormat )
81+ return ChangeID {}, fmt .Errorf ("invalid change ID %q: need at least repo/ref/sha, got %d path segments (expected format: %s)" , raw , len (segments ), changeIDFormat )
8582 }
8683
8784 sha := segments [len (segments )- 1 ]
8885 encodedRef := segments [len (segments )- 2 ]
89- repoPath := strings .Join (segments [:len (segments )- 2 ], "/" )
86+ repo := strings .Join (segments [:len (segments )- 2 ], "/" )
9087
9188 if sha == "" {
9289 return ChangeID {}, fmt .Errorf ("invalid change ID %q: empty commit SHA (expected format: %s)" , raw , changeIDFormat )
@@ -103,20 +100,20 @@ func ParseChangeID(raw string) (ChangeID, error) {
103100 return ChangeID {}, fmt .Errorf ("invalid change ID %q: ref %q must be a fully-qualified git ref (e.g. refs/heads/main, refs/tags/v1.0) (expected format: %s)" , raw , ref , changeIDFormat )
104101 }
105102
106- if repoPath == "" {
107- return ChangeID {}, fmt .Errorf ("invalid change ID %q: empty repo path (expected format: %s)" , raw , changeIDFormat )
103+ if repo == "" {
104+ return ChangeID {}, fmt .Errorf ("invalid change ID %q: empty repo (expected format: %s)" , raw , changeIDFormat )
108105 }
109106
110107 return ChangeID {
111108 Scheme : u .Scheme ,
112- Host : u .Host ,
113- RepoPath : repoPath ,
109+ Remote : u .Host ,
110+ Repo : repo ,
114111 Ref : ref ,
115112 CommitSHA : sha ,
116113 }, nil
117114}
118115
119116// String returns the string representation of the change ID.
120117func (c ChangeID ) String () string {
121- return fmt .Sprintf ("%s://%s/%s/%s/%s" , c .Scheme , c .Host , c .RepoPath , url .PathEscape (c .Ref ), c .CommitSHA )
118+ return fmt .Sprintf ("%s://%s/%s/%s/%s" , c .Scheme , c .Remote , c .Repo , url .PathEscape (c .Ref ), c .CommitSHA )
122119}
0 commit comments