File: git-show.rst

package info (click to toggle)
python-pygit2 1.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,328 kB
  • sloc: ansic: 11,016; python: 5,943; sh: 275; makefile: 19
file content (66 lines) | stat: -rw-r--r-- 2,320 bytes parent folder | download | duplicates (2)
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 = commit.hex

======================================================================
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(['commit {}'.format(commit.tree_id.hex),
    ...                      'Author: {} <{}>'.format(commit.author.name, commit.author.email),
    ...                      'Date:   {}'.format(timestr),
    ...                      '',
    ...                      commit.message])

----------------------------------------------------------------------
References
----------------------------------------------------------------------

- git-show_.

.. _git-show: https://www.kernel.org/pub/software/scm/git/docs/git-show.html