From 1b9d278cc9d8e62f76bc343373023e0a17246406 Mon Sep 17 00:00:00 2001 From: Tillie Kottmann Date: Sat, 31 Oct 2020 12:06:54 +0100 Subject: [PATCH] Do some minor clean up --- pkg/goop/clone.go | 73 ++-------------------------------------------- pkg/goop/consts.go | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 pkg/goop/consts.go diff --git a/pkg/goop/clone.go b/pkg/goop/clone.go index 5cb2a2b..76622b6 100644 --- a/pkg/goop/clone.go +++ b/pkg/goop/clone.go @@ -19,87 +19,20 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "strings" "sync" "time" ) -const maxConcurrency = 60 - var c = &fasthttp.Client{ - MaxConnsPerHost: utils.MaxInt(maxConcurrency + 250, fasthttp.DefaultMaxConnsPerHost), + MaxConnsPerHost: utils.MaxInt(maxConcurrency+250, fasthttp.DefaultMaxConnsPerHost), TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, NoDefaultUserAgentHeader: true, - MaxConnWaitTimeout: 10 * time.Second, + MaxConnWaitTimeout: 10 * time.Second, } -var refPrefix = []byte{'r', 'e', 'f', ':'} -var ( - packRegex = regexp.MustCompile(`(?m)pack-([a-f0-9]{40})\.pack`) - objRegex = regexp.MustCompile(`(?m)(^|\s)([a-f0-9]{40})($|\s)`) -) -var ( - commonFiles = []string{ - ".gitignore", - ".gitattributes", - ".gitmodules", - ".env", - ".git/COMMIT_EDITMSG", - ".git/description", - ".git/hooks/applypatch-msg.sample", - ".git/hooks/applypatch-msg.sample", - ".git/hooks/applypatch-msg.sample", - ".git/hooks/commit-msg.sample", - ".git/hooks/post-commit.sample", - ".git/hooks/post-receive.sample", - ".git/hooks/post-update.sample", - ".git/hooks/pre-applypatch.sample", - ".git/hooks/pre-commit.sample", - ".git/hooks/pre-push.sample", - ".git/hooks/pre-rebase.sample", - ".git/hooks/pre-receive.sample", - ".git/hooks/prepare-commit-msg.sample", - ".git/hooks/update.sample", - ".git/index", - ".git/info/exclude", - ".git/objects/info/packs", - } - commonRefs = []string{ - ".git/FETCH_HEAD", - ".git/HEAD", - ".git/ORIG_HEAD", - ".git/config", - ".git/info/refs", - ".git/logs/HEAD", - ".git/logs/refs/heads/master", - ".git/logs/refs/heads/main", - ".git/logs/refs/heads/dev", - ".git/logs/refs/heads/develop", - ".git/logs/refs/remotes/origin/HEAD", - ".git/logs/refs/remotes/origin/master", - ".git/logs/refs/remotes/origin/main", - ".git/logs/refs/remotes/origin/dev", - ".git/logs/refs/remotes/origin/develop", - ".git/logs/refs/stash", - ".git/packed-refs", - ".git/refs/heads/master", - ".git/refs/heads/main", - ".git/refs/heads/dev", - ".git/refs/heads/develop", - ".git/refs/remotes/origin/HEAD", - ".git/refs/remotes/origin/master", - ".git/refs/remotes/origin/main", - ".git/refs/remotes/origin/dev", - ".git/refs/remotes/origin/develop", - ".git/refs/stash", - ".git/refs/wip/wtree/refs/heads/master", //Magit - ".git/refs/wip/index/refs/heads/master", //Magit - } -) - func Clone(u, dir string, force bool) error { baseUrl := strings.TrimSuffix(u, "/") baseUrl = strings.TrimSuffix(baseUrl, "/HEAD") @@ -293,10 +226,10 @@ func FetchGit(baseUrl, baseDir string) error { indexPath := utils.Url(baseDir, ".git/index") if utils.Exists(indexPath) { f, err := os.Open(indexPath) - defer f.Close() if err != nil { return err } + defer f.Close() var idx index.Index decoder := index.NewDecoder(f) if err := decoder.Decode(&idx); err != nil { diff --git a/pkg/goop/consts.go b/pkg/goop/consts.go new file mode 100644 index 0000000..3d7c08d --- /dev/null +++ b/pkg/goop/consts.go @@ -0,0 +1,69 @@ +package goop + +import "regexp" + +const maxConcurrency = 50 + +var refPrefix = []byte{'r', 'e', 'f', ':'} +var ( + packRegex = regexp.MustCompile(`(?m)pack-([a-f0-9]{40})\.pack`) + objRegex = regexp.MustCompile(`(?m)(^|\s)([a-f0-9]{40})($|\s)`) +) +var ( + commonFiles = []string{ + ".gitignore", + ".gitattributes", + ".gitmodules", + ".env", + ".git/COMMIT_EDITMSG", + ".git/description", + ".git/hooks/applypatch-msg.sample", + ".git/hooks/applypatch-msg.sample", + ".git/hooks/applypatch-msg.sample", + ".git/hooks/commit-msg.sample", + ".git/hooks/post-commit.sample", + ".git/hooks/post-receive.sample", + ".git/hooks/post-update.sample", + ".git/hooks/pre-applypatch.sample", + ".git/hooks/pre-commit.sample", + ".git/hooks/pre-push.sample", + ".git/hooks/pre-rebase.sample", + ".git/hooks/pre-receive.sample", + ".git/hooks/prepare-commit-msg.sample", + ".git/hooks/update.sample", + ".git/index", + ".git/info/exclude", + ".git/objects/info/packs", + } + commonRefs = []string{ + ".git/FETCH_HEAD", + ".git/HEAD", + ".git/ORIG_HEAD", + ".git/config", + ".git/info/refs", + ".git/logs/HEAD", + ".git/logs/refs/heads/master", + ".git/logs/refs/heads/main", + ".git/logs/refs/heads/dev", + ".git/logs/refs/heads/develop", + ".git/logs/refs/remotes/origin/HEAD", + ".git/logs/refs/remotes/origin/master", + ".git/logs/refs/remotes/origin/main", + ".git/logs/refs/remotes/origin/dev", + ".git/logs/refs/remotes/origin/develop", + ".git/logs/refs/stash", + ".git/packed-refs", + ".git/refs/heads/master", + ".git/refs/heads/main", + ".git/refs/heads/dev", + ".git/refs/heads/develop", + ".git/refs/remotes/origin/HEAD", + ".git/refs/remotes/origin/master", + ".git/refs/remotes/origin/main", + ".git/refs/remotes/origin/dev", + ".git/refs/remotes/origin/develop", + ".git/refs/stash", + ".git/refs/wip/wtree/refs/heads/master", //Magit + ".git/refs/wip/index/refs/heads/master", //Magit + } +) \ No newline at end of file