On 2024-06-14, Ihor Radchenko wrote:

> Jens Lechtenboerger <lech...@wi.uni-muenster.de> writes:
>
>> Jumping in here, I do not understand the publishing cache.  Some of
>> my org documents are re-published every time, while others are only
>> re-published after changes.  What is checked where?
>
> See "14.4 Triggering Publication" section of Org mode manual:
>
>        Org uses timestamps to track when a file has changed.  The above
>     functions normally only publish changed files.  You can override this
> [...]

I propose to change caching and checking of timestamps as in the
attached path.

Currently, org-publish-cache-file-needs-publishing checks whether
the source file was modified after the cached modification time,
which is fine.  However, for each included file B, it checks whether
that was modified more recently than the source file A.  If so, the
source is file A is considered to need publishing.  This does not
make sense.  File A will be published again and again, even if
neither A nor B changed since the last publishing.

In the patch, I store the current time in the publish cache, not the
source file’s modification time.  Also, for included files, I do not
check their timestamp against the one of the source file but against
the cached publish timestamp.

What do you think?

As an aside, recursive inclusions are currently not checked.
Maybe code to collect all included files is available elsewhere in
the code base?

Also, in my case, it would be useful to have a new keyword like
“#+PUBLISH_DEPENDENCY: some-file” to record timestamps for
additional dependencies, whose changes should also trigger
publishing.  Currently, that could be added as alternative to the
regexp for INCLUDE.  However, maybe you prefer to refactor that
code to deal with recursive inclusions?

Best wishes,
Jens

From 5f1c5d4e56afd91db85884df6018960f3639230b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jens=20Lechtenb=C3=B6rger?= <lech...@wi.uni-muenster.de>
Date: Mon, 12 Aug 2024 09:40:13 +0200
Subject: [PATCH] lisp/ox-publish.el: Use publish time in publish cache

* lisp/ox-publish.el (org-publish-update-timestamp): Store current
time in publish cache, instead of modification time of source file.
(org-publish-cache-file-needs-publishing): Return t, if source or an
included file was modified more recently.

Previously, a source file including a newer file was published again
and again.  Now, publishing only happens if either source or an
included file changed since the last publishing.
---
 lisp/ox-publish.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 9f943cedc..e26e2ca37 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -389,7 +389,7 @@ still decide about that independently."
   "Update publishing timestamp for file FILENAME.
 If there is no timestamp, create one."
   (let ((key (org-publish-timestamp-filename filename pub-dir pub-func))
-	(stamp (org-publish-cache-mtime-of-src filename)))
+	(stamp (current-time)))
     (org-publish-cache-set key stamp)))
 
 (defun org-publish-remove-all-timestamps ()
@@ -1286,9 +1286,10 @@ If FREE-CACHE, empty the cache."
 (defun org-publish-cache-file-needs-publishing
     (filename &optional pub-dir pub-func _base-dir)
   "Check the timestamp of the last publishing of FILENAME.
-Return non-nil if the file needs publishing.  Also check if
-any included files have been more recently published, so that
-the file including them will be republished as well."
+Return non-nil if the file needs publishing.  This is the case
+if either FILENAME does not occur in the publication cache or
+if FILENAME, or any file included by it, was modified after the
+most recent publication."
   (unless org-publish-cache
     (error
      "`org-publish-cache-file-needs-publishing' called, but no cache present"))
@@ -1322,7 +1323,7 @@ the file including them will be republished as well."
     (or (null pstamp)
 	(let ((mtime (org-publish-cache-mtime-of-src filename)))
 	  (or (time-less-p pstamp mtime)
-	      (cl-some (lambda (ct) (time-less-p mtime ct))
+	      (cl-some (lambda (ct) (time-less-p pstamp ct))
 		       included-files-mtime))))))
 
 (defun org-publish-cache-set-file-property
-- 
2.25.1

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to