From c098c11be8eb9e0c12be42640721e3cb21c37628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 20 May 2020 13:01:26 +0200 Subject: git: Add 'commit-relation'. * guix/git.scm (commit-relation): New procedure. * tests/git.scm ("commit-relation"): New test. --- guix/git.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'guix/git.scm') 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. -- cgit v1.2.3