diff options
author | Michael Muré <batolettre@gmail.com> | 2020-07-01 19:39:02 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-07-01 19:39:02 +0200 |
commit | 3cf31fc4049fefc82db0a3d2018b5d98ab77c5d7 (patch) | |
tree | c77a29e1f35fefa5040454976c6edcf86e7678bc /repository/git.go | |
parent | 33d510ac3999b3d8fa7a4652dc44a21c713f97de (diff) | |
download | git-bug-3cf31fc4049fefc82db0a3d2018b5d98ab77c5d7.tar.gz |
repository: merge git.Hash in for one less /util package
Diffstat (limited to 'repository/git.go')
-rw-r--r-- | repository/git.go | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/repository/git.go b/repository/git.go index 83037307..22055dbb 100644 --- a/repository/git.go +++ b/repository/git.go @@ -10,7 +10,6 @@ import ( "strings" "sync" - "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/lamport" ) @@ -218,16 +217,16 @@ func (repo *GitRepo) PushRefs(remote string, refSpec string) (string, error) { } // StoreData will store arbitrary data and return the corresponding hash -func (repo *GitRepo) StoreData(data []byte) (git.Hash, error) { +func (repo *GitRepo) StoreData(data []byte) (Hash, error) { var stdin = bytes.NewReader(data) stdout, err := repo.runGitCommandWithStdin(stdin, "hash-object", "--stdin", "-w") - return git.Hash(stdout), err + return Hash(stdout), err } // ReadData will attempt to read arbitrary data from the given hash -func (repo *GitRepo) ReadData(hash git.Hash) ([]byte, error) { +func (repo *GitRepo) ReadData(hash Hash) ([]byte, error) { var stdout bytes.Buffer var stderr bytes.Buffer @@ -241,7 +240,7 @@ func (repo *GitRepo) ReadData(hash git.Hash) ([]byte, error) { } // StoreTree will store a mapping key-->Hash as a Git tree -func (repo *GitRepo) StoreTree(entries []TreeEntry) (git.Hash, error) { +func (repo *GitRepo) StoreTree(entries []TreeEntry) (Hash, error) { buffer := prepareTreeEntries(entries) stdout, err := repo.runGitCommandWithStdin(&buffer, "mktree") @@ -250,22 +249,22 @@ func (repo *GitRepo) StoreTree(entries []TreeEntry) (git.Hash, error) { return "", err } - return git.Hash(stdout), nil + return Hash(stdout), nil } // StoreCommit will store a Git commit with the given Git tree -func (repo *GitRepo) StoreCommit(treeHash git.Hash) (git.Hash, error) { +func (repo *GitRepo) StoreCommit(treeHash Hash) (Hash, error) { stdout, err := repo.runGitCommand("commit-tree", string(treeHash)) if err != nil { return "", err } - return git.Hash(stdout), nil + return Hash(stdout), nil } // StoreCommitWithParent will store a Git commit with the given Git tree -func (repo *GitRepo) StoreCommitWithParent(treeHash git.Hash, parent git.Hash) (git.Hash, error) { +func (repo *GitRepo) StoreCommitWithParent(treeHash Hash, parent Hash) (Hash, error) { stdout, err := repo.runGitCommand("commit-tree", string(treeHash), "-p", string(parent)) @@ -273,11 +272,11 @@ func (repo *GitRepo) StoreCommitWithParent(treeHash git.Hash, parent git.Hash) ( return "", err } - return git.Hash(stdout), nil + return Hash(stdout), nil } // UpdateRef will create or update a Git reference -func (repo *GitRepo) UpdateRef(ref string, hash git.Hash) error { +func (repo *GitRepo) UpdateRef(ref string, hash Hash) error { _, err := repo.runGitCommand("update-ref", ref, string(hash)) return err @@ -319,7 +318,7 @@ func (repo *GitRepo) CopyRef(source string, dest string) error { } // ListCommits will return the list of commit hashes of a ref, in chronological order -func (repo *GitRepo) ListCommits(ref string) ([]git.Hash, error) { +func (repo *GitRepo) ListCommits(ref string) ([]Hash, error) { stdout, err := repo.runGitCommand("rev-list", "--first-parent", "--reverse", ref) if err != nil { @@ -328,9 +327,9 @@ func (repo *GitRepo) ListCommits(ref string) ([]git.Hash, error) { split := strings.Split(stdout, "\n") - casted := make([]git.Hash, len(split)) + casted := make([]Hash, len(split)) for i, line := range split { - casted[i] = git.Hash(line) + casted[i] = Hash(line) } return casted, nil @@ -338,7 +337,7 @@ func (repo *GitRepo) ListCommits(ref string) ([]git.Hash, error) { } // ReadTree will return the list of entries in a Git tree -func (repo *GitRepo) ReadTree(hash git.Hash) ([]TreeEntry, error) { +func (repo *GitRepo) ReadTree(hash Hash) ([]TreeEntry, error) { stdout, err := repo.runGitCommand("ls-tree", string(hash)) if err != nil { @@ -349,25 +348,25 @@ func (repo *GitRepo) ReadTree(hash git.Hash) ([]TreeEntry, error) { } // FindCommonAncestor will return the last common ancestor of two chain of commit -func (repo *GitRepo) FindCommonAncestor(hash1 git.Hash, hash2 git.Hash) (git.Hash, error) { +func (repo *GitRepo) FindCommonAncestor(hash1 Hash, hash2 Hash) (Hash, error) { stdout, err := repo.runGitCommand("merge-base", string(hash1), string(hash2)) if err != nil { return "", err } - return git.Hash(stdout), nil + return Hash(stdout), nil } // GetTreeHash return the git tree hash referenced in a commit -func (repo *GitRepo) GetTreeHash(commit git.Hash) (git.Hash, error) { +func (repo *GitRepo) GetTreeHash(commit Hash) (Hash, error) { stdout, err := repo.runGitCommand("rev-parse", string(commit)+"^{tree}") if err != nil { return "", err } - return git.Hash(stdout), nil + return Hash(stdout), nil } // GetOrCreateClock return a Lamport clock stored in the Repo. |