diff options
-rw-r--r-- | lib/git/index.py | 18 | ||||
-rw-r--r-- | lib/git/utils.py | 6 | ||||
-rw-r--r-- | test/git/test_index.py | 6 | ||||
-rw-r--r-- | test/git/test_utils.py | 4 |
4 files changed, 20 insertions, 14 deletions
diff --git a/lib/git/index.py b/lib/git/index.py index 747ccc88..45bf617f 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -36,7 +36,7 @@ class _TemporaryFileSwap(object): def __del__(self): if os.path.isfile(self.tmp_file_path): - if sys.platform == "win32" and os.path.exists(self.file_path): + if os.name == 'nt' and os.path.exists(self.file_path): os.remove(self.file_path) os.rename(self.tmp_file_path, self.file_path) # END temp file exists @@ -243,9 +243,10 @@ class IndexFile(LazyMixin, diff.Diffable): if attr == "entries": # read the current index # try memory map for speed - fp = open(self._file_path, "r") + fp = open(self._file_path, "rb") stream = fp try: + raise Exception() stream = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) except Exception: pass @@ -254,7 +255,12 @@ class IndexFile(LazyMixin, diff.Diffable): try: self._read_from_stream(stream) finally: - fp.close() + pass + # make sure we close the stream ( possibly an mmap ) + # and the file + #stream.close() + #if stream is not fp: + # fp.close() # END read from default index on demand else: super(IndexFile, self)._set_cache_(attr) @@ -603,7 +609,7 @@ class IndexFile(LazyMixin, diff.Diffable): """ if not os.path.isabs(path): return path - relative_path = path.replace(self.repo.git.git_dir+"/", "") + relative_path = path.replace(self.repo.git.git_dir+os.sep, "") if relative_path == path: raise ValueError("Absolute path %r is not in git repository at %r" % (path,self.repo.git.git_dir)) return relative_path @@ -839,10 +845,10 @@ class IndexFile(LazyMixin, diff.Diffable): # create message stream tmp_file_path = tempfile.mktemp() - fp = open(tmp_file_path,"w") + fp = open(tmp_file_path,"wb") fp.write(str(message)) fp.close() - fp = open(tmp_file_path,"r") + fp = open(tmp_file_path,"rb") fp.seek(0) try: diff --git a/lib/git/utils.py b/lib/git/utils.py index 4397fbb2..5deed556 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -131,7 +131,7 @@ class LockFile(object): lock_file = self._lock_file_path() try: - fp = open(lock_file, "r") + fp = open(lock_file, "rb") pid = int(fp.read()) fp.close() except IOError: @@ -156,7 +156,7 @@ class LockFile(object): if os.path.exists(lock_file): raise IOError("Lock for file %r did already exist, delete %r in case the lock is illegal" % (self._file_path, lock_file)) - fp = open(lock_file, "w") + fp = open(lock_file, "wb") fp.write(str(os.getpid())) fp.close() @@ -212,7 +212,7 @@ class ConcurrentWriteOperation(LockFile): self._obtain_lock_or_raise() dirname, basename = os.path.split(self._file_path) - self._temp_write_fp = open(tempfile.mktemp(basename, '', dirname), "w") + self._temp_write_fp = open(tempfile.mktemp(basename, '', dirname), "wb") return self._temp_write_fp def _is_writing(self): diff --git a/test/git/test_index.py b/test/git/test_index.py index e9541232..6f57538f 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -42,7 +42,7 @@ class TestTree(TestBase): # write the data - it must match the original tmpfile = tempfile.mktemp() index_merge.write(tmpfile) - fp = open(tmpfile, 'r') + fp = open(tmpfile, 'rb') assert fp.read() == fixture("index_merge") fp.close() os.remove(tmpfile) @@ -164,14 +164,14 @@ class TestTree(TestBase): # reset the working copy as well to current head,to pull 'back' as well new_data = "will be reverted" file_path = os.path.join(rw_repo.git.git_dir, "CHANGES") - fp = open(file_path, "w") + fp = open(file_path, "wb") fp.write(new_data) fp.close() index.reset(rev_head_parent, working_tree=True) assert not index.diff(None) assert cur_branch == rw_repo.active_branch assert cur_commit == rw_repo.head.commit - fp = open(file_path) + fp = open(file_path,'rb') try: assert fp.read() != new_data finally: diff --git a/test/git/test_utils.py b/test/git/test_utils.py index 029d2054..69a9297d 100644 --- a/test/git/test_utils.py +++ b/test/git/test_utils.py @@ -56,7 +56,7 @@ class TestUtils(TestCase): def _cmp_contents(self, file_path, data): # raise if data from file at file_path # does not match data string - fp = open(file_path, "r") + fp = open(file_path, "rb") try: assert fp.read() == data finally: @@ -66,7 +66,7 @@ class TestUtils(TestCase): my_file = tempfile.mktemp() orig_data = "hello" new_data = "world" - my_file_fp = open(my_file, "w") + my_file_fp = open(my_file, "wb") my_file_fp.write(orig_data) my_file_fp.close() |