Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions B-embedding-git-in-your-applications.asc
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ include::book/B-embedding-git/sections/libgit2.asc[]
include::book/B-embedding-git/sections/jgit.asc[]

include::book/B-embedding-git/sections/go-git.asc[]

include::book/B-embedding-git/sections/dulwich.asc[]

44 changes: 44 additions & 0 deletions book/B-embedding-git/sections/dulwich.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== Dulwich

(((Dulwich)))((("Python")))
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Does this index entry require the quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do not know, to be hones, I just copied it from libgit2 example.
Digging deeper, #471 seems to be a reason for those quotes.

Will be happy to remove those if you think there might be some side-effects, but I guess same logic should be applicable for go-git as well.

Let me know if you want me to remove both in this PR

Copy link
Member

Choose a reason for hiding this comment

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

Alright, let's maybe clean them up in a separate PR then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 #1096 created

There is also a pure-Python Git implementation - Dulwich.
The project is hosted under https://www.dulwich.io/
It aims to provide an interface to git repositories (both local and remote) that doesn't call out to git directly but instead uses pure Python.
It has an optional C extensions though, that significantly improve the performance.

Dulwich follows git design and separate two basic levels of API: plumbing and porcelain.

Here is an example of using the lower level API to access the commit message of the last commit:

[source, python]
-----
from dulwich.repo import Repo
r = Repo('.')
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind renaming this variable to current_repo or something similar? And maybe c should be called commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now it's just 1-to-1 copy from https://www.dulwich.io/docs/#getting-started

Please, let me know if you still think it should be change and I will be happy to do so.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. Should we make this example more readable, or easier to update? Let's stick with Dulwich's example then.

r.head()
# '57fbe010446356833a6ad1600059d80b1e731e15'

c = r[r.head()]
c
# <Commit 015fc1267258458901a94d228e39f0a378370466>

c.message
# 'Add note about encoding.\n'
-----

To print a commit log using high-level porcelain API, one can use:

[source, python]
-----
from dulwich import porcelain
porcelain.log('.', max_entries=1)

#commit: 57fbe010446356833a6ad1600059d80b1e731e15
#Author: Jelmer Vernooij <jelmer@jelmer.uk>
#Date: Sat Apr 29 2017 23:57:34 +0000
-----


==== Further Reading

* The official API documentation is available at https://www.dulwich.io/apidocs/dulwich.html[]
* Official tutorial at https://www.dulwich.io/docs/tutorial[] has many examples of how to do specific tasks with Dulwich