Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list a directory in a Git repository together with the latest commit info for each directory entry?

Tags:

git

I want to list a directory from a Git repository together with the latest commit information of each directory entry. Similiar to how GitHub displays directories or how viewvc displays a directory in an SVN/CVS repository.

Currently I do it like this:

  1. Get the directory entries with git ls-tree master and parse the directory structure from the output.

  2. Then for each directory entry I do this: git log -n 1 master -- filename and parse the commit information from it (I specify a special format string to make this easier, but this isn't relevant to my problem).

It's pretty obvious that this is very slow, because I have to call Git for each file. Is there a faster way to do this? Maybe a single command I can execute to get all the data I need at once?

like image 669
kayahr Avatar asked May 21 '11 16:05

kayahr


1 Answers

Oneliner to parse git whatchanged output and print tree annotated with recent commit ids:

git whatchanged -r --pretty=oneline | perl -ne 'our %q; if (/^([0-9a-f]{40})/) {$c = $1} if (/:.{38}(.*)/) { $q{$1} = $c unless exists $q{$1} }; END { print map {"$q{$_} $_\n"} (keys %q); }'  | sort -k 2

Example output:

b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/file.c
b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/Makefile
b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/unfreezemodule.c
efeda0a22e4d1d5f3d755fee5b72fa99c0046e38 code/unfreezer/.gitignore
b822361ffbc4548d918df5381ce94c296459598a code/unfreezer/unfreezer.c
18ed76836182eba702e89b929eff2c0ea78ffb3e code/whole/wh
1e111ce4e8c0813b397f34e3634309f7594cb864 code/xbmctest/.gitignore
cb67943c4c18e3461267a34935fc8efaca5e2166 .config/awesome/awesome.lua
d5e2b7c1d24bed1d0b53338f43747dc856c9cfe4 .config/awesome/rc.lua
13ca8dbcd7f1ec684a7eba494442ee743ed577c0 cr
566b54fb72e32947fcbf7d5c58fed78b5abe976d d
392ac1a2456e8a29b2ebb7af9499c3f69d24a559 Desktop/CityInfo.desktop
392ac1a2456e8a29b2ebb7af9499c3f69d24a559 Desktop/.directory

You can adjust git whatchanged parameters and/or filter the output as you want.

like image 192
Vi. Avatar answered Oct 01 '22 03:10

Vi.