Merge lp:~jelmer/dulwich/tree-add-order into lp:~vcs-imports/dulwich/trunk

Proposed by Jelmer Vernooij
Status: Merged
Merge reported by: Jelmer Vernooij
Merged at revision: not available
Proposed branch: lp:~jelmer/dulwich/tree-add-order
Merge into: lp:~vcs-imports/dulwich/trunk
Diff against target: 152 lines (+44/-12)
7 files modified
NEWS (+6/-0)
docs/tutorial/object-store.txt (+1/-1)
dulwich/index.py (+1/-1)
dulwich/objects.py (+8/-3)
dulwich/tests/test_fastexport.py (+1/-1)
dulwich/tests/test_objects.py (+21/-0)
dulwich/tests/test_patch.py (+6/-6)
To merge this branch: bzr merge lp:~jelmer/dulwich/tree-add-order
Reviewer Review Type Date Requested Status
VCS imports Pending
Review via email: mp+53178@code.launchpad.net

Description of the change

This change makes the order of the arguments to Tree.add() consistent
with the rest of Dulwich - name, mode, hexsha. The old ordering is
still supported but using it will display a deprecation warning.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-03-06 03:48:23 +0000
3+++ NEWS 2011-03-13 16:58:09 +0000
4@@ -16,6 +16,12 @@
5
6 * Sphinxified documentation. (Lukasz Balcerzak)
7
8+ API CHANGES
9+
10+ * The order of the parameters to Tree.add(name, mode, sha) has changed, and
11+ is now consistent with the rest of Dulwich. Existing code will still
12+ work but print a DeprecationWarning. (Jelmer Vernooij, #663550)
13+
14 0.7.0 2011-01-21
15
16 FEATURES
17
18=== modified file 'docs/tutorial/object-store.txt'
19--- docs/tutorial/object-store.txt 2011-01-24 16:36:50 +0000
20+++ docs/tutorial/object-store.txt 2011-03-13 16:58:09 +0000
21@@ -27,7 +27,7 @@
22
23 >>> from dulwich.objects import Tree
24 >>> tree = Tree()
25- >>> tree.add(0100644, "spam", blob.id)
26+ >>> tree.add("spam", 0100644, blob.id)
27
28 Note that "0100644" is the octal form for a regular file with common
29 permissions. You can hardcode them or you can use the ``stat`` module.
30
31=== modified file 'dulwich/index.py'
32--- dulwich/index.py 2010-05-24 17:21:02 +0000
33+++ dulwich/index.py 2011-03-13 16:58:09 +0000
34@@ -330,7 +330,7 @@
35 sha = build_tree(pathjoin(path, basename))
36 else:
37 (mode, sha) = entry
38- tree.add(mode, basename, sha)
39+ tree.add(basename, mode, sha)
40 object_store.add_object(tree)
41 return tree.id
42 return build_tree("")
43
44=== modified file 'dulwich/objects.py'
45--- dulwich/objects.py 2011-03-06 03:48:23 +0000
46+++ dulwich/objects.py 2011-03-13 16:58:09 +0000
47@@ -27,6 +27,7 @@
48 import os
49 import posixpath
50 import stat
51+import warnings
52 import zlib
53
54 from dulwich.errors import (
55@@ -819,14 +820,18 @@
56 self._ensure_parsed()
57 return iter(self._entries)
58
59- def add(self, mode, name, hexsha):
60+ def add(self, name, mode, hexsha):
61 """Add an entry to the tree.
62
63- :param mode: The mode of the entry as an integral type. Not all possible
64- modes are supported by git; see check() for details.
65+ :param mode: The mode of the entry as an integral type. Not all
66+ possible modes are supported by git; see check() for details.
67 :param name: The name of the entry, as a string.
68 :param hexsha: The hex SHA of the entry as a string.
69 """
70+ if type(name) is int and type(mode) is str:
71+ (name, mode) = (mode, name)
72+ warnings.warn("Please use Tree.add(name, mode, hexsha)",
73+ category=DeprecationWarning, stacklevel=2)
74 self._ensure_parsed()
75 self._entries[name] = mode, hexsha
76 self._needs_serialization = True
77
78=== modified file 'dulwich/tests/test_fastexport.py'
79--- dulwich/tests/test_fastexport.py 2010-12-12 05:15:03 +0000
80+++ dulwich/tests/test_fastexport.py 2011-03-13 16:58:09 +0000
81@@ -61,7 +61,7 @@
82 b = Blob()
83 b.data = "FOO"
84 t = Tree()
85- t.add(stat.S_IFREG | 0644, "foo", b.id)
86+ t.add("foo", stat.S_IFREG | 0644, b.id)
87 c = Commit()
88 c.committer = c.author = "Jelmer <jelmer@host>"
89 c.author_time = c.commit_time = 1271345553
90
91=== modified file 'dulwich/tests/test_objects.py'
92--- dulwich/tests/test_objects.py 2010-12-19 15:56:03 +0000
93+++ dulwich/tests/test_objects.py 2011-03-13 16:58:09 +0000
94@@ -26,6 +26,7 @@
95 import datetime
96 import os
97 import stat
98+import warnings
99
100 from dulwich.errors import (
101 ObjectFormatException,
102@@ -404,6 +405,26 @@
103
104 class TreeTests(ShaFileCheckTests):
105
106+ def test_add(self):
107+ myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
108+ x = Tree()
109+ x.add("myname", 0100755, myhexsha)
110+ self.assertEquals(x["myname"], (0100755, myhexsha))
111+ self.assertEquals('100755 myname\0' + hex_to_sha(myhexsha),
112+ x.as_raw_string())
113+
114+ def test_add_old_order(self):
115+ myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
116+ x = Tree()
117+ warnings.simplefilter("ignore", DeprecationWarning)
118+ try:
119+ x.add(0100755, "myname", myhexsha)
120+ finally:
121+ warnings.resetwarnings()
122+ self.assertEquals(x["myname"], (0100755, myhexsha))
123+ self.assertEquals('100755 myname\0' + hex_to_sha(myhexsha),
124+ x.as_raw_string())
125+
126 def test_simple(self):
127 myhexsha = "d80c186a03f423a81b39df39dc87fd269736ca86"
128 x = Tree()
129
130=== modified file 'dulwich/tests/test_patch.py'
131--- dulwich/tests/test_patch.py 2010-12-18 16:48:28 +0000
132+++ dulwich/tests/test_patch.py 2011-03-13 16:58:09 +0000
133@@ -256,13 +256,13 @@
134 changed2 = Blob.from_string("unchanged\nadded\n")
135 unchanged = Blob.from_string("unchanged\n")
136 tree1 = Tree()
137- tree1.add(0644, "removed.txt", removed.id)
138- tree1.add(0644, "changed.txt", changed1.id)
139- tree1.add(0644, "unchanged.txt", changed1.id)
140+ tree1.add("removed.txt", 0644, removed.id)
141+ tree1.add("changed.txt", 0644, changed1.id)
142+ tree1.add("unchanged.txt", 0644, changed1.id)
143 tree2 = Tree()
144- tree2.add(0644, "added.txt", added.id)
145- tree2.add(0644, "changed.txt", changed2.id)
146- tree2.add(0644, "unchanged.txt", changed1.id)
147+ tree2.add("added.txt", 0644, added.id)
148+ tree2.add("changed.txt", 0644, changed2.id)
149+ tree2.add("unchanged.txt", 0644, changed1.id)
150 store.add_objects([(o, None) for o in [
151 tree1, tree2, added, removed, changed1, changed2, unchanged]])
152 write_tree_diff(f, store, tree1.id, tree2.id)

Subscribers

People subscribed via source and target branches