Emacs:有没有办法从 diff 生成骨架变更日志?

发布于 2024-07-19 16:12:36 字数 1352 浏览 2 评论 0原文

我想在版本控制中使用源代码时部分自动创建 GNU 风格的 ChangeLog 条目。 add-changelog-entry-other-window 一次只处理一个文件,您必须访问该文件才能使用它。

我希望看到的是有一些命令可以获取 diff -u -p 的输出(或者与 VC 模式集成,以便它可以处理 svn diff > 等)并立即创建所有骨架条目。

例如,如果 svn status 显示

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

该命令会创建

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

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

更好的结果,如果它可以在一定程度上解析某些语言中已更改的文件,以便它可以提供:

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

我找到了 Emacs 手册中的此功能,但我不知道如何应用在这里。

有什么建议么? 谢谢。

编辑:建议一个答案 vc-update -更改日志。 不幸的是,它仅支持 CVS,并通过查询已提交的 VC 日志来创建 ChangeLog 条目。 因此,即使它支持 svn 和其他,也不可能在同一次提交中提交更改和 ChangeLog。

EDIT2:显然 add-changelog-entry-other-window (Cx 4 a)不仅适用于访问的文件,也适用于涉及该文件的 diff 块。 (来源)这几乎就是我正在寻找的。 这与 elisp 循环一起迭代所有块应该可以解决它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最美不过初阳 2024-07-26 16:12:36

有一个函数 vc -update-change-log 从版本控制日志条目自动生成更改日志条目。

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

月下客 2024-07-26 16:12:36

diff-add-change-log-entries-other-window 被记录为完全按照您在 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.

不幸的是,它对于新文件来说效果不佳:它没有甚至不要在骨架变更日志条目中包含此类文件的文件名。

您可能会更幸运地使用 gcc 的 mklog 脚本,您可以从 http:// gcc.gnu.org/viewcvs/gcc/trunk/contrib/mklog

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.

迷鸟归林 2024-07-26 16:12:36

我不知道有什么函数可以做到这一点,但它应该很容易实现。 基本上,您想要

  • 获取每个文件的更改文件
  • ,请调用 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."

因此魔术代码将类似于

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

make-magic-change-log-entry< /code> 只是柯里化了 add-change-log 函数,以便唯一的参数是 file-name — 您可以设置其他参数。

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.

漫雪独思 2024-07-26 16:12:36

我已经编写了一个函数来执行与您所说的类似的操作。 您可以在 http://www.emacswiki.org/emacs/log- 获取代码编辑-填充

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文