-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update git-show recipe #491
Conversation
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.
@@ -31,7 +31,7 @@ Show SHA hash | |||
Show diff | |||
====================================================================== | |||
|
|||
>>> diff = commit.tree.diff() | |||
>>> diff = commit.parents[0].tree.diff_to_tree(commit.tree) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should prefer to recommend repo.diff(commit.parents[0], commit)
here, as that accepts treeishes in a few forms.
Make the diff generation more idiomatic and fix the assembling of the timestamp. git-show normally prints the author time, so use this instead of the commit time. Also fix how tzinfo is obtained. Of course we have to use the author's time zone and not some fixed one as I had written before.
>>> from __future__ import unicode_literals | ||
>>> from datetime import datetime | ||
>>> import pytz | ||
>>> tzinfo = pytz.timezone('Europe/Berlin') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timezone (really offset) is not fixed for the user running git-show, but is read from the commit, in this case from commit.author.time_offset
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at my new commit. I fixed it there already.
Python 3.2+ has a new |
Thanks for pointing that out. I will upload the patch as soon as I've managed to install pygit2 under Python 3. |
As @jdavid pointed out, Python 3 already provides a tzinfo subclass for fixed UTC offsets. Incorporate this in the recipe. Leave the old code with the self-made class, since many people are working with Python 2 and it is harder to find out there.
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.