Skip to content
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

Merged
merged 4 commits into from
Feb 13, 2015
Merged

Update git-show recipe #491

merged 4 commits into from
Feb 13, 2015

Conversation

rmoehn
Copy link
Contributor

@rmoehn rmoehn commented Feb 11, 2015

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.

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)
Copy link
Member

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')
Copy link
Member

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.

Copy link
Contributor Author

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.

@jdavid
Copy link
Member

jdavid commented Feb 13, 2015

Python 3.2+ has a new datetime.timezone object. In my opinion it would be better to use it, and just add a comment about Python 2.

@rmoehn
Copy link
Contributor Author

rmoehn commented Feb 13, 2015

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.
@jdavid jdavid merged commit 1cb62ab into libgit2:master Feb 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants