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

Commit600fcbc

Browse files
committed
Repo: Added comparison operators and hash operator including test
Cmd: AutoInterrupt handles boundary cases more gracefully as it can be that the os module suddenly becomes None if the interpreter is going down
1 parent8caeec1 commit600fcbc

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

‎lib/git/cmd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ def __init__(self, proc, args ):
6363
def__del__(self):
6464
# did the process finish already so we have a return code ?
6565
ifself.proc.poll()isnotNone:
66-
return
67-
66+
return
67+
68+
# can be that nothing really exists anymore ...
69+
ifosisNone:
70+
return
71+
6872
# try to kill it
6973
try:
7074
os.kill(self.proc.pid,2)# interrupt signal

‎lib/git/repo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ def __init__(self, path=None):
131131
self.working_dir=self._working_tree_dirorself.git_dir
132132
self.git=Git(self.working_dir)
133133

134+
def__eq__(self,rhs):
135+
ifisinstance(rhs,Repo):
136+
returnself.git_dir==rhs.git_dir
137+
returnFalse
138+
139+
def__ne__(self,rhs):
140+
returnnotself.__eq__(rhs)
141+
142+
def__hash__(self):
143+
returnhash(self.git_dir)
144+
145+
def__repr__(self):
146+
return"%s(%r)"% (type(self).__name__,self.git_dir)
147+
134148
# Description property
135149
def_get_description(self):
136150
filename=os.path.join(self.git_dir,'description')
@@ -145,6 +159,8 @@ def _set_description(self, descr):
145159
del_get_description
146160
del_set_description
147161

162+
163+
148164
@property
149165
defworking_tree_dir(self):
150166
"""

‎test/git/test_index.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def test_index_file_from_tree(self):
147147

148148
@with_rw_repo('0.1.6')
149149
deftest_index_merge_tree(self,rw_repo):
150+
# A bit out of place, but we need a different repo for this:
151+
assertself.rorepo!=rw_repoandnot (self.rorepo==rw_repo)
152+
assertlen(set((self.rorepo,self.rorepo,rw_repo,rw_repo)))==2
153+
150154
# SINGLE TREE MERGE
151155
# current index is at the (virtual) cur_commit
152156
next_commit="4c39f9da792792d4e73fc3a5effde66576ae128c"
@@ -546,10 +550,10 @@ def make_paths():
546550
yieldindex.entries[index.get_entries_key('.gitignore',0)]
547551

548552
forfidinrange(3):
549-
fname='newfile%i'%fid
550-
open(fname,'wb').write("abcd")
551-
yieldBlob(rw_repo,Blob.NULL_HEX_SHA,0100644,fname)
552-
# END for each new file
553+
fname='newfile%i'%fid
554+
open(fname,'wb').write("abcd")
555+
yieldBlob(rw_repo,Blob.NULL_HEX_SHA,0100644,fname)
556+
# END for each new file
553557
# END path producer
554558
paths=list(make_paths())
555559
index.add(paths,path_rewriter=rewriter)

‎test/git/test_repo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _test_empty_repo(self, repo):
115115

116116
# we can add a file to the index ( if we are not bare )
117117
ifnotrepo.bare:
118-
pass
118+
pass
119119
# END test repos with working tree
120120

121121

@@ -327,3 +327,8 @@ def test_creation_deletion(self):
327327

328328
remote=self.rorepo.create_remote("new_remote","git@server:repo.git")
329329
self.rorepo.delete_remote(remote)
330+
331+
deftest_comparison_and_hash(self):
332+
# this is only a preliminary test, more testing done in test_index
333+
assertself.rorepo==self.rorepoandnot (self.rorepo!=self.rorepo)
334+
assertlen(set((self.rorepo,self.rorepo)))==1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp