3

git statusdulwichと同等の機能をどのように実行できるのでしょうか。

私はこれを試しました:

いくつかのファイルを追加/変更/名前変更し、コミットのためにそれらをステージングした後、これは私がやろうとしたことです:

from dulwich.repo  import Repo
from dulwich.index import changes_from_tree
r = Repo('my-git-repo')
index = r.open_index()
changes = index.changes_from_tree(r.object_store, r['HEAD'].tree)

以下を出力します。

>>> list(changes)
(('Makefile', None), (33188, None), ('9b20...', None))
(('test/README.txt', 'test/README.txt'), (33188, 33188), ('484b...', '4f89...'))
((None, 'Makefile.mk'), (None, 33188), (None, '9b20...'))
((None, 'TEST.txt'), (None, 33188), (None, '2a02...'))

しかし、この出力では、以下を検出するためにさらに処理する必要があります。

  1. 変更しましたREADME.txt
  2. 名前をに変更MakefileしましたMakefile.mk
  3. TEST.txtリポジトリに追加しました。

の関数は、dulwich.diff_treeツリーの変更に対してはるかに優れたインターフェイスを提供します...これは実際にコミットする前に不可能ですか?

4

2 に答える 2

2

dulwich.diff_tree.tree_changesを使用して、2つのツリー間の変更を検出できるはずです。

このための要件の1つは、関連するツリーオブジェクトをオブジェクトストアに追加することです。これに使用できますdulwich.index.commit_index

于 2012-06-10T11:27:37.100 に答える
1

完全を期すために、実用的なサンプル:

from dulwich.repo import Repo
from dulwich.diff_tree import tree_changes

repo = Repo("./") 

index = repo.open_index()

try:
    head_tree = repo.head().tree
except KeyError: # in case of empty tree
    head_tree = dulwich.objects.Tree()

changes = list(tree_changes(repo, head_tree, index.commit(repo.object_store)))


for change in changes:
    print "%s: %s"%(change.type,change.new.path)
于 2013-09-19T07:46:55.170 に答える