From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: Re: commit style redux Date: Sat, 16 Jan 2010 10:10:26 +0100 Message-ID: <87y6jypg8t.fsf@ambire.localdomain> References: <3a26oiti.fsf@fencepost.gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1263633200 29462 80.91.229.12 (16 Jan 2010 09:13:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 16 Jan 2010 09:13:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 16 10:13:13 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NW4iU-0001YP-9y for ged-emacs-devel@m.gmane.org; Sat, 16 Jan 2010 10:13:10 +0100 Original-Received: from localhost ([127.0.0.1]:40378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NW4iU-0005oG-Jd for ged-emacs-devel@m.gmane.org; Sat, 16 Jan 2010 04:13:10 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NW4iO-0005o7-NI for emacs-devel@gnu.org; Sat, 16 Jan 2010 04:13:04 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NW4iM-0005nV-3C for emacs-devel@gnu.org; Sat, 16 Jan 2010 04:13:03 -0500 Original-Received: from [199.232.76.173] (port=44514 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NW4iL-0005nR-W2 for emacs-devel@gnu.org; Sat, 16 Jan 2010 04:13:02 -0500 Original-Received: from smtp-out26.alice.it ([85.33.2.26]:1268) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NW4iL-00082A-Fp for emacs-devel@gnu.org; Sat, 16 Jan 2010 04:13:01 -0500 Original-Received: from FBCMMO01.fbc.local ([192.168.68.195]) by smtp-out26.alice.it with Microsoft SMTPSVC(6.0.3790.3959); Sat, 16 Jan 2010 10:12:59 +0100 Original-Received: from FBCMCL01B01.fbc.local ([192.168.69.82]) by FBCMMO01.fbc.local with Microsoft SMTPSVC(6.0.3790.3959); Sat, 16 Jan 2010 10:12:59 +0100 Original-Received: from ambire.localdomain ([87.4.66.221]) by FBCMCL01B01.fbc.local with Microsoft SMTPSVC(6.0.3790.3959); Sat, 16 Jan 2010 10:12:59 +0100 Original-Received: from ttn by ambire.localdomain with local (Exim 4.63) (envelope-from ) id 1NW4fq-0001Ut-93 for emacs-devel@gnu.org; Sat, 16 Jan 2010 10:10:26 +0100 In-Reply-To: <3a26oiti.fsf@fencepost.gnu.org> (Glenn Morris's message of "Fri, 15 Jan 2010 22:00:09 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (gnu/linux) X-OriginalArrivalTime: 16 Jan 2010 09:12:59.0665 (UTC) FILETIME=[193F5810:01CA968C] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:120098 Archived-At: () Glenn Morris () Fri, 15 Jan 2010 22:00:09 -0500 I use M-x log-edit-insert-changelog to auto-populate the vc-log buffer from my ChangeLog entries. Is this doing the right thing, or does Emacs need to be changed? It creates log entries like this: * cedet/ede/cpp-root.el (ede-cpp-root-project): Foo * srecode/doc-cpp.srt, srecode/doc-default.srt: Bar * ede.texi (ede-target): * org.texi (Refiling notes): Qux The paths are relative to where each ChangeLog file is, rather than relative to the root of the project. If there are two files with the same basename in different subdirectories, things might get ambiguous. FWIW, the following substandard (undocumented except for this message, works for me on 23.0.60.9, tuned to my tastes) code disambiguates the ChangeLog greps. It basically: - looks at each named ChangeLog in the "git status" output; - inserts the first entry, stripping/unifying the "subject line" (sanity-checking that they are all string=, in the process); - modifies the entries' "* foo" to contain the ChangeLog's directory parent prefix (if any) from the project root, so that "abc/def/ChangeLog" entry "* foo (bar): baz" ends up looking like "* abc/def/foo (bar): baz". The OLDGIT cruft is for Git 1.5.3.5, which i have transitioned away from in the last few months and can probably be safely ignored. With this, i do "git commit" (either directly via M-x compile) or through some VC keybinding, `C-c C-d' to populate the buffer, and `C-c C-c' to finish. Doubtless a SMOP can get this adapted to (current) Emacs (current) VC (current) Git with support for other DVCSes as well. thi ________________________________________________________________________ ;;; this is arguably the wrong way to go about things... (defun commit-log-from-git-status (relative-file-names) (let ((changelogs (or (remove-if-not (lambda (s) (string-match "ChangeLog$" s)) relative-file-names) (error "No ChangeLog files"))) head body) (dolist (fn changelogs) (with-temp-buffer (insert-file-contents fn) (search-forward "\n\n" nil nil 2) (push (buffer-substring (point-min) (point)) head) (unless (or (null (cdr head)) (string= (car head) (cadr head))) (error "head mismatch for %s" fn)) (push (buffer-substring (point) (progn (re-search-forward change-log-start-entry-re) (match-beginning 0))) body))) (setq head (car head) head (and (string-match "\n\n\t" head) (substring head (match-end 0))) body (map 'list (lambda (fn bod) (let ((pre (and (string-match "ChangeLog$" fn) (substring fn 0 (match-beginning 0))))) (with-temp-buffer (insert bod) (goto-char (point-min)) (while (search-forward "\t* " nil 1) (insert pre)) (while (re-search-backward "^\t" nil t) (delete-char 1)) (buffer-string)))) (nreverse changelogs) body)) (apply 'concat head body))) (defun scan-git-status-and-insert-commit-log () (interactive) (let ((oldgitp (equal "1" (getenv "OLDGIT"))) (default-directory (expand-file-name "..")) (max (save-excursion (if (search-forward "Changed but not updated" nil t) (match-beginning 0) (point-max)))) sub acc) (unless oldgitp (let ((root default-directory)) (find-if (lambda (buf) (with-current-buffer buf (when (and (eq 'compilation-mode major-mode) (eq 'run (process-status buf)) (setq sub (expand-file-name default-directory)) (search root sub)) (setq sub (substring sub (1+ (mismatch root sub))))))) (buffer-list)))) (save-excursion (while (re-search-forward "\tmodified: +\\(.+$\\)" max t) (push (concat sub (match-string 1)) acc))) (insert (commit-log-from-git-status (nreverse acc))))) (defvar commit-editmsg-map (let ((m (copy-keymap text-mode-map))) (define-keys m "\C-c\C-d" 'scan-git-status-and-insert-commit-log "\C-c\C-c" 'server-edit) m)) (defun commit-editmsg-setup () (when (string-match ".git/COMMIT_EDITMSG" (or buffer-file-name "")) (set-buffer-file-coding-system 'utf-8) (use-local-map commit-editmsg-map))) (add-hook 'server-visit-hook 'commit-editmsg-setup) ;;; vc-git-hacking.el ends here