]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add bzr support for vcs root checking
authorGustavo Niemeyer <gustavo@niemeyer.net>
Fri, 24 Oct 2014 17:49:17 +0000 (15:49 -0200)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Fri, 24 Oct 2014 17:49:17 +0000 (15:49 -0200)
Complements the logic introduced in CL 147170043.

LGTM=rsc
R=rsc, gustavo
CC=golang-codereviews
https://golang.org/cl/147240043

src/cmd/go/get.go
src/cmd/go/vcs.go

index 2640339414a5ce62a4a430c71f2aae4aca93fb4b..b8eac5c1ef02bbe555c239ffcc18e7dd05af7155 100644 (file)
@@ -272,8 +272,15 @@ func downloadPackage(p *Package) error {
                        dir := filepath.Join(p.build.SrcRoot, rootPath)
                        if remote, err := vcs.remoteRepo(vcs, dir); err == nil {
                                if rr, err := repoRootForImportPath(p.ImportPath); err == nil {
-                                       if remote != rr.repo {
-                                               return fmt.Errorf("%s is from %s, should be from %s", dir, remote, rr.repo)
+                                       repo := rr.repo
+                                       if rr.vcs.resolveRepo != nil {
+                                               resolved, err := rr.vcs.resolveRepo(rr.vcs, dir, repo)
+                                               if err == nil {
+                                                       repo = resolved
+                                               }
+                                       }
+                                       if remote != repo {
+                                               return fmt.Errorf("%s is from %s, should be from %s", dir, remote, repo)
                                        }
                                }
                        }
index 0834a7d192df7fe32176e6d4234c2a34d2d8345a..1cac6133889be6e4724cb3899e9f2306066dbf8c 100644 (file)
@@ -34,7 +34,8 @@ type vcsCmd struct {
        scheme  []string
        pingCmd string
 
-       remoteRepo func(v *vcsCmd, rootDir string) (remoteRepo string, err error)
+       remoteRepo  func(v *vcsCmd, rootDir string) (remoteRepo string, err error)
+       resolveRepo func(v *vcsCmd, rootDir, remoteRepo string) (realRepo string, err error)
 }
 
 // A tagCmd describes a command to list available tags
@@ -164,8 +165,51 @@ var vcsBzr = &vcsCmd{
        tagSyncCmd:     "update -r {tag}",
        tagSyncDefault: "update -r revno:-1",
 
-       scheme:  []string{"https", "http", "bzr", "bzr+ssh"},
-       pingCmd: "info {scheme}://{repo}",
+       scheme:      []string{"https", "http", "bzr", "bzr+ssh"},
+       pingCmd:     "info {scheme}://{repo}",
+       remoteRepo:  bzrRemoteRepo,
+       resolveRepo: bzrResolveRepo,
+}
+
+func bzrRemoteRepo(vcsBzr *vcsCmd, rootDir string) (remoteRepo string, err error) {
+       outb, err := vcsBzr.runOutput(rootDir, "config parent_location")
+       if err != nil {
+               return "", err
+       }
+       return strings.TrimSpace(string(outb)), nil
+}
+
+func bzrResolveRepo(vcsBzr *vcsCmd, rootDir, remoteRepo string) (realRepo string, err error) {
+       outb, err := vcsBzr.runOutput(rootDir, "info "+remoteRepo)
+       if err != nil {
+               return "", err
+       }
+       out := string(outb)
+
+       // Expect:
+       // ...
+       //   (branch root|repository branch): <URL>
+       // ...
+
+       found := false
+       for _, prefix := range []string{"\n  branch root: ", "\n  repository branch: "} {
+               i := strings.Index(out, prefix)
+               if i >= 0 {
+                       out = out[i+len(prefix):]
+                       found = true
+                       break
+               }
+       }
+       if !found {
+               return "", fmt.Errorf("unable to parse output of bzr info")
+       }
+
+       i := strings.Index(out, "\n")
+       if i < 0 {
+               return "", fmt.Errorf("unable to parse output of bzr info")
+       }
+       out = out[:i]
+       return strings.TrimSpace(string(out)), nil
 }
 
 // vcsSvn describes how to use Subversion.