Browse Source

#3233 code cleanup and minor issue fix

pull/3436/head
Unknwon 8 years ago
parent
commit
5077408d78
  1. 2
      .gopmfile
  2. 2
      README.md
  3. 2
      cmd/web.go
  4. 2
      glide.lock
  5. 2
      gogs.go
  6. 115
      models/repo.go
  7. 2
      models/wiki.go
  8. 1
      modules/context/repo.go
  9. 2
      templates/.VERSION
  10. 2
      templates/repo/wiki/start.tmpl
  11. 2
      templates/repo/wiki/view.tmpl

2
.gopmfile

@ -18,7 +18,7 @@ github.com/go-xorm/core = commit:5bf745d
github.com/go-xorm/xorm = commit:c6c7056 github.com/go-xorm/xorm = commit:c6c7056
github.com/gogits/chardet = commit:2404f77 github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:7f3990a github.com/gogits/cron = commit:7f3990a
github.com/gogits/git-module = commit:18dd87d github.com/gogits/git-module = commit:efc90b5
github.com/gogits/go-gogs-client = commit:d1020b4 github.com/gogits/go-gogs-client = commit:d1020b4
github.com/issue9/identicon = commit:d36b545 github.com/issue9/identicon = commit:d36b545
github.com/jaytaylor/html2text = commit:52d9b78 github.com/jaytaylor/html2text = commit:52d9b78

2
README.md

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.72 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) ##### Current tip version: 0.9.73 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

2
cmd/web.go

@ -87,7 +87,7 @@ func checkVersion() {
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, {"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/ini.v1", ini.Version, "1.8.4"},
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, {"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
{"github.com/gogits/git-module", git.Version, "0.3.4"}, {"github.com/gogits/git-module", git.Version, "0.3.5"},
{"github.com/gogits/go-gogs-client", gogs.Version, "0.10.3"}, {"github.com/gogits/go-gogs-client", gogs.Version, "0.10.3"},
} }
for _, c := range checkers { for _, c := range checkers {

2
glide.lock generated

@ -41,7 +41,7 @@ imports:
- name: github.com/gogits/cron - name: github.com/gogits/cron
version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c
- name: github.com/gogits/git-module - name: github.com/gogits/git-module
version: 18dd87dc5eac9ee7076133c8363803f2192d5713 version: efc90b5ea1f7b7e404673dcc19674b2a6856e0d3
- name: github.com/gogits/go-gogs-client - name: github.com/gogits/go-gogs-client
version: d1020b4da5474f7533f5b11084dcfd5536cf2e71 version: d1020b4da5474f7533f5b11084dcfd5536cf2e71
- name: github.com/issue9/identicon - name: github.com/issue9/identicon

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.72.0811" const APP_VER = "0.9.73.0811"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

115
models/repo.go

@ -659,47 +659,21 @@ type MigrateRepoOptions struct {
RemoteAddr string RemoteAddr string
} }
func isGitRepoURL(repoURL string, timeout time.Duration) bool { /*
cmd := git.NewCommand("ls-remote") GitHub, GitLab, Gogs: *.wiki.git
cmd.AddArguments("-q", "-h", repoURL, "HEAD") BitBucket: *.git/wiki
res, err := cmd.RunTimeout(timeout) */
if err != nil { var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
return false
} // wikiRemoteURL returns accessible repository URL for wiki if exists.
if strings.Contains(res, "fatal") || strings.Contains(res, "not found") { // Otherwise, it returns an empty string.
return false func wikiRemoteURL(remote string) string {
} remote = strings.TrimSuffix(remote, ".git")
return true for _, suffix := range commonWikiURLSuffixes {
} wikiURL := remote + suffix
if git.IsRepoURLAccessible(wikiURL) {
func wikiRemoteURL(remote string, timeout time.Duration) string { return wikiURL
wikiRemoteStd := remote
wikiRemoteBitBucket := remote
/*
GitHub, GitLab, Gogs: NAME.wiki.git
BitBucket: NAME.git/wiki
*/
gitSuffixed := strings.HasSuffix(remote, ".git")
if gitSuffixed {
wikiRemoteStd = wikiRemoteStd[:len(wikiRemoteStd)-4]
wikiRemoteBitBucket += "/wiki"
} else {
wikiRemoteBitBucket += ".git/wiki"
}
wikiRemoteStd += ".wiki.git"
isBB := strings.Contains(remote, "bitbucket")
if isBB {
if isGitRepoURL(wikiRemoteBitBucket, timeout) {
return wikiRemoteBitBucket
} else if isGitRepoURL(wikiRemoteStd, timeout) {
return wikiRemoteStd
} }
return ""
}
if isGitRepoURL(wikiRemoteStd, timeout) {
return wikiRemoteStd
} else if isGitRepoURL(wikiRemoteBitBucket, timeout) {
return wikiRemoteBitBucket
} }
return "" return ""
} }
@ -733,25 +707,26 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
repo.NumWatches = 1 repo.NumWatches = 1
} }
gitTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
os.RemoveAll(repoPath) os.RemoveAll(repoPath)
if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{ if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
Mirror: true, Mirror: true,
Quiet: true, Quiet: true,
Timeout: gitTimeout, Timeout: migrateTimeout,
}); err != nil { }); err != nil {
return repo, fmt.Errorf("Clone: %v", err) return repo, fmt.Errorf("Clone: %v", err)
} }
wikiRemotePath := wikiRemoteURL(opts.RemoteAddr, gitTimeout) wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
if wikiRemotePath != "" { if len(wikiRemotePath) > 0 {
os.RemoveAll(wikiPath) os.RemoveAll(wikiPath)
if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{ if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
Mirror: true, Mirror: true,
Quiet: true, Quiet: true,
Timeout: gitTimeout, Timeout: migrateTimeout,
}); err != nil { }); err != nil {
log.Info("Clone wiki failed: %v", err) log.Info("Clone wiki: %v", err)
} }
} }
@ -797,40 +772,38 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
return CleanUpMigrateInfo(repo) return CleanUpMigrateInfo(repo)
} }
// Finish migrating repository with things that don't need to be done for mirrors. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
// This also removes possible user credentials.
func cleanUpMigrateGitConfig(configPath string) error {
cfg, err := ini.Load(configPath)
if err != nil {
return fmt.Errorf("open config file: %v", err)
}
cfg.DeleteSection("remote \"origin\"")
if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
return fmt.Errorf("save config file: %v", err)
}
return nil
}
// Finish migrating repository and/or wiki with things that don't need to be done for mirrors.
func CleanUpMigrateInfo(repo *Repository) (*Repository, error) { func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
repoPath := repo.RepoPath() repoPath := repo.RepoPath()
hasWiki := repo.HasWiki()
if err := createUpdateHook(repoPath); err != nil { if err := createUpdateHook(repoPath); err != nil {
return repo, fmt.Errorf("createUpdateHook: %v", err) return repo, fmt.Errorf("createUpdateHook: %v", err)
} }
if hasWiki { if repo.HasWiki() {
if err := createUpdateHook(repoPath); err != nil { if err := createUpdateHook(repo.WikiPath()); err != nil {
return repo, fmt.Errorf("createUpdateHook: %v", err) return repo, fmt.Errorf("createUpdateHook (wiki): %v", err)
} }
} }
// Clean up mirror info which prevents "push --all". if err := cleanUpMigrateGitConfig(repo.GitConfigPath()); err != nil {
// This also removes possible user credentials. return repo, fmt.Errorf("cleanUpMigrateGitConfig: %v", err)
configPath := repo.GitConfigPath()
cfg, err := ini.Load(configPath)
if err != nil {
return repo, fmt.Errorf("open config file: %v", err)
}
cfg.DeleteSection("remote \"origin\"")
if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
return repo, fmt.Errorf("save config file: %v", err)
} }
if hasWiki { if repo.HasWiki() {
wikiConfigPath := filepath.Join(repo.WikiPath(), "config") if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
cfg, err = ini.Load(wikiConfigPath) return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
if err != nil {
return repo, fmt.Errorf("open wiki config file: %v", err)
}
cfg.DeleteSection("remote \"origin\"")
if err = cfg.SaveToIndent(wikiConfigPath, "\t"); err != nil {
return repo, fmt.Errorf("save wiki config file: %v", err)
} }
} }

2
models/wiki.go

@ -105,6 +105,8 @@ func (repo *Repository) InitWiki() error {
if err := git.InitRepository(repo.WikiPath(), true); err != nil { if err := git.InitRepository(repo.WikiPath(), true); err != nil {
return fmt.Errorf("InitRepository: %v", err) return fmt.Errorf("InitRepository: %v", err)
} else if err = createUpdateHook(repo.WikiPath()); err != nil {
return fmt.Errorf("createUpdateHook: %v", err)
} }
return nil return nil
} }

1
modules/context/repo.go

@ -223,7 +223,6 @@ func RepoAssignment(args ...bool) macaron.Handler {
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner() ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin() ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter() ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter()
ctx.Data["IsRepositoryMirror"] = repo.IsMirror
ctx.Data["DisableSSH"] = setting.SSH.Disabled ctx.Data["DisableSSH"] = setting.SSH.Disabled
ctx.Data["CloneLink"] = repo.CloneLink() ctx.Data["CloneLink"] = repo.CloneLink()

2
templates/.VERSION

@ -1 +1 @@
0.9.72.0811 0.9.73.0811

2
templates/repo/wiki/start.tmpl

@ -6,7 +6,7 @@
<span class="mega-octicon octicon-book"></span> <span class="mega-octicon octicon-book"></span>
<h2>{{.i18n.Tr "repo.wiki.welcome"}}</h2> <h2>{{.i18n.Tr "repo.wiki.welcome"}}</h2>
<p>{{.i18n.Tr "repo.wiki.welcome_desc"}}</p> <p>{{.i18n.Tr "repo.wiki.welcome_desc"}}</p>
{{if and .IsRepositoryWriter (not .IsRepositoryMirror)}} {{if and .IsRepositoryWriter (not .Repository.IsMirror)}}
<a class="ui green button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.create_first_page"}}</a> <a class="ui green button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.create_first_page"}}</a>
{{end}} {{end}}
</div> </div>

2
templates/repo/wiki/view.tmpl

@ -46,7 +46,7 @@
</div> </div>
<div class="ui dividing header"> <div class="ui dividing header">
{{.title}} {{.title}}
{{if and .IsRepositoryWriter (not .IsRepositoryMirror)}} {{if and .IsRepositoryWriter (not .Repository.IsMirror)}}
<div class="ui right"> <div class="ui right">
<a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}/_edit">{{.i18n.Tr "repo.wiki.edit_page_button"}}</a> <a class="ui small button" href="{{.RepoLink}}/wiki/{{.PageURL}}/_edit">{{.i18n.Tr "repo.wiki.edit_page_button"}}</a>
<a class="ui green small button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.new_page_button"}}</a> <a class="ui green small button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.new_page_button"}}</a>

Loading…
Cancel
Save