Subject: Re: bug#63916: 30.0.50; use-package: changes do not propagate to elpa-devel

From: Benjamin Orthen <[email-masked]>
Date: Mon, 11 Sep 2023 11:58:45 +0200

Hi,

I've sent the mail to [email-masked] and request the assignment form.

I modified the changes according to your and Philip's remarks.

On Fri, 2023-09-08 at 15:35 -0400, Stefan Monnier wrote:
> Hi,
> 
> > Instead of looking only at the git log of the main package file, we
> > look instead at the git log of all files of the core package.
> > This way, a new devel version is created when any other package
> > file is
> > changed, not just the main file.
> 
> It has a minor downside which is that it slows down the overwhelming
> cases (where there are no changes), but it's probably lost in the
> noise,
> so it sounds like a very good idea, thank you.
> 
> > Is this the right mailing list to send the patch?
> 
> Yes.
> 
> [ BTW, Philip's `list-ensure` is called `ensure-list` :-)
>   And yes, I think it's OK to use functionality from Emacs-28.  ]
> 
> > +  (when-let
> > +      ((core (elpaa--spec-get pkg-spec :core)))
> 
> AFAICT this code is only used when `:core` is non-nil, so better
> either
> not test for it redundantly, or do it via `cl-assert`.

Done
> 
> > +                    (unless (member item excludes)
> 
> The code looks generally good, but I'm not sure about the one line
> above:
> - I know it won't do the right thing for ERC's "lisp/erc/ChangeLog.*"
>   but it's probably harmless (those files basically never change
>   anyway).
> - I have the impression that it won't do the right thing for
>   `use-package`'s "bind-key.el"

I changed the code to ignore files using the wildcards in :excludes.
This still does not work for "bind-key.el", but IMO this can and should
be solved by changing it to "lisp/use-package/bind-key.el", 
similar to how erc is doing it ("lisp/erc/erc-loaddefs.el" ).

(The commentary says: ";; Exclude matches must be against the full
file-name, substring matches don't
;; work unless wildcards are used (e.g. use "etc/*" instead of
"etc/").")

> 
> Also, I see you do (concat item file) but you only know that `item`
> is
> a directory, not that it ends with a `/`.  Better use `file-name-
> concat`.

With `directory-files-recursively` this has resolved itself.
> 
> Last but not least: I think this doesn't quite qualify as "trivial"
> so
> we'd need you to sign the copyright paperwork (well, maybe with some
> of
> the suggested simplifications, it could qualify as "trivial", but
> it's
> easier if you sign the paperwork so we don't have to worry about it,
> especially if you ever submit more code, which I hope you will).
> To that end, please fill the form below and email it to the FSF as
> instructed so they can send you the appropriate paperwork to sign.
> 
> 
>         Stefan
> 
> 
> Please email the following information to [email-masked], and we
> will send you the assignment form for your past and future changes.
> 
> Please use your full legal name (in ASCII characters) as the subject
> line of the message.
> ----------------------------------------------------------------------
> REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
> 
> [What is the name of the program or package you're contributing to?]
> Emacs
> 
> [Did you copy any files or text written by someone else in these
> changes?
> Even if that material is free software, we need to know about it.]
> 
> 
> [Do you have an employer who might have a basis to claim to own
> your changes?  Do you attend a school which might make such a claim?]
> 
> 
> [For the copyright registration, what country are you a citizen of?]
> 
> 
> [What year were you born?]
> 
> 
> [Please write your email address here.]
> 
> 
> [Please write your postal address here.]
> 
> 
> 
> 
> 
> [Which files have you changed so far, and which new files have you
> written
> so far?]
> 

From 0290e2f2e9bc5a3615dde54c142ae3cb54dc2274 Mon Sep 17 00:00:00 2001
From: Benjamin Orthen <[email-masked]>
Date: Fri, 8 Sep 2023 12:05:14 +0200
Subject: [PATCH] Add elpa--core-files to get more exact devel-versions for
 core packages

---
 elpa-admin.el | 54 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 11 deletions(-)

diff --git a/elpa-admin.el b/elpa-admin.el
index 2c2d2aeab7..d9a22b0055 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -908,20 +908,52 @@ of the current `process-environment'.  Return the modified copy."
                0)))
     (encode-time (list s mi h d mo y nil nil zs))))
 
+(defun elpaa--core-files (pkg-spec)
+  "Get a list of core files (and only files) for PKG-SPEC.
+Core folders are recursively searched, excluded files are ignored."
+  (let* ((file-patterns (ensure-list (elpaa--spec-get pkg-spec :core)))
+         (excludes (elpaa--spec-get pkg-spec :excludes))
+         (emacs-repo-root (expand-file-name "emacs"))
+         (default-directory emacs-repo-root)
+         (core-files nil))
+
+    ;; ensure we look at files from a core package
+    (cl-assert file-patterns)
+
+    ;; we look at each file or files in folder and add them
+    ;; to core-files
+    (dolist (item file-patterns)
+      (if (file-directory-p item)
+          (setq core-files (append core-files (directory-files-recursively item ".*")))
+        (push item core-files)))
+
+    ;; remove all files which match a wildcard in the excludes
+    (setq core-files (cl-remove-if
+                      (lambda (file-name)
+                        (seq-some
+                         (lambda (wildcard)
+                           (string-match-p (wildcard-to-regexp wildcard) file-name))
+                         excludes))
+                      core-files))
+    core-files))
+
 (defun elpaa--get-devel-version (dir pkg-spec)
   "Compute the date-based pseudo-version used for devel builds."
-  (let* ((ftn (file-truename      ;; Follow symlinks!
-              (expand-file-name (elpaa--main-file pkg-spec) dir)))
-         (default-directory (file-name-directory ftn))
-         (gitdate
+  (let* ((gitdate
           (with-temp-buffer
-           (if (plist-get (cdr pkg-spec) :core)
-               ;; For core packages, don't use the date of the last
-               ;; commit to the branch, but that of the last commit
-               ;; to the main file.
-               (elpaa--call t "git" "log" "--pretty=format:%cI" "--no-patch"
-                            "-1" "--" (file-name-nondirectory ftn))
-             (elpaa--call t "git" "show" "--pretty=format:%cI" "--no-patch"))
+            (if (plist-get (cdr pkg-spec) :core)
+                (let
+                    ((core-files (elpaa--core-files pkg-spec))
+                     (default-directory (expand-file-name "emacs")))
+                  ;; For core packages, don't use the date of the last
+                  ;; commit to the branch, but that of the last commit
+                  ;; to the core files.
+                  (apply #'elpaa--call t "git" "log" "--pretty=format:%cI" "--no-patch"
+                         "-1" "--" core-files))
+              (let* ((ftn (file-truename      ;; Follow symlinks!
+                           (expand-file-name (elpaa--main-file pkg-spec) dir)))
+                     (default-directory (file-name-directory ftn)))
+                (elpaa--call t "git" "show" "--pretty=format:%cI" "--no-patch")))
             (buffer-string)))
          (verdate
           ;; Convert Git's date into something that looks like a version number.
-- 
2.41.0