I’d like to write a set of elisp functions to manipulate commits identified by the currently selected region when viewing a git log in Git-Log-View mode of vc.el. A common subcomponent of these functions would need to be a function that would obtain the commit metadata for the list of commits selected by the region in the Git-Log-View buffer, but I have no idea how to write such a routine. I was hoping that vc.el provided such a mechanism directly, but from what I can see via apropos it doesn’t.
I’ve poked around in vc.el and vc-git.el to try to get some idea of how vc.el works, but it is a fairly complex bit of elisp and I’m by no means an elisp expert. It seems reasonable to me though that vc.el/vc-git.el has the commit metadata available somewhere, since in Git-Log-View mode you can do things like select a region and ask for a changeset diff over that region, or expand a given commit to see the detailed commit info, and I just want to build some similar functionality.
Any thoughts on how to do this? I suppose I could just directly get the currently selected text and parse the abbreviated log format myself, but that seems like a huge amount of work that I’d like to avoid if vc-mode can help me out.
vc-gitand other backends don’t really keep the whole bulk of metadata anywhere. For most operations, the backend calls the respective command to get the required data.For example,
Git-Log-Viewis a prettified output ofgit log [-- filename]. The summary you see when expanding a commit was already present in the command output, just hidden, so it’s easier for the user to scan. To show the changeset over a region,log-view-diff-changesetlooks which commits correspond to the region bounds, and delegates tovc-diff-internal, which eventually callsgit diff FROM TO.So you’ll get the hashes of each commit in the region, then call some git command (
git show?) withvc-git-command,vc-git--callor maybevc-git--run-command-stringfor each of them and parse the results. Maybe just callgit logfor all of them at once if you manage to make it include all the relevant data.