Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "git log --pretty=<pretty format>" a porcelain or plumbing command?

Tags:

git

git-log

I am creating some scripts and programs that fetch commit information using

git log --pretty=<my format> -1 <commit>

I wonder if the output of this command is suitable to be parsed by programs (plumbing) or only meant to be presented to humans (porcelain). For example, in some projects I am fetching commit SHA + author name + commit summary with this:

git log --pretty="%H%n%an%n%s" -1 HEAD

And then I split the output string by the newline character (I'm on Linux).

Besides, in some cases I also do something like this:

git log --pretty='[%h] %an: %s' -1 HEAD

And then parse the result with the following regex, expecting that a short SHA, the author name and the commit summary are in the captured groups:

^\[(\w+)\] ([^:]+): (.*)$

Is it a good approach? If not, what is the preferred way to programmatically get information about commits?

like image 503
iBug Avatar asked Dec 02 '18 15:12

iBug


1 Answers

git log is a porcelain command.

It actually performs quite a disparate number of tasks — combining walking the revision graph, git diff and git grep and whatnot.

A plumbing way to do someting like

git log --pretty='[%h] %an: %s' -1 HEAD

is to combine git show-ref with git cat-file and parse the result—something like

git cat-file commit `git show-ref -s HEAD` |
  while read line; do
    # do some processing
  done

Actually the root Git's manual page, git(1)—run git help git to read it—contains the breakdown of commands into porcelain and plumbing layers.

like image 54
kostix Avatar answered Oct 05 '22 22:10

kostix