summaryrefslogtreecommitdiff
path: root/scripts/update-commits
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-09 09:13:59 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-09 09:13:59 -0500
commit2a6a04b6ae3e76effb995b167de7e52e85f0392e (patch)
tree24a9b926d802d839cb1364abac73d3982ba4eb27 /scripts/update-commits
parentfix element-desktop: firefox segfaults in nonguix electron (diff)
downloaddotfiles-guix-2a6a04b6ae3e76effb995b167de7e52e85f0392e.tar.gz
dotfiles-guix-2a6a04b6ae3e76effb995b167de7e52e85f0392e.tar.bz2
dotfiles-guix-2a6a04b6ae3e76effb995b167de7e52e85f0392e.zip
update commits, fix hyprland ambiguous, fix `update-commits` script to get timestamps correctly
Diffstat (limited to '')
-rwxr-xr-xscripts/update-commits73
1 files changed, 40 insertions, 33 deletions
diff --git a/scripts/update-commits b/scripts/update-commits
index 9302dcb..15e38b1 100755
--- a/scripts/update-commits
+++ b/scripts/update-commits
@@ -82,12 +82,24 @@
(invoke "git" "ls-remote" git-url "HEAD")
#\tab)))
-(define (commit-timestamp git-url commit)
- ; get the unix timestamp of a <commit> in git repo <git-url>
- (let* ((dir (git-checkout git-url))
- (timestamp
- (invoke "git" "-C" dir "show" "--quiet" "--format=%at" commit)))
- (string->number (string-trim-both timestamp #\newline))))
+(define (git-rev-list git-url local-commit remote-commit)
+ ;; get how many commits ahead the remote commit is
+ ;; from the current local commit
+ ;; - returns 0 if remote-commit is the same or older
+ (if (and (string? local-commit)
+ (string? remote-commit))
+ (let* ((dir (git-checkout git-url))
+ (timestamp
+ ;; git rev-list counts #commits
+ ;; - returns zero if commits out of order (remote older)
+ (invoke "git" "-C" dir "rev-list" "--count"
+ (string-append local-commit
+ ".."
+ remote-commit))))
+ (string->number (string-trim-both timestamp #\newline)))
+ ;; return zero of one of the commit
+ ;; hashes provided is invalid
+ 0))
;;
;; core functions
@@ -109,23 +121,18 @@
(fold (lambda (local-repo commits)
(let* ((repo-id (car local-repo))
(git-url (cadr local-repo))
- ; local
(local-commit (caddr local-repo))
- (local-timestamp (commit-timestamp git-url local-commit))
- ; remote
(remote-commit (assoc-ref remote-commits repo-id))
- (remote-timestamp (if (string? remote-commit)
- (commit-timestamp git-url remote-commit)))
- ; newest
- (newest-commit (if (and (number? remote-timestamp)
- (> remote-timestamp local-timestamp))
- remote-commit))
- ; result
- (result (if (string? newest-commit)
- (cons (list repo-id local-commit newest-commit)
- commits)
- commits)))
- result))
+ (commit-diff (git-rev-list git-url
+ local-commit
+ remote-commit)))
+ ;; dont append these commits to the updated
+ ;; merge list if the remote-commit is not better then
+ ;; what we already have locally
+ (if (> commit-diff 0)
+ (cons (list repo-id local-commit remote-commit)
+ commits)
+ commits)))
'()
local-commits))
@@ -145,7 +152,8 @@
remote-commit)))
(read-file path)
commits)))
- (write-file path result)))
+ (write-file path result)
+ (length commits)))
;;
;; guix functions
@@ -254,15 +262,14 @@
(define %nix-remote-commits
(nix-remote-commits %nix-local-commits))
-(update-file
- %guix-local-commits
- %guix-remote-commits
- %guix-channels-file)
+(if (> (update-file
+ %guix-local-commits
+ %guix-remote-commits
+ %guix-channels-file) 0)
+ (system* "guix-retry" "guix" "pull" "-C" %guix-channels-file))
-(update-file
- %nix-local-commits
- %nix-remote-commits
- %nix-flake-file)
-
-(system* "guix" "pull" "-C" %guix-channels-file)
-(system* "nix" "flake" "lock" (dirname %nix-flake-file))
+(if (> (update-file
+ %nix-local-commits
+ %nix-remote-commits
+ %nix-flake-file) 0)
+ (system* "nix" "flake" "lock" (dirname %nix-flake-file)))