aboutsummaryrefslogtreecommitdiff
path: root/pearl.el
diff options
context:
space:
mode:
Diffstat (limited to 'pearl.el')
-rw-r--r--pearl.el34
1 files changed, 20 insertions, 14 deletions
diff --git a/pearl.el b/pearl.el
index e78123b..f148992 100644
--- a/pearl.el
+++ b/pearl.el
@@ -3246,6 +3246,15 @@ is nil or a symbol detailing a non-success outcome (`fetch-failed',
:label (plist-get spec :label)
:message (pearl--save-outcome-detail (plist-get spec :label) status reason)))
+(defun pearl--marker-live-p (marker)
+ "Non-nil if MARKER is nil, or points into a still-live buffer.
+A nil MARKER (synthetic callers with no buffer) passes; a marker into a killed
+buffer fails. Guards async commit callbacks that touch the buffer after a push
+the buffer may not have survived."
+ (or (null marker)
+ (let ((buffer (marker-buffer marker)))
+ (and buffer (buffer-live-p buffer)))))
+
(defun pearl--save-field-push (spec text callback)
"Push TEXT for SPEC, advancing the provenance hash on success.
CALLBACK gets a `pushed' outcome after any :after-push bookkeeping runs, or a
@@ -3255,10 +3264,14 @@ CALLBACK gets a `pushed' outcome after any :after-push bookkeeping runs, or a
(lambda (result)
(if (plist-get result :success)
(progn
- (org-entry-put marker (plist-get spec :prop)
- (secure-hash 'sha256 text))
- (when (plist-get spec :after-push)
- (funcall (plist-get spec :after-push) result marker))
+ ;; The push can land after the buffer was killed; only run
+ ;; the buffer-touching bookkeeping when it's still live, but
+ ;; still report the remote success.
+ (when (pearl--marker-live-p marker)
+ (org-entry-put marker (plist-get spec :prop)
+ (secure-hash 'sha256 text))
+ (when (plist-get spec :after-push)
+ (funcall (plist-get spec :after-push) result marker)))
(funcall callback (pearl--save-outcome spec 'pushed nil)))
(funcall callback (pearl--save-outcome spec 'failed 'push-failed)))))))
@@ -3330,7 +3343,9 @@ used by the local dirty scan), so the next scan sees the ticket as clean."
(lambda (outcome)
;; A push or use-remote leaves the buffer body current; resync the Org
;; hash from it so the lossless local scan agrees with the markdown one.
- (when (memq (plist-get outcome :status) '(pushed resolved-remote))
+ ;; Skip when the buffer was killed before this async callback fired.
+ (when (and (memq (plist-get outcome :status) '(pushed resolved-remote))
+ (pearl--marker-live-p marker))
(org-with-point-at marker
(org-entry-put marker "LINEAR-DESC-ORG-SHA256"
(secure-hash 'sha256 (pearl--entry-body-at-point)))))
@@ -3447,15 +3462,6 @@ Surface BUFFER when any field pushed. The shared close-out for
(message "%s: %s" label (pearl--save-summary-message outcomes))
(when pushed (pearl--surface-buffer buffer))))
-(defun pearl--marker-live-p (marker)
- "Non-nil if MARKER is nil, or points into a still-live buffer.
-A nil MARKER (synthetic callers with no buffer) passes; a marker into a killed
-buffer fails. Guards async commit callbacks that touch the buffer after a push
-the buffer may not have survived."
- (or (null marker)
- (let ((buffer (marker-buffer marker)))
- (and buffer (buffer-live-p buffer)))))
-
(defun pearl--run-atomic-field-save (spec callback)
"Save one atomic (enum/relation) field per SPEC, calling CALLBACK once.
SPEC keys: :issue-id :identifier :field :marker :label; :live and :baseline