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

Expand revparse support #1022

Merged
merged 3 commits into from
Jul 24, 2020
Merged

Expand revparse support #1022

merged 3 commits into from
Jul 24, 2020

Conversation

rcoup
Copy link
Contributor

@rcoup rcoup commented Jul 23, 2020

Expands revision parsing support:

  1. adds Repository.revparse_with_reference() which maps to git_revparse_ext() — takes the same arguments as revparse_single() but returns a 2-tuple (Object, Reference) where the revspec is a reference eg: master.
    a. ❓ Not sure on naming? find_revision()?
    b. ❓ Should we deprecate Repository.revparse_single() in favour of this rather than having two methods?
    c. ❓ Or merge them via something like revparse_single(revspec, with_reference=True)

  2. adds Repository.revparse() which maps to git_revparse() — does range requests (eg: HEAD^1...new@{yesterday}). Returns a RevSpec object which has .from_object, .to_object, and .intents properties.

  3. Adds a crude repr() implementation for Object-ish classes. eg: <pygit2.Object{commit:5ebeeebb320790caf276b9fc8b24546d63316533}>. I kinda feel we should be adding useful repr() methods to all classes going forward, otherwise debugging or exploration via a Python shell is unnecessarily slow.

>>> repr(a_commit)
<pygit2.Object{commit:5ebeeebb320790caf276b9fc8b24546d63316533}>
Copy link
Member

@jdavid jdavid left a comment

Choose a reason for hiding this comment

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

I would keep both methods and call the new one revparse_ext.

At some point we should reconsider the API. Probably adding a higher level interface in Python that calls the low-level revparse_single etc. Something like repo.objects.get(...)

src/repository.c Outdated Show resolved Hide resolved
src/revspec.c Outdated Show resolved Hide resolved
…pport.

This maps to git_revparse() and accepts full revspecs including ranges:
https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions

Returns a RevSpec object which has from_object/to_object/flags properties.
Implements git_revparse_ext(). Takes the same revspec as Repository.revparse_single(), but returns
a 2-tuple (Object, Reference). Where the revspec maps to a reference it is returned as well as the
target object, otherwise None.
@rcoup
Copy link
Contributor Author

rcoup commented Jul 24, 2020

I would keep both methods and call the new one revparse_ext.

Done. I renamed RevSpec.intent to .flags to match the libgit2 object as well.

@jdavid jdavid merged commit 083ecd8 into libgit2:master Jul 24, 2020
@jdavid jdavid mentioned this pull request Oct 4, 2020
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 22, 2020
Includes a build fix for the updated libgit2 1.1.x, figured it may as well
be updated at the same time.

1.3.0 (2020-09-18)
-------------------------

- New ``Repository.add_submodule(...)``
  `#1011 <https://github.com/libgit2/pygit2/pull/1011>`_

- New ``Repository.applies(...)``
  `#1019 <https://github.com/libgit2/pygit2/pull/1019>`_

- New ``Repository.revparse(...)`` and ``Repository.revparse_ext(...)``
  `#1022 <https://github.com/libgit2/pygit2/pull/1022>`_

- New optional ``flags`` and ``file_flags`` arguments in
  ``Repository.merge_commits`` and ``Repository.merge_trees``
  `#1008 <https://github.com/libgit2/pygit2/pull/1008>`_

- New ``Reference.raw_target``, ``Repository.raw_listall_branches(...)`` and
  ``Repository.raw_listall_references()``; allow bytes in
  ``Repository.lookup_branch(...)`` and ``Repository.diff(...)``
  `#1029 <https://github.com/libgit2/pygit2/pull/1029>`_

- New ``GIT_BLAME_FIRST_PARENT`` and ``GIT_BLAME_USE_MAILMAP`` constants
  `#1031 <https://github.com/libgit2/pygit2/pull/1031>`_

- New ``IndexEntry`` supports ``repr()``, ``str()``, ``==`` and ``!=``
  `#1009 <https://github.com/libgit2/pygit2/pull/1009>`_

- New ``Object`` supports ``repr()``
  `#1022 <https://github.com/libgit2/pygit2/pull/1022>`_

- New accept tuples of strings (not only lists) in a number of places
  `#1025 <https://github.com/libgit2/pygit2/pull/1025>`_

- Fix compatibility with old macOS 10.9
  `#1026 <https://github.com/libgit2/pygit2/issues/1026>`_
  `#1027 <https://github.com/libgit2/pygit2/pull/1027>`_

- Fix check argument type in ``Repository.apply(...)``
  `#1033 <https://github.com/libgit2/pygit2/issues/1033>`_

- Fix raise exception if error in ``Repository.listall_submodules()`` commit 32133974

- Fix a couple of refcount errors in ``OdbBackend.refresh()`` and
  ``Worktree_is_prunable`` commit fed0c19c

- Unit tests
  `#800 <https://github.com/libgit2/pygit2/issues/800>`_
  `#1015 <https://github.com/libgit2/pygit2/pull/1015>`_

- Documentation
  `#705 <https://github.com/libgit2/pygit2/pull/705>`_
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

2 participants