Skip to content

Commit

Permalink
Fix order of parameters to Tree.add.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Mar 13, 2011
1 parent ee747f6 commit 9c7de18
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

* Sphinxified documentation. (Lukasz Balcerzak)

API CHANGES

* The order of the parameters to Tree.add(name, mode, sha) has changed, and
is now consistent with the rest of Dulwich. Existing code will still
work but print a DeprecationWarning. (Jelmer Vernooij, #663550)

0.7.0 2011-01-21

FEATURES
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/object-store.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ give this content a name::

>>> from dulwich.objects import Tree
>>> tree = Tree()
>>> tree.add(0100644, "spam", blob.id)
>>> tree.add("spam", 0100644, blob.id)

Note that "0100644" is the octal form for a regular file with common
permissions. You can hardcode them or you can use the ``stat`` module.
Expand Down
2 changes: 1 addition & 1 deletion dulwich/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def build_tree(path):
sha = build_tree(pathjoin(path, basename))
else:
(mode, sha) = entry
tree.add(mode, basename, sha)
tree.add(basename, mode, sha)
object_store.add_object(tree)
return tree.id
return build_tree("")
Expand Down
11 changes: 8 additions & 3 deletions dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import posixpath
import stat
import warnings
import zlib

from dulwich.errors import (
Expand Down Expand Up @@ -819,14 +820,18 @@ def __iter__(self):
self._ensure_parsed()
return iter(self._entries)

def add(self, mode, name, hexsha):
def add(self, name, mode, hexsha):
"""Add an entry to the tree.
:param mode: The mode of the entry as an integral type. Not all possible
modes are supported by git; see check() for details.
:param mode: The mode of the entry as an integral type. Not all
possible modes are supported by git; see check() for details.
:param name: The name of the entry, as a string.
:param hexsha: The hex SHA of the entry as a string.
"""
if type(name) is int and type(mode) is str:
(name, mode) = (mode, name)
warnings.warn("Please use Tree.add(name, mode, hexsha)",
category=DeprecationWarning, stacklevel=2)
self._ensure_parsed()
self._entries[name] = mode, hexsha
self._needs_serialization = True
Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/test_fastexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_emit_commit(self):
b = Blob()
b.data = "FOO"
t = Tree()
t.add(stat.S_IFREG | 0644, "foo", b.id)
t.add("foo", stat.S_IFREG | 0644, b.id)
c = Commit()
c.committer = c.author = "Jelmer <jelmer@host>"
c.author_time = c.commit_time = 1271345553
Expand Down
21 changes: 21 additions & 0 deletions dulwich/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import datetime
import os
import stat
import warnings

from dulwich.errors import (
ObjectFormatException,
Expand Down Expand Up @@ -404,6 +405,26 @@ def test_check_order(self):

class TreeTests(ShaFileCheckTests):

def test_add(self):
myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
x = Tree()
x.add("myname", 0100755, myhexsha)
self.assertEquals(x["myname"], (0100755, myhexsha))
self.assertEquals('100755 myname\0' + hex_to_sha(myhexsha),
x.as_raw_string())

def test_add_old_order(self):
myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
x = Tree()
warnings.simplefilter("ignore", DeprecationWarning)
try:
x.add(0100755, "myname", myhexsha)
finally:
warnings.resetwarnings()
self.assertEquals(x["myname"], (0100755, myhexsha))
self.assertEquals('100755 myname\0' + hex_to_sha(myhexsha),
x.as_raw_string())

def test_simple(self):
myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
x = Tree()
Expand Down
12 changes: 6 additions & 6 deletions dulwich/tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ def test_tree_diff(self):
changed2 = Blob.from_string("unchanged\nadded\n")
unchanged = Blob.from_string("unchanged\n")
tree1 = Tree()
tree1.add(0644, "removed.txt", removed.id)
tree1.add(0644, "changed.txt", changed1.id)
tree1.add(0644, "unchanged.txt", changed1.id)
tree1.add("removed.txt", 0644, removed.id)
tree1.add("changed.txt", 0644, changed1.id)
tree1.add("unchanged.txt", 0644, changed1.id)
tree2 = Tree()
tree2.add(0644, "added.txt", added.id)
tree2.add(0644, "changed.txt", changed2.id)
tree2.add(0644, "unchanged.txt", changed1.id)
tree2.add("added.txt", 0644, added.id)
tree2.add("changed.txt", 0644, changed2.id)
tree2.add("unchanged.txt", 0644, changed1.id)
store.add_objects([(o, None) for o in [
tree1, tree2, added, removed, changed1, changed2, unchanged]])
write_tree_diff(f, store, tree1.id, tree2.id)
Expand Down

0 comments on commit 9c7de18

Please sign in to comment.