Emacs: Is there a way to generate a skeleton ChangeLog from diff?
Asked Answered
S

4

6

I'd like to partly automate creation of GNU-style ChangeLog entries when working with source code in version control. The add-changelog-entry-other-window works with one file at a time and you have to visit the file to use it.

What I'd like to see instead is to have some command that would take an output of diff -u -p (or have integration with VC modes so it could process svn diff etc) and to create all the skeleton entries at once.

For example, if svn status shows

D file1.c
M file2.c
A file3.c

the command would create

2009-09-05  My Name <my.email>

      * file1.c: Removed.
      * file2.c: WRITE YOUR CHANGES HERE
      * file3.c: New.

Better yet, if it could parse the changed files in some languages to an extent so it could offer:

  * file2.c (new_function): New function.
  (deleted_function): Removed.
  (changed_function): WRITE YOUR CHANGES HERE

I have found this feature in Emacs manual, but I don't see how I could apply it here.

Any suggestions? Thanks.

EDIT: One answer suggested vc-update-change-log. Unfortunately it only supports CVS and it creates ChangeLog entries by querying the already-commited VC logs. Thus even if it supported svn and others, it would be impossible to commit the changes and the ChangeLog in the same commit.

EDIT2: Apparently add-changelog-entry-other-window (C-x 4 a) works not only from visited file but from diff hunk involving that file too. (Source) This is almost what I am looking for. This together with elisp loop to iterate through all hunks should solve it.

Sanguinary answered 5/5, 2009 at 17:59 Comment(2)
I think tracking the function level changes will be tricky.Langbehn
jinxed_coder: no question about that. That was more "pie in the sky" wish. On the other hand, it does not have to be 100% perfect.Sanguinary
M
2

I don't know of a function that does this, but it should be easy to implement. Basically, you want to

  • get the changed files
  • for each file, call add-change-log
"Find change log file, and add an entry for today and an item for this file.
Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
name and email (stored in `add-log-full-name' and `add-log-mailing-address').

Second arg FILE-NAME is file name of the change log.
If nil, use the value of `change-log-default-name'.

Third arg OTHER-WINDOW non-nil means visit in other window.

Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry.  Option `add-log-keep-changes-together'
otherwise affects whether a new entry is created.

Option `add-log-always-start-new-record' non-nil means always create a
new record, even when the last record was made on the same date and by
the same person.

The change log file can start with a copyright notice and a copying
permission notice.  The first blank line indicates the end of these
notices.

Today's date is calculated according to `add-log-time-zone-rule' if
non-nil, otherwise in local time."

so the magic code is going to look something like

(apply 'make-magic-change-log-entry changed-files-list)

and make-magic-change-log-entry simply curries the add-change-log function so that the only argument is file-name — you set the other ones.

Mickey answered 5/5, 2009 at 18:50 Comment(2)
Thanks. I guess this will exclude deleted and added files?Sanguinary
Depends o how you generate that changed-files-list. Lots of things you could do, like having the list be a list of cons pairs (an "alist") like ("added" . "filename"). If you want to do much magic, you might make a new customized add-change-log-entry with an argument for whatever other stuff you want. the thing to do is read the add-log.el code.Mickey
K
3

There is a function vc-update-change-log that automatically generates change log entries from the version control log entries.

Ketubim answered 6/5, 2009 at 5:41 Comment(2)
Sorry, this is not what I am looking for. First, it only supports CVS. Even if it supported other VC systems, it creates ChangeLog entries from VC log entries, meaning that the changed files are already commited. Sure that's fine with CVS, but with any 21st century version control system i'd like to commit the ChangeLog in the same changeset as the changed files themselves.Sanguinary
You're right, I didn't check that neither psvn or git/magit implemented this feature, sorry about that.Ketubim
I
3

diff-add-change-log-entries-other-window is documented to do exactly what you mentioned in EDIT2:

diff-add-change-log-entries-other-window is an interactive compiled
Lisp function in `diff-mode.el'.

(diff-add-change-log-entries-other-window)

Iterate through the current diff and create ChangeLog entries.
I.e. like `add-change-log-entry-other-window' but applied to all hunks.

Unfortunately, it doesn't work very well for, say, new files: it doesn't even include the filenames of such files in the skeletal changelog entry.

You might have better luck with gcc's mklog script, which you can get from http://gcc.gnu.org/viewcvs/gcc/trunk/contrib/mklog.

Infinitesimal answered 4/11, 2013 at 3:49 Comment(1)
Indeed diff-add-change-log-entries-other-window is supposed to be exactly what Laurynas asked for, but it's far from perfect. We welcome improvements to it (e.g. to handle deleted/added files), but my experience when I tried it lead me to believe that it requires too much intelligence to do it automatically, and that since the actual text has to be written by hand anyway, the benefit of making the skeleton in one go is not that significant.Choke
M
2

I don't know of a function that does this, but it should be easy to implement. Basically, you want to

  • get the changed files
  • for each file, call add-change-log
"Find change log file, and add an entry for today and an item for this file.
Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
name and email (stored in `add-log-full-name' and `add-log-mailing-address').

Second arg FILE-NAME is file name of the change log.
If nil, use the value of `change-log-default-name'.

Third arg OTHER-WINDOW non-nil means visit in other window.

Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry.  Option `add-log-keep-changes-together'
otherwise affects whether a new entry is created.

Option `add-log-always-start-new-record' non-nil means always create a
new record, even when the last record was made on the same date and by
the same person.

The change log file can start with a copyright notice and a copying
permission notice.  The first blank line indicates the end of these
notices.

Today's date is calculated according to `add-log-time-zone-rule' if
non-nil, otherwise in local time."

so the magic code is going to look something like

(apply 'make-magic-change-log-entry changed-files-list)

and make-magic-change-log-entry simply curries the add-change-log function so that the only argument is file-name — you set the other ones.

Mickey answered 5/5, 2009 at 18:50 Comment(2)
Thanks. I guess this will exclude deleted and added files?Sanguinary
Depends o how you generate that changed-files-list. Lots of things you could do, like having the list be a list of cons pairs (an "alist") like ("added" . "filename"). If you want to do much magic, you might make a new customized add-change-log-entry with an argument for whatever other stuff you want. the thing to do is read the add-log.el code.Mickey
M
2

I've written a function to do something similar to what you were talking about. You can get the code at http://www.emacswiki.org/emacs/log-edit-fill

Monadelphous answered 3/6, 2009 at 18:34 Comment(1)
Thanks! Finally I got around trying it. How do I actually use it? If I try to invoke in svn-log-edit buffer, I get Symbol's function definition is void: log-edit-show-diff. Also, my question concerned about filling the ChangeLog file before the actual commit, is there a way to use log-edit-fill in that way?Sanguinary

© 2022 - 2024 — McMap. All rights reserved.