rename private functions and variables

This commit is contained in:
Tim Schubert 2022-06-02 21:12:39 +02:00
parent 1792848028
commit 8deec15978
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA

32
main.go
View file

@ -22,23 +22,23 @@ import (
) )
const ( const (
DefaultRemoteName = "origin" defaultRemoteName = "origin"
) )
var ( var (
NothingToDo = errors.New("Nothing to do for unmodified file") nothingToDo = errors.New("Nothing to do for unmodified file")
) )
var Commitmu sync.Mutex var cm sync.Mutex
func Commit( func commit(
tree *git.Worktree, tree *git.Worktree,
padfile string, padfile string,
url string, url string,
) (plumbing.Hash, error) { ) (plumbing.Hash, error) {
Commitmu.Lock() cm.Lock()
defer Commitmu.Unlock() defer cm.Unlock()
if _, err := tree.Add(padfile); err != nil { if _, err := tree.Add(padfile); err != nil {
return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err) return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err)
@ -51,7 +51,7 @@ func Commit(
fileStatus := status.File(padfile) fileStatus := status.File(padfile)
if fileStatus.Staging != git.Added && fileStatus.Staging != git.Modified { if fileStatus.Staging != git.Added && fileStatus.Staging != git.Modified {
return plumbing.ZeroHash, NothingToDo return plumbing.ZeroHash, nothingToDo
} }
commit, err := tree.Commit( commit, err := tree.Commit(
@ -73,7 +73,7 @@ func Commit(
return commit, nil return commit, nil
} }
func Download( func download(
gitdir string, gitdir string,
url string, url string,
) (string, error) { ) (string, error) {
@ -102,7 +102,7 @@ func Download(
} }
func Push( func push(
auth *githttp.BasicAuth, auth *githttp.BasicAuth,
r *git.Repository, r *git.Repository,
remote *string, remote *string,
@ -126,7 +126,7 @@ func main() {
cwd, cwd,
"git directory", "git directory",
) )
push := flag.Bool( doPush := flag.Bool(
"push", "push",
false, false,
"push repository to remote", "push repository to remote",
@ -143,7 +143,7 @@ func main() {
) )
remote := flag.String( remote := flag.String(
"remote", "remote",
DefaultRemoteName, defaultRemoteName,
"remote", "remote",
) )
@ -171,15 +171,15 @@ func main() {
go func() { go func() {
defer wg.Done() defer wg.Done()
padfile, err := Download(filesystemRoot, padurl) padfile, err := download(filesystemRoot, padurl)
if err != nil { if err != nil {
log.Printf("%s", err) log.Printf("%s", err)
return return
} }
log.Printf("Downloaded %s", padurl) log.Printf("Downloaded %s", padurl)
if _, err := Commit(tree, padfile, padurl); err != nil { if _, err := commit(tree, padfile, padurl); err != nil {
if err == NothingToDo { if err == nothingToDo {
log.Printf("Nothing to do for %s", padfile) log.Printf("Nothing to do for %s", padfile)
} else { } else {
log.Printf("%s", err) log.Printf("%s", err)
@ -196,8 +196,8 @@ func main() {
Password: *password, Password: *password,
} }
if *push == true { if *doPush == true {
if err := Push(auth, repo, remote); err != nil { if err := push(auth, repo, remote); err != nil {
if err == git.NoErrAlreadyUpToDate { if err == git.NoErrAlreadyUpToDate {
log.Println("Already up-to-date") log.Println("Already up-to-date")
} else { } else {