{"thread":{"id":"8980","subject":"Getting version output for a file.","startedAt":"2007-07-11T11:39:31Z","lastAt":"2007-07-12T14:48:48Z","messageCount":3,"participants":["David Kastrup","Brian Gernhardt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"47024","messageId":"86abu3dv9o.fsf@lola.quinscape.zz","threadId":"8980","inReplyTo":null,"subject":"Getting version output for a file.","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-07-11T11:39:31Z","receivedAt":"2007-07-11T11:39:31Z","isPatch":false,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"\nHi,\n\nthe Emacs support for git is incomplete, making it bomb out, for\nexample, when doing\nC-u C-x v =\n\nIn order to have it work better, I need to fill in the following\nfunctions:\n\n(vc-git-previous-version FILE REV)\nReturn the version number immediately preceding REV for FILE,\nor nil if there is no previous version.\n\n(vc-git-next-version FILE REV)\nReturn the version number immediately following REV for FILE,\nor nil if there is no previous version.\n\nREV will tend to be a symbolic reference like \"master\" or possibly\n\"master{2}\" (I am fuzzy about the details, but at least repeated\ninvocations of vc-git-previous-version should work with the previous\noutput).  The corresponding next and previous versions should be\nchanges that actually changed the file in question.\n\nThere is likely going to be some magic shell invocation of\ngit-rev-list, git-symbolic-ref and/or similar things to achieve this\ntask.  I don't have enough of a clue to fill in the necessary details,\nbut I'd be able to convert them into Elisp.\n\nAnybody with good suggestions?  It would be beneficial if this would\nnot require the newest git version in order to work.  If that means\nthat the output needs to be somewhat more massaged, that's ok.\n\nThanks,\n\n-- \nDavid Kastrup\n"},{"id":"47067","messageId":"A084830C-F1CD-4EDC-A13D-573DFC68DF77@silverinsanity.com","threadId":"8980","inReplyTo":"86abu3dv9o.fsf@lola.quinscape.zz","subject":"Re: Getting version output for a file.","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-07-11T19:48:51Z","receivedAt":"2007-07-11T19:48:51Z","isPatch":false,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"I don't know lisp very well, and elisp not at all, but I can help you  \nwith what command lines would give you the results you might want.\n\nOn Jul 11, 2007, at 7:39 AM, David Kastrup wrote:\n\n> (vc-git-previous-version FILE REV)\n> Return the version number immediately preceding REV for FILE,\n> or nil if there is no previous version.\n\nIf you want the last revision where the file was altered, you could  \neasily use\n\ngit rev-list -2 $current_rev -- $file | tail -1\n\nThe result would be a SHA-1 of the next commit where the file was  \naltered.\n\n> (vc-git-next-version FILE REV)\n> Return the version number immediately following REV for FILE,\n> or nil if there is no previous version.\n\nThis is a little more problematic as git doesn't have forward links  \nin it's history.  If you have a ref to start with (HEAD is a good one  \nto use, if you don't have anything else) you could use a similar  \ncommand to the above\n\ngit rev-list $ref -- $file | grep -C1 -m1 $current_rev | head -1\n\nIf you don't have a ref to start from, you could use --all, but that  \nmay not be what the user expects.\n\nIf you want a human readable name for either you could use name-rev.   \n(Add \"| git name-rev --stdin\" to the end of the above.)  It places a  \nhuman readable name after the SHA-1 in parentheses.  (example:  \n\"54dadbdb29668fbd51effefd0a0c65d915f5422b (master~3)\")\n\n~~ Brian\n"},{"id":"47168","messageId":"86lkdlu0tr.fsf_-_@lola.quinscape.zz","threadId":"8980","inReplyTo":"A084830C-F1CD-4EDC-A13D-573DFC68DF77@silverinsanity.com","subject":"[PATCH] Add missing functions to contrib/emacs/vc-git.el","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-07-12T14:48:48Z","receivedAt":"2007-07-12T14:48:48Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"\nThis is necessary to make several editing functions work, like\nC-u C-x v =\n\nSigned-off-by: David Kastrup <dak@gnu.org>\n\n---\n contrib/emacs/vc-git.el |   65 +++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 65 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/emacs/vc-git.el b/contrib/emacs/vc-git.el\nindex e456ab9..b8f6be5 100644\n--- a/contrib/emacs/vc-git.el\n+++ b/contrib/emacs/vc-git.el\n@@ -81,6 +81,71 @@\n         (match-string 2 str)\n       str)))\n \n+(defun vc-git-symbolic-commit (commit)\n+  \"Translate COMMIT string into symbolic form.\n+Returns nil if not possible.\"\n+  (and commit\n+       (with-temp-buffer\n+\t (and\n+\t  (zerop\n+\t   (call-process \"git\" nil '(t nil) nil \"name-rev\"\n+\t\t\t \"--name-only\" \"--tags\"\n+\t\t\t commit))\n+\t  (goto-char (point-min))\n+\t  (= (forward-line 2) 1)\n+\t  (bolp)\n+\t  (buffer-substring-no-properties (point-min) (1- (point-max)))))))\n+\n+(defun vc-git-previous-version (file rev)\n+  \"git-specific version of `vc-previous-version'.\"\n+  (let ((default-directory (file-name-directory (expand-file-name file)))\n+\t(file (file-name-nondirectory file)))\n+    (vc-git-symbolic-commit\n+     (with-temp-buffer\n+       (and\n+\t(zerop\n+\t (call-process \"git\" nil '(t nil) nil \"rev-list\"\n+\t\t       \"-2\" rev \"--\" file))\n+\t(goto-char (point-max))\n+\t(bolp)\n+\t(zerop (forward-line -1))\n+\t(not (bobp))\n+\t(buffer-substring-no-properties\n+\t   (point)\n+\t   (1- (point-max))))))))\n+\n+(defun vc-git-next-version (file rev)\n+  \"git-specific version of `vc-next-version'.\"\n+  (let* ((default-directory (file-name-directory\n+\t\t\t     (expand-file-name file)))\n+\t(file (file-name-nondirectory file))\n+\t(current-rev\n+\t (with-temp-buffer\n+\t   (and\n+\t    (zerop\n+\t     (call-process \"git\" nil '(t nil) nil \"rev-list\"\n+\t\t\t   \"-1\" rev \"--\" file))\n+\t    (goto-char (point-max))\n+\t    (bolp)\n+\t    (zerop (forward-line -1))\n+\t    (bobp)\n+\t    (buffer-substring-no-properties\n+\t     (point)\n+\t     (1- (point-max)))))))\n+    (and current-rev\n+\t (vc-git-symbolic-commit\n+\t  (with-temp-buffer\n+\t    (and\n+\t     (zerop\n+\t      (call-process \"git\" nil '(t nil) nil \"rev-list\"\n+\t\t\t    \"HEAD\" \"--\" file))\n+\t     (goto-char (point-min))\n+\t     (search-forward current-rev nil t)\n+\t     (zerop (forward-line -1))\n+\t     (buffer-substring-no-properties\n+\t      (point)\n+\t      (progn (forward-line 1) (1- (point))))))))))\n+\n (defun vc-git-revert (file &optional contents-done)\n   \"Revert FILE to the version stored in the git repository.\"\n   (if contents-done\n-- \n1.5.3.rc0.51.gb0b1f\n\n\n-- \nDavid Kastrup\n"}]}