Reputation: 2095
I am trying to use 'git log --pretty=tformat' to create xml file log. However I have problem getting the list of file for each commit.
for example: I use this command
$echo '<?xml version="1.0"?>' > out.xml
$echo '<git>' >> out.xml
$git log --pretty=tformat:' <commit>%n <h1>%s</h1>%n </commit>' --name-only >> out.xml
$echo '</git>'>> out.xml
the output:
<?xml version="1.0"?>
<git>
<commit>
<h1>Commit 1</h1>
</commit>
<commit>
<h1>Commit 2</h1>
</commit>
<commit>
<h1>Commit 3</h1>
</commit>
</git>
I want to add tag in side the commit tag with the list of files so my final output look like this
<?xml version="1.0"?>
<git>
<commit>
<h1>Commit 1</h1>
<list>file1</list>
</commit>
<commit>
<h1>Commit 2</h1>
<list>file2</list>
</commit>
<commit>
<h1>Commit 3</h1>
<list>file3</list>
</commit>
</git>
I did try --name-only it will list the file but cannot format the output.
Any help would be much appreciated.
Upvotes: 0
Views: 4517
Reputation: 3
I managed to get all file information as a single text field with some minor manipulation of the file afterwards (moving the first two rows to the end of the file) with the following powershell script: (replacing REPONAME with the name of the repository, could be automated further.)
git --git-dir <path to repository> log --name-only --pretty=format:"]]></files>%n</commit>%n<commit>%n<repo>REPONAME</repo>%n<hash>%H</hash>%n<author>%an</author>%n<dt>%ct</dt>%n<subject><![CDATA[%s]]></subject>%n<files><![CDATA[" | Out-File REPONAME.xml
$x = get-content REPONAME.xml
@("<gitrepo>") + $x[2..$x.count] + $x[0..1] + @("</gitrepo>") | set-content REPONAME.xml
To split up the files I had to do some further processing in the database (splitting newline etc), but that is outside the scope of this answer.
This outputs a file which looks like:
<gitrepo>
<commit>
<repo>REPONAME</repo>
<hash>388d77493cb2b4d3260cd12b1adcf23e947755f4</hash>
<author>Some Guy</author>
<dt>1401802177</dt>
<subject><![CDATA[Comments added to files]]></subject>
<files><![CDATA[
src/aben/blanksid.w
src/aben/c_typop.w
src/aben/freg.w
src/aben/freskid.w
src/aben/grit5.w
src/aben/grokli.w
]]></files>
</commit>
</gitrepo>
Upvotes: 0
Reputation: 44294
This might not be what you're looking for, but it's easy to script. The following is one implementation, inefficient but functional. Careful running it: It will operate on your entire history. Change the second line to revlist=$(git rev-list -10 HEAD)
to see it work on just the last 10 commits. It also assumes you want older commits at the bottom of the file, per your example above. Add a --reverse
flag to git rev-list
if you'd prefer chronological order:
#!/bin/sh
revlist=$(git rev-list HEAD)
(
echo '<?xml version="1.0"?>'
echo '<git>'
for rev in $revlist
do
files=$(git log -1 --pretty="format:" --name-only $rev)
echo ' <commit>\n <h1>\c'
echo "$(git log -1 --pretty="%s" $rev)\c"
echo '</h1>'
for file in $files
do
echo " <list>$file</list>"
done
echo ' </commit>'
done
echo '</git>'
) > out.xml
Upvotes: 4