Skip to content

Update git-show recipe #491

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

Merged
merged 4 commits into from
Feb 13, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/recipes/git-show.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


======================================================================
Show all files in commit
Expand All @@ -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')
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.

>>> dt = datetime.fromtimestamp(float(commit.commit_time), tzinfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git-show/git-log use the author time rather than commit time. In order to show what it would show, we'd want to use commit.author.time here.

>>> 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
----------------------------------------------------------------------
Expand Down