浏览代码

models/mirror: feed git.IsRepoURLAccessible with raw mirror address

Unknwon 8 年之前
父节点
当前提交
c05717a5f0
共有 4 个文件被更改,包括 18 次插入13 次删除
  1. 15 9
      models/mirror.go
  2. 1 1
      routers/api/v1/repo/repo.go
  3. 0 1
      routers/repo/http.go
  4. 2 2
      routers/repo/repo.go

+ 15 - 9
models/mirror.go

@@ -121,13 +121,13 @@ func (m *Mirror) readAddress() {
 		log.Error(2, "Load: %v", err)
 		return
 	}
-	m.address = unescapeMirrorCredentials(cfg.Section("remote \"origin\"").Key("url").Value())
+	m.address = cfg.Section("remote \"origin\"").Key("url").Value()
 }
 
-// HandleCloneUserCredentials replaces user credentials from HTTP/HTTPS URL
+// HandleMirrorCredentials replaces user credentials from HTTP/HTTPS URL
 // with placeholder <credentials>.
-// It will fail for any other forms of clone addresses.
-func HandleCloneUserCredentials(url string, mosaics bool) string {
+// It returns original string if protocol is not HTTP/HTTPS.
+func HandleMirrorCredentials(url string, mosaics bool) string {
 	i := strings.Index(url, "@")
 	if i == -1 {
 		return url
@@ -145,21 +145,27 @@ func HandleCloneUserCredentials(url string, mosaics bool) string {
 // Address returns mirror address from Git repository config without credentials.
 func (m *Mirror) Address() string {
 	m.readAddress()
-	return HandleCloneUserCredentials(m.address, false)
+	return HandleMirrorCredentials(m.address, false)
 }
 
 // MosaicsAddress returns mirror address from Git repository config with credentials under mosaics.
 func (m *Mirror) MosaicsAddress() string {
 	m.readAddress()
-	return HandleCloneUserCredentials(m.address, true)
+	return HandleMirrorCredentials(m.address, true)
 }
 
-// FullAddress returns mirror address from Git repository config.
-func (m *Mirror) FullAddress() string {
+// RawAddress returns raw mirror address directly from Git repository config.
+func (m *Mirror) RawAddress() string {
 	m.readAddress()
 	return m.address
 }
 
+// FullAddress returns mirror address from Git repository config with unescaped credentials.
+func (m *Mirror) FullAddress() string {
+	m.readAddress()
+	return unescapeMirrorCredentials(m.address)
+}
+
 // escapeCredentials returns mirror address with escaped credentials.
 func escapeMirrorCredentials(addr string) string {
 	start, end, found := findPasswordInMirrorAddress(addr)
@@ -191,7 +197,7 @@ func (m *Mirror) runSync() bool {
 	// Do a fast-fail testing against on repository URL to ensure it is accessible under
 	// good condition to prevent long blocking on URL resolution without syncing anything.
 	if !git.IsRepoURLAccessible(git.NetworkOptions{
-		URL:     m.FullAddress(),
+		URL:     m.RawAddress(),
 		Timeout: 10 * time.Second,
 	}) {
 		desc := fmt.Sprintf("Source URL of mirror repository '%s' is not accessible: %s", m.Repo.FullName(), m.MosaicsAddress())

+ 1 - 1
routers/api/v1/repo/repo.go

@@ -270,7 +270,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
 				log.Error(4, "DeleteRepository: %v", errDelete)
 			}
 		}
-		ctx.Error(500, "MigrateRepository", models.HandleCloneUserCredentials(err.Error(), true))
+		ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
 		return
 	}
 

+ 0 - 1
routers/repo/http.go

@@ -111,7 +111,6 @@ func HTTPContexter() macaron.Handler {
 			askCredentials(c, http.StatusUnauthorized, "")
 			return
 		}
-		fmt.Println(authUsername, authPassword)
 
 		authUser, err := models.UserSignIn(authUsername, authPassword)
 		if err != nil && !errors.IsUserNotExist(err) {

+ 2 - 2
routers/repo/repo.go

@@ -217,11 +217,11 @@ func MigratePost(ctx *context.Context, f form.MigrateRepo) {
 	if strings.Contains(err.Error(), "Authentication failed") ||
 		strings.Contains(err.Error(), "could not read Username") {
 		ctx.Data["Err_Auth"] = true
-		ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &f)
+		ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleMirrorCredentials(err.Error(), true)), MIGRATE, &f)
 		return
 	} else if strings.Contains(err.Error(), "fatal:") {
 		ctx.Data["Err_CloneAddr"] = true
-		ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &f)
+		ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleMirrorCredentials(err.Error(), true)), MIGRATE, &f)
 		return
 	}