Update git-show recipe

I couldn't get the diff as shown in the git-show recipe. Therefore
update it to what I think it should be. Maybe there is a better way.

Also add a section on how to assemble a git show-like message. It took
me quite some searching in the Python docs to find out how to do it,
especially the date and time part. So this might save people time. I
wanted to add something that gives me a git show --stat equivalent, but
couldn't figure it out.
This commit is contained in:
Richard Möhn 2015-02-11 18:00:00 +01:00
parent d64dd15bd2
commit c87d28c9a8

@ -31,7 +31,7 @@ Show SHA hash
Show diff
======================================================================
>>> diff = commit.tree.diff()
>>> diff = commit.parents[0].tree.diff_to_tree(commit.tree)
======================================================================
Show all files in commit
@ -40,6 +40,22 @@ Show all files in commit
>>> for e in commit.tree:
>>> print(e.name)
======================================================================
Produce something like a `git show` message
======================================================================
>>> from __future__ import unicode_literals
>>> from datetime import datetime
>>> import pytz
>>> tzinfo = pytz.timezone('Europe/Berlin')
>>> dt = datetime.fromtimestamp(float(commit.commit_time), tzinfo)
>>> timestr = dt.strftime('%c %z')
>>> msg = '\n'.join(['commit {}'.format(commit.tree_id.hex),
... 'Author: {} <{}>'.format(commit.author.name, commit.author.email),
... 'Date: {}'.format(timestr),
... '',
... commit.message])
----------------------------------------------------------------------
References
----------------------------------------------------------------------