Skip to content

Commit 600fcbc

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 parent 8caeec1 commit 600fcbc

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
if self.proc.poll() is not None:
66-
return
67-
66+
return
67+
68+
# can be that nothing really exists anymore ...
69+
if os is None:
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_dir or self.git_dir
132132
self.git = Git(self.working_dir)
133133

134+
def __eq__(self, rhs):
135+
if isinstance(rhs, Repo):
136+
return self.git_dir == rhs.git_dir
137+
return False
138+
139+
def __ne__(self, rhs):
140+
return not self.__eq__(rhs)
141+
142+
def __hash__(self):
143+
return hash(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
def working_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
def test_index_merge_tree(self, rw_repo):
150+
# A bit out of place, but we need a different repo for this:
151+
assert self.rorepo != rw_repo and not (self.rorepo == rw_repo)
152+
assert len(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
yield index.entries[index.get_entries_key('.gitignore', 0)]
547551

548552
for fid in range(3):
549-
fname = 'newfile%i' % fid
550-
open(fname, 'wb').write("abcd")
551-
yield Blob(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+
yield Blob(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
if not repo.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+
def test_comparison_and_hash(self):
332+
# this is only a preliminary test, more testing done in test_index
333+
assert self.rorepo == self.rorepo and not (self.rorepo != self.rorepo)
334+
assert len(set((self.rorepo, self.rorepo))) == 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy