1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
**********************************************************************
git-show
**********************************************************************
----------------------------------------------------------------------
Showing a commit
----------------------------------------------------------------------
.. code-block:: bash
$ git show d370f56
.. code-block:: python
>>> repo = pygit2.Repository('/path/to/repository')
>>> commit = repo.revparse_single('d370f56')
======================================================================
Show log message
======================================================================
>>> message = commit.message
======================================================================
Show SHA hash
======================================================================
>>> hash = str(commit.id)
======================================================================
Show diff
======================================================================
>>> diff = repo.diff(commit.parents[0], commit)
======================================================================
Show all files in commit
======================================================================
>>> for e in commit.tree:
>>> print(e.name)
======================================================================
Produce something like a ``git show`` message
======================================================================
Then you can make your message:
>>> from datetime import datetime, timezone, timedelta
>>> tzinfo = timezone( timedelta(minutes=commit.author.offset) )
>>>
>>> dt = datetime.fromtimestamp(float(commit.author.time), tzinfo)
>>> timestr = dt.strftime('%c %z')
>>> msg = '\n'.join([f'commit {commit.tree_id}',
... f'Author: {commit.author.name} <{commit.author.email}>',
... f'Date: {timestr}',
... '',
... commit.message])
----------------------------------------------------------------------
References
----------------------------------------------------------------------
- git-show_.
.. _git-show: https://www.kernel.org/pub/software/scm/git/docs/git-show.html
|