Commit a7f52745c95e5dd673a79a2281ccd7463ce00ffa

Added info about 0.1.7 release changes
reverted 19533ffadbcc959f12bf51488cf66f0715bec4c1 as it would introduce an API change
CHANGES
(11 / 7)
  
44
550.1.7
66=======
7This is a bugfix release and the last of its kind in 0.1.X, as 0.2.X will receive
8a major redesign that will change the API.
9
10Bugfixes
11--------
12* Paths in Tree objects can now handle whitespace
13* Blob.blame was returning incorrect results which has been fixed.
14
715General
816-------
9* See changes in Diff class as your client code needs adjustments to work with it
10
11Diff
12----
13* Members a a_commit and b_commit renamed to a_blob and b_blob - they are populated
14 with Blob objects if possible
15* Members a_path and b_path removed as this information is kept in the blobs
17* The test suite now supports Mock 0.5 and above. The transition between Mock 0.4
18 0.5 changed the API which required adjustments.
19* Many small enhancements done to the method documentation
1620
1721
18220.1.6
  
55# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
77import re
8import blob
8import commit
99
1010class Diff(object):
1111 """
1212 A Diff contains diff information between two commits.
13
14 It contains two sides a and b of the diff, members are prefixed with
15 "a" and "b" respectively to inidcate that.
16
17 Diffs keep information about the changed blob objects, the file mode, renames,
18 deletions and new files.
19
20 There are a few cases where None has to be expected as member variable value:
21
22 ``New File``::
23
24 a_mode is None
25 a_blob is None
26
27 ``Deleted File``::
28
29 b_mode is None
30 b_blob is NOne
3113 """
3214
33 def __init__(self, repo, a_path, b_path, a_blob, b_blob, a_mode,
15 def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode,
3416 b_mode, new_file, deleted_file, rename_from,
3517 rename_to, diff):
3618 self.repo = repo
19 self.a_path = a_path
20 self.b_path = b_path
3721
38 if not a_blob or re.search(r'^0{40}$', a_blob):
39 self.a_blob = None
22 if not a_commit or re.search(r'^0{40}$', a_commit):
23 self.a_commit = None
4024 else:
41 self.a_blob = blob.Blob(repo, id=a_blob, mode=a_mode, name=a_path)
42 if not b_blob or re.search(r'^0{40}$', b_blob):
43 self.b_blob = None
25 self.a_commit = commit.Commit(repo, id=a_commit)
26 if not b_commit or re.search(r'^0{40}$', b_commit):
27 self.b_commit = None
4428 else:
45 self.b_blob = blob.Blob(repo, id=b_blob, mode=b_mode, name=b_path)
29 self.b_commit = commit.Commit(repo, id=b_commit)
4630
4731 self.a_mode = a_mode
4832 self.b_mode = b_mode
3939
4040 @classmethod
4141 def list_from_string(cls, repo, text):
42 """
43 Create a new diff object from the given text
44 ``repo``
45 is the repository we are operating on - it is required
46
47 ``text``
48 result of 'git diff' between two commits or one commit and the index
49
50 Returns
51 git.Diff[]
52 """
5342 diffs = []
5443
5544 diff_header = re.compile(r"""
5151 ^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
5252 (?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
5353 (?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
54 (?:^index[ ](?P<a_blob>[0-9A-Fa-f]+)
55 \.\.(?P<b_blob>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
54 (?:^index[ ](?P<a_commit>[0-9A-Fa-f]+)
55 \.\.(?P<b_commit>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
5656 """, re.VERBOSE | re.MULTILINE).match
5757
5858 for diff in ('\n' + text).split('\ndiff --git')[1:]:
6060
6161 a_path, b_path, similarity_index, rename_from, rename_to, \
6262 old_mode, new_mode, new_file_mode, deleted_file_mode, \
63 a_blob, b_blob, b_mode = header.groups()
63 a_commit, b_commit, b_mode = header.groups()
6464 new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode)
6565
66 diffs.append(Diff(repo, a_path, b_path, a_blob, b_blob,
66 diffs.append(Diff(repo, a_path, b_path, a_commit, b_commit,
6767 old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode,
6868 new_file, deleted_file, rename_from, rename_to, diff[header.end():]))
6969
  
3737
3838 assert_equal(15, len(diffs))
3939
40 assert_equal('.gitignore', diffs[0].a_blob.name)
41 assert_equal('.gitignore', diffs[0].b_blob.name)
42 assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id)
43 assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id)
44 assert_equal('100644', diffs[0].b_blob.mode)
40 assert_equal('.gitignore', diffs[0].a_path)
41 assert_equal('.gitignore', diffs[0].b_path)
42 assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_commit.id)
43 assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_commit.id)
44 assert_equal('100644', diffs[0].b_mode)
4545 assert_equal(False, diffs[0].new_file)
4646 assert_equal(False, diffs[0].deleted_file)
4747 assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff)
4848
49 assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name)
50 assert_equal(None, diffs[5].a_blob)
51 assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id)
52 assert_equal( None, diffs[5].a_mode )
49 assert_equal('lib/grit/actor.rb', diffs[5].a_path)
50 assert_equal(None, diffs[5].a_commit)
51 assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id)
5352 assert_equal(True, diffs[5].new_file)
5453
5554 assert_true(git.called)
8888 diffs = Commit.diff(self.repo, '59ddc32', ['lib'])
8989
9090 assert_equal(1, len(diffs))
91 assert_equal('lib/grit/diff.rb', diffs[0].a_blob.name)
91 assert_equal('lib/grit/diff.rb', diffs[0].a_path)
9292
9393 assert_true(git.called)
9494 assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True}))
100100 diffs = Commit.diff(self.repo, '59ddc32', '13d27d5', ['lib'])
101101
102102 assert_equal(1, len(diffs))
103 assert_equal('lib/grit/commit.rb', diffs[0].a_blob.name)
103 assert_equal('lib/grit/commit.rb', diffs[0].a_path)
104104
105105 assert_true(git.called)
106106 assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True}))
114114
115115 assert_equal(15, len(diffs))
116116
117 assert_equal('.gitignore', diffs[0].a_blob.name)
118 assert_equal('.gitignore', diffs[0].b_blob.name)
119 assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_blob.id)
120 assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_blob.id)
121 assert_equal('100644', diffs[0].b_blob.mode)
117 assert_equal('.gitignore', diffs[0].a_path)
118 assert_equal('.gitignore', diffs[0].b_path)
119 assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666', diffs[0].a_commit.id)
120 assert_equal('2dd02534615434d88c51307beb0f0092f21fd103', diffs[0].b_commit.id)
121 assert_equal('100644', diffs[0].b_mode)
122122 assert_equal(False, diffs[0].new_file)
123123 assert_equal(False, diffs[0].deleted_file)
124124 assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg", diffs[0].diff)
125125
126 assert_equal('lib/grit/actor.rb', diffs[5].b_blob.name)
127 assert_equal(None, diffs[5].a_blob)
128 assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id)
126 assert_equal('lib/grit/actor.rb', diffs[5].a_path)
127 assert_equal(None, diffs[5].a_commit)
128 assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id)
129129 assert_equal(True, diffs[5].new_file)
130130
131131 assert_true(git.called)
144144
145145 assert_equal(10, len(diffs))
146146
147 assert_equal('History.txt', diffs[0].b_blob.name)
148 assert_equal(None, diffs[0].a_blob)
149 assert_equal('100644', diffs[0].b_blob.mode)
150 assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_blob.id)
147 assert_equal('History.txt', diffs[0].a_path)
148 assert_equal('History.txt', diffs[0].b_path)
149 assert_equal(None, diffs[0].a_commit)
150 assert_equal('100644', diffs[0].b_mode)
151 assert_equal('81d2c27608b352814cbe979a6acd678d30219678', diffs[0].b_commit.id)
151152 assert_equal(True, diffs[0].new_file)
152153 assert_equal(False, diffs[0].deleted_file)
153154 assert_equal("--- /dev/null\n+++ b/History.txt\n@@ -0,0 +1,5 @@\n+== 1.0.0 / 2007-10-09\n+\n+* 1 major enhancement\n+ * Birthday!\n+", diffs[0].diff)
154155
155 assert_equal('lib/grit.rb', diffs[5].b_blob.name)
156 assert_equal(None, diffs[5].a_blob)
157 assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id)
156 assert_equal('lib/grit.rb', diffs[5].a_path)
157 assert_equal(None, diffs[5].a_commit)
158 assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_commit.id)
158159 assert_equal(True, diffs[5].new_file)
159160
160161 assert_true(git.called)
181181 commit.__bake_it__()
182182 diffs = commit.diffs
183183
184 # in case of mode-only changes, there is no blob
185184 assert_equal(23, len(diffs))
186 assert_equal(None, diffs[0].a_blob)
187 assert_equal(None, diffs[0].b_blob)
188185 assert_equal('100644', diffs[0].a_mode)
189186 assert_equal('100755', diffs[0].b_mode)
190187