summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-20 13:01:26 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-25 00:00:28 +0200
commitc098c11be8eb9e0c12be42640721e3cb21c37628 (patch)
tree7a1f98c34719f61c404f8fe4ff6b17a5ae2edbc7 /guix
parent86ac14b2f37efbb6f4a3ed1c3e183fbc9496b7a5 (diff)
downloadpatches-c098c11be8eb9e0c12be42640721e3cb21c37628.tar
patches-c098c11be8eb9e0c12be42640721e3cb21c37628.tar.gz
git: Add 'commit-relation'.
* guix/git.scm (commit-relation): New procedure. * tests/git.scm ("commit-relation"): New test.
Diffstat (limited to 'guix')
-rw-r--r--guix/git.scm16
1 files changed, 16 insertions, 0 deletions
diff --git a/guix/git.scm b/guix/git.scm
index 92121156cf..249d622756 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -43,6 +43,7 @@
url+commit->name
latest-repository-commit
commit-difference
+ commit-relation
git-checkout
git-checkout?
@@ -405,6 +406,21 @@ that of OLD."
(cons head result)
(set-insert head visited)))))))
+(define (commit-relation old new)
+ "Return a symbol denoting the relation between OLD and NEW, two commit
+objects: 'ancestor (meaning that OLD is an ancestor of NEW), 'descendant, or
+'unrelated, or 'self (OLD and NEW are the same commit)."
+ (if (eq? old new)
+ 'self
+ (let ((newest (commit-closure new)))
+ (if (set-contains? newest old)
+ 'ancestor
+ (let* ((seen (list->setq (commit-parents new)))
+ (oldest (commit-closure old seen)))
+ (if (set-contains? oldest new)
+ 'descendant
+ 'unrelated))))))
+
;;;
;;; Checkouts.