git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Getting version output for a file.

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Jul 11, 2007, 19:48 UTC
Message-ID
<A084830C-F1CD-4EDC-A13D-573DFC68DF77@silverinsanity.com>
In-Reply-To
<86abu3dv9o.fsf@lola.quinscape.zz>

I don't know lisp very well, and elisp not at all, but I can help you with what command lines would give you the results you might want.

On Jul 11, 2007, at 7:39 AM, David Kastrup wrote:
> (vc-git-previous-version FILE REV)
> Return the version number immediately preceding REV for FILE,
> or nil if there is no previous version.

If you want the last revision where the file was altered, you could easily use

git rev-list -2 $current_rev -- $file | tail -1

The result would be a SHA-1 of the next commit where the file was altered.

> (vc-git-next-version FILE REV)
> Return the version number immediately following REV for FILE,
> or nil if there is no previous version.

This is a little more problematic as git doesn't have forward links in it's history. If you have a ref to start with (HEAD is a good one to use, if you don't have anything else) you could use a similar command to the above

git rev-list $ref -- $file | grep -C1 -m1 $current_rev | head -1

If you don't have a ref to start from, you could use --all, but that may not be what the user expects.

If you want a human readable name for either you could use name-rev. (Add "| git name-rev --stdin" to the end of the above.) It places a human readable name after the SHA-1 in parentheses. (example: "54dadbdb29668fbd51effefd0a0c65d915f5422b (master~3)")

~~ Brian
Previous: David KastrupNext: David Kastrup
Message 2 of 3 in “Getting version output for a file.”
  1. David KastrupJul 11, 2007
  2. Brian GernhardtJul 11, 2007
  3. Add missing functions to contrib/emacs/vc-git.elDavid Kastrup, Jul 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.