Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88cc927

Browse files
committed
Merge branches 'doc_enhancements' and 'fixes_for_mainline' into improvements_for_mainline
* doc_enhancements: improved repo documentation Improved head and tag object documentation slightly Added docs for the error module Added missing information to docstrings of commit and stats module improved git.cmd documentation Improved documentation on Actor and Blob* fixes_for_mainline: repo_tests: fixed duplicate test-method name which would redefine the previous one which never ran Fixed Diff class which used Commits instead of Blobs - as Blobs contain the path ( in the 'name' member variable ), the a|b_path members of Diff have been removed. Tests were adjusted and run git.git.Git.__init__ takes None as default argument as the execute method handles this correctly Fixed git.blob.Blob.blame function which would return the text-per-commit as individual charactersConflicts:lib/git/cmd.pytest/git/test_repo.py
2 parents07eaa4c +ac13dbc commit88cc927

File tree

7 files changed

+97
-111
lines changed

7 files changed

+97
-111
lines changed

‎CHANGES

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ Repo
4949
* Corrected ``commits_between`` always returning None instead of the reversed
5050
list.
5151

52+
53+
0.1.X
54+
=====
55+
( Future Release )
56+
General
57+
-------
58+
* See changes in Diff class as your client code needs adjustments to work with it
59+
60+
Diff
61+
----
62+
* Members a a_commit and b_commit renamed to a_blob and b_blob - they are populated
63+
with Blob objects if possible
64+
* Members a_path and b_path removed as this information is kept in the blobs
65+
5266

5367
0.1.5
5468
=====

‎lib/git/blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def blame(cls, repo, commit, file):
152152
m=re.search(r'^\t(.*)$',line)
153153
text,=m.groups()
154154
blames[-1][0]=c
155-
blames[-1][1]+=text
155+
blames[-1][1].append(text )
156156
info=None
157157

158158
returnblames

‎lib/git/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Git(object):
3535
of the command to stdout.
3636
Set its value to 'full' to see details about the returned values.
3737
"""
38-
def__init__(self,git_dir):
38+
def__init__(self,git_dir=None):
3939
"""
4040
Initialize this instance with:
4141

‎lib/git/diff.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,44 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
importre
8-
importcommit
8+
importblob
99

1010
classDiff(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
1331
"""
1432

15-
def__init__(self,repo,a_path,b_path,a_commit,b_commit,a_mode,
33+
def__init__(self,repo,a_path,b_path,a_blob,b_blob,a_mode,
1634
b_mode,new_file,deleted_file,rename_from,
1735
rename_to,diff):
1836
self.repo=repo
19-
self.a_path=a_path
20-
self.b_path=b_path
2137

22-
ifnota_commitorre.search(r'^0{40}$',a_commit):
23-
self.a_commit=None
38+
ifnota_bloborre.search(r'^0{40}$',a_blob):
39+
self.a_blob=None
2440
else:
25-
self.a_commit=commit.Commit(repo,id=a_commit)
26-
ifnotb_commitorre.search(r'^0{40}$',b_commit):
27-
self.b_commit=None
41+
self.a_blob=blob.Blob(repo,id=a_blob,mode=a_mode,name=a_path)
42+
ifnotb_bloborre.search(r'^0{40}$',b_blob):
43+
self.b_blob=None
2844
else:
29-
self.b_commit=commit.Commit(repo,id=b_commit)
45+
self.b_blob=blob.Blob(repo,id=b_blob,mode=b_mode,name=b_path)
3046

3147
self.a_mode=a_mode
3248
self.b_mode=b_mode
@@ -39,6 +55,17 @@ def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode,
3955

4056
@classmethod
4157
deflist_from_string(cls,repo,text):
58+
"""
59+
Create a new diff object from the given text
60+
``repo``
61+
is the repository we are operating on - it is required
62+
63+
``text``
64+
result of 'git diff' between two commits or one commit and the index
65+
66+
Returns
67+
git.Diff[]
68+
"""
4269
diffs= []
4370

4471
diff_header=re.compile(r"""
@@ -51,19 +78,19 @@ def list_from_string(cls, repo, text):
5178
^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
5279
(?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
5380
(?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
54-
(?:^index[ ](?P<a_commit>[0-9A-Fa-f]+)
55-
\.\.(?P<b_commit>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
81+
(?:^index[ ](?P<a_blob>[0-9A-Fa-f]+)
82+
\.\.(?P<b_blob>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
5683
""",re.VERBOSE|re.MULTILINE).match
5784

5885
fordiffin ('\n'+text).split('\ndiff --git')[1:]:
5986
header=diff_header(diff)
6087

6188
a_path,b_path,similarity_index,rename_from,rename_to, \
6289
old_mode,new_mode,new_file_mode,deleted_file_mode, \
63-
a_commit,b_commit,b_mode=header.groups()
90+
a_blob,b_blob,b_mode=header.groups()
6491
new_file,deleted_file=bool(new_file_mode),bool(deleted_file_mode)
6592

66-
diffs.append(Diff(repo,a_path,b_path,a_commit,b_commit,
93+
diffs.append(Diff(repo,a_path,b_path,a_blob,b_blob,
6794
old_modeordeleted_file_mode,new_modeornew_file_modeorb_mode,
6895
new_file,deleted_file,rename_from,rename_to,diff[header.end():]))
6996

‎test/git/test_blob.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_should_display_blame_information(self, git):
6969
git.return_value=fixture('blame')
7070
b=Blob.blame(self.repo,'master','lib/git.py')
7171
assert_equal(13,len(b))
72+
assert_equal(2,len(b[0]) )
7273
# assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b))
7374
assert_equal(hash(b[0][0]),hash(b[9][0]))
7475
c=b[0][0]
@@ -83,6 +84,13 @@ def test_should_display_blame_information(self, git):
8384
assert_equal('tom@mojombo.com',c.committer.email)
8485
assert_equal(time.gmtime(1191997100),c.committed_date)
8586
assert_equal('initial grit setup',c.message)
87+
88+
# test the 'lines per commit' entries
89+
tlist=b[0][1]
90+
assert_true(tlist )
91+
assert_true(isinstance(tlist[0],basestring ) )
92+
assert_true(len(tlist )<sum(len(t)fortintlist ) )# test for single-char bug
93+
8694

8795
deftest_should_return_appropriate_representation(self):
8896
blob=Blob(self.repo,**{'id':'abc'})

‎test/git/test_commit.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ def test_diff(self, git):
3737

3838
assert_equal(15,len(diffs))
3939

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)
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)
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].a_path)
50-
assert_equal(None,diffs[5].a_commit)
51-
assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4',diffs[5].b_commit.id)
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 )
5253
assert_equal(True,diffs[5].new_file)
5354

5455
assert_true(git.called)
@@ -88,7 +89,7 @@ def test_diff_with_files(self, git):
8889
diffs=Commit.diff(self.repo,'59ddc32', ['lib'])
8990

9091
assert_equal(1,len(diffs))
91-
assert_equal('lib/grit/diff.rb',diffs[0].a_path)
92+
assert_equal('lib/grit/diff.rb',diffs[0].a_blob.name)
9293

9394
assert_true(git.called)
9495
assert_equal(git.call_args, (('diff','-M','59ddc32','--','lib'), {'full_index':True}))
@@ -100,7 +101,7 @@ def test_diff_with_two_commits_and_files(self, git):
100101
diffs=Commit.diff(self.repo,'59ddc32','13d27d5', ['lib'])
101102

102103
assert_equal(1,len(diffs))
103-
assert_equal('lib/grit/commit.rb',diffs[0].a_path)
104+
assert_equal('lib/grit/commit.rb',diffs[0].a_blob.name)
104105

105106
assert_true(git.called)
106107
assert_equal(git.call_args, (('diff','-M','59ddc32','13d27d5','--','lib'), {'full_index':True}))
@@ -114,18 +115,18 @@ def test_diffs(self, git):
114115

115116
assert_equal(15,len(diffs))
116117

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)
118+
assert_equal('.gitignore',diffs[0].a_blob.name)
119+
assert_equal('.gitignore',diffs[0].b_blob.name)
120+
assert_equal('4ebc8aea50e0a67e000ba29a30809d0a7b9b2666',diffs[0].a_blob.id)
121+
assert_equal('2dd02534615434d88c51307beb0f0092f21fd103',diffs[0].b_blob.id)
122+
assert_equal('100644',diffs[0].b_blob.mode)
122123
assert_equal(False,diffs[0].new_file)
123124
assert_equal(False,diffs[0].deleted_file)
124125
assert_equal("--- a/.gitignore\n+++ b/.gitignore\n@@ -1 +1,2 @@\n coverage\n+pkg",diffs[0].diff)
125126

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)
127+
assert_equal('lib/grit/actor.rb',diffs[5].b_blob.name)
128+
assert_equal(None,diffs[5].a_blob)
129+
assert_equal('f733bce6b57c0e5e353206e692b0e3105c2527f4',diffs[5].b_blob.id)
129130
assert_equal(True,diffs[5].new_file)
130131

131132
assert_true(git.called)
@@ -144,18 +145,17 @@ def test_diffs_on_initial_import(self, git):
144145

145146
assert_equal(10,len(diffs))
146147

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)
148+
assert_equal('History.txt',diffs[0].b_blob.name)
149+
assert_equal(None,diffs[0].a_blob)
150+
assert_equal('100644',diffs[0].b_blob.mode)
151+
assert_equal('81d2c27608b352814cbe979a6acd678d30219678',diffs[0].b_blob.id)
152152
assert_equal(True,diffs[0].new_file)
153153
assert_equal(False,diffs[0].deleted_file)
154154
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)
155155

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)
156+
assert_equal('lib/grit.rb',diffs[5].b_blob.name)
157+
assert_equal(None,diffs[5].a_blob)
158+
assert_equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1',diffs[5].b_blob.id)
159159
assert_equal(True,diffs[5].new_file)
160160

161161
assert_true(git.called)
@@ -181,7 +181,10 @@ def test_diffs_with_mode_only_change(self, git):
181181
commit.__bake_it__()
182182
diffs=commit.diffs
183183

184+
# in case of mode-only changes, there is no blob
184185
assert_equal(23,len(diffs))
186+
assert_equal(None,diffs[0].a_blob)
187+
assert_equal(None,diffs[0].b_blob)
185188
assert_equal('100644',diffs[0].a_mode)
186189
assert_equal('100755',diffs[0].b_mode)
187190

‎test/git/test_repo.py

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,18 @@ def test_diff(self, git):
185185
assert_equal(git.call_args, (('diff','master^','master','--','foo/bar','foo/baz'), {}))
186186

187187
@patch_object(Git,'_call_process')
188-
deftest_diff(self,git):
188+
deftest_diff_with_parents(self,git):
189189
git.return_value=fixture('diff_p')
190190

191191
diffs=self.repo.commit_diff('master')
192192
assert_equal(15,len(diffs))
193193
assert_true(git.called)
194194

195195
deftest_archive_tar(self):
196-
assertself.repo.archive_tar()
196+
self.repo.archive_tar()
197197

198198
deftest_archive_tar_gz(self):
199-
assertself.repo.archive_tar_gz()
199+
self.repo.archive_tar_gz()
200200

201201
@patch('git.utils.touch')
202202
deftest_enable_daemon_serve(self,touch):
@@ -207,52 +207,13 @@ def test_disable_daemon_serve(self):
207207
self.repo.daemon_serve=True
208208
assert_true(self.repo.daemon_serve)
209209

210-
# @patch_object(os.path, 'exists')
211-
# @patch_object('__builtin__', 'open')
212-
# def test_alternates_with_two_alternates(self, exists, read):
213-
# # File.expects(:exist?).with("#{absolute_project_path}/.git/objects/info/alternates").returns(true)
214-
# # File.expects(:read).returns("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
215-
# exists.return_value = True
216-
# read.return_value = ("/path/to/repo1/.git/objects\n/path/to/repo2.git/objects\n")
217-
#
218-
# assert_equal(["/path/to/repo1/.git/objects", "/path/to/repo2.git/objects"], self.repo.alternates)
219-
#
220-
# assert_true(exists.called)
221-
# assert_true(read.called)
222-
#
223210
@patch_object(os.path,'exists')
224211
deftest_alternates_no_file(self,os):
225212
os.return_value=False
226213
assert_equal([],self.repo.alternates)
227214

228215
assert_true(os.called)
229216

230-
# @patch_object(os.path, 'exists')
231-
# def test_alternates_setter_ok(self, os):
232-
# os.return_value = True
233-
# alts = ['/path/to/repo.git/objects', '/path/to/repo2.git/objects']
234-
#
235-
# # File.any_instance.expects(:write).with(alts.join("\n"))
236-
#
237-
# self.repo.alternates = alts
238-
#
239-
# assert_true(os.called)
240-
# # assert_equal(os.call_args, ((alts,), {}))
241-
# # for alt in alts:
242-
#
243-
# @patch_object(os.path, 'exists')
244-
# @raises(NoSuchPathError)
245-
# def test_alternates_setter_bad(self, os):
246-
# os.return_value = False
247-
#
248-
# alts = ['/path/to/repo.git/objects']
249-
# # File.any_instance.expects(:write).never
250-
# self.repo.alternates = alts
251-
#
252-
# for alt in alts:
253-
# assert_true(os.called)
254-
# assert_equal(os.call_args, (alt, {}))
255-
256217
@patch_object(os,'remove')
257218
deftest_alternates_setter_empty(self,os):
258219
self.repo.alternates= []
@@ -278,33 +239,6 @@ def test_log_with_path_and_options(self, git):
278239
assert_true(git.called)
279240
assert_equal(git.call_args, (('log','master','--','file.rb'), {'pretty':'raw','max_count':1}))
280241

281-
# @patch_object(Git, '_call_process')
282-
# @patch_object(Git, '_call_process')
283-
# def test_commit_deltas_from_nothing_new(self, gitb, gita):
284-
# gitb.return_value = fixture("rev_list_delta_b")
285-
# gita.return_value = fixture("rev_list_delta_a")
286-
# other_repo = Repo(GIT_REPO)
287-
# # self.repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
288-
# # other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
289-
#
290-
# delta_commits = self.repo.commit_deltas_from(other_repo)
291-
# assert_equal(0, len(delta_commits))
292-
# assert_true(gitb.called)
293-
# assert_equal(gitb.call_args, (('rev_list', 'master'), {}))
294-
# assert_true(gita.called)
295-
# assert_equal(gita.call_args, (('rev_list', 'master'), {}))
296-
#
297-
# def test_commit_deltas_from_when_other_has_new(self):
298-
# other_repo = Repo(GIT_REPO)
299-
# # self.repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_a"))
300-
# # other_repo.git.expects(:rev_list).with({}, "master").returns(fixture("rev_list_delta_b"))
301-
# # for ref in ['4c8124ffcf4039d292442eeccabdeca5af5c5017',
302-
# # '634396b2f541a9f2d58b00be1a07f0c358b999b3',
303-
# # 'ab25fd8483882c3bda8a458ad2965d2248654335']:
304-
# # Commit.expects(:find_all).with(other_repo, ref, :max_count => 1).returns([stub()])
305-
# delta_commits = self.repo.commit_deltas_from(other_repo)
306-
# assert_equal(3, len(delta_commits))
307-
308242
deftest_is_dirty_with_bare_repository(self):
309243
self.repo.bare=True
310244
assert_false(self.repo.is_dirty)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp