浏览代码

Better upload commit performance

Two major changes:
1. Replace 'git add' with 'git annex add'
  This generally has faster performance.  I'm not 100% certain why but
  it's definitely related to how git-annex sets up and uses smudge
  filters.  Asking git-annex to check files in only sends files to git
  when they are not going to be annex and so it doesn't need to run the
  smudge filter on all the files.
2. Replace 'git annex sync' with 'git annex copy'
  When running 'git annex sync --content' it would download and upload
  all content.  Downloading is unnecessary when adding new files.
  We still run a 'git annex sync' (without --content) to synchronise
  repository information, which is required before upload since the
  local clone is new.
Achilleas Koutsou 5 年之前
父节点
当前提交
bd9af71768
共有 2 个文件被更改,包括 28 次插入4 次删除
  1. 24 0
      internal/db/models_gin.go
  2. 4 4
      internal/db/repo_editor.go

+ 24 - 0
internal/db/models_gin.go

@@ -8,6 +8,7 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"strings"
 	"strings"
 
 
+	"github.com/G-Node/git-module"
 	"github.com/G-Node/gogs/internal/setting"
 	"github.com/G-Node/gogs/internal/setting"
 	"github.com/G-Node/libgin/libgin"
 	"github.com/G-Node/libgin/libgin"
 	"github.com/G-Node/libgin/libgin/annex"
 	"github.com/G-Node/libgin/libgin/annex"
@@ -145,3 +146,26 @@ func annexSync(path string) error {
 	}
 	}
 	return nil
 	return nil
 }
 }
+
+func annexAdd(repoPath string, all bool, files ...string) error {
+	cmd := git.NewCommand("annex", "add")
+	if all {
+		cmd.AddArguments(".")
+	}
+	_, err := cmd.AddArguments(files...).RunInDir(repoPath)
+	return err
+}
+
+func annexUpload(repoPath, remote string) error {
+	log.Trace("Synchronising annex info")
+	if msg, err := git.NewCommand("annex", "sync").RunInDir(repoPath); err != nil {
+		log.Error(2, "git-annex sync failed: %v (%s)", err, msg)
+	}
+	log.Trace("Uploading annexed data")
+	cmd := git.NewCommand("annex", "copy", fmt.Sprintf("--to=%s", remote), "--all")
+	if msg, err := cmd.RunInDir(repoPath); err != nil {
+		log.Error(2, "git-annex copy failed: %v (%s)", err, msg)
+		return fmt.Errorf("git annex copy [%s]", repoPath)
+	}
+	return nil
+}

+ 4 - 4
internal/db/repo_editor.go

@@ -502,8 +502,8 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 	}
 	}
 
 
 	annexSetup(localPath) // Initialise annex and set configuration (with add filter for filesizes)
 	annexSetup(localPath) // Initialise annex and set configuration (with add filter for filesizes)
-	if err = git.AddChanges(localPath, true); err != nil {
-		return fmt.Errorf("git add --all: %v", err)
+	if err = annexAdd(localPath, true); err != nil {
+		return fmt.Errorf("git annex add: %v", err)
 	} else if err = git.CommitChanges(localPath, git.CommitChangesOptions{
 	} else if err = git.CommitChanges(localPath, git.CommitChangesOptions{
 		Committer: doer.NewGitSig(),
 		Committer: doer.NewGitSig(),
 		Message:   opts.Message,
 		Message:   opts.Message,
@@ -521,8 +521,8 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 		return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
 		return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
 	}
 	}
 
 
-	if err := annexSync(localPath); err != nil { // Run full annex sync
-		return fmt.Errorf("annex sync %s: %v", localPath, err)
+	if err := annexUpload(localPath, "origin"); err != nil { // Copy new files
+		return fmt.Errorf("annex copy %s: %v", localPath, err)
 	}
 	}
 	annexUninit(localPath) // Uninitialise annex to prepare for deletion
 	annexUninit(localPath) // Uninitialise annex to prepare for deletion
 	StartIndexing(*repo)   // Index the new data
 	StartIndexing(*repo)   // Index the new data