aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-07-08 00:41:19 +0100
committerGitHub <noreply@github.com>2023-07-08 00:41:19 +0100
commit7e143ceb36ed6d46462f3c37f07993f9a10f91e3 (patch)
tree8b6d76278f0a5020fc7fc675908abc29e2a8025d /plumbing/object/commit.go
parentdd4e2b7f4b01e2aaafcf182d2884a186a6f37d21 (diff)
parente0fc8a8f00c238f7f7cdf0e0c59e743550587bdf (diff)
downloadgo-git-7e143ceb36ed6d46462f3c37f07993f9a10f91e3.tar.gz
Merge pull request #789 from AriehSchneier/rewrite-blame
plumbing: blame, Complete rewrite. Fixes #603
Diffstat (limited to 'plumbing/object/commit.go')
-rw-r--r--plumbing/object/commit.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go
index d2f7184..8a0f35c 100644
--- a/plumbing/object/commit.go
+++ b/plumbing/object/commit.go
@@ -376,6 +376,17 @@ func (c *Commit) Verify(armoredKeyRing string) (*openpgp.Entity, error) {
return openpgp.CheckArmoredDetachedSignature(keyring, er, signature, nil)
}
+// Less defines a compare function to determine which commit is 'earlier' by:
+// - First use Committer.When
+// - If Committer.When are equal then use Author.When
+// - If Author.When also equal then compare the string value of the hash
+func (c *Commit) Less(rhs *Commit) bool {
+ return c.Committer.When.Before(rhs.Committer.When) ||
+ (c.Committer.When.Equal(rhs.Committer.When) &&
+ (c.Author.When.Before(rhs.Author.When) ||
+ (c.Author.When.Equal(rhs.Author.When) && bytes.Compare(c.Hash[:], rhs.Hash[:]) < 0)))
+}
+
func indent(t string) string {
var output []string
for _, line := range strings.Split(t, "\n") {