diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-07-20 16:18:01 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-07-20 16:18:01 +0200 |
commit | 192472f9673b18c91ce618e64e935f91769c50e7 (patch) | |
tree | 11fa568ea41d3856e6df605c8c8c8559fded3745 /lib/git | |
parent | 89422841e46efa99bda49acfbe33ee1ca5122845 (diff) | |
download | gitpython-192472f9673b18c91ce618e64e935f91769c50e7.tar.gz |
BaseIndexEntry: Added to_blob method, refactored functionality sligthly
repo.clone: assured backslashes won't reach the remote configuration, as it can cause trouble when re-reading the file later on. Some git commands don't appear to be able to properly deal with backslashes, other's do
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/index/base.py | 33 | ||||
-rw-r--r-- | lib/git/index/fun.py | 27 | ||||
-rw-r--r-- | lib/git/index/typ.py | 5 | ||||
-rw-r--r-- | lib/git/repo/base.py | 12 |
4 files changed, 50 insertions, 27 deletions
diff --git a/lib/git/index/base.py b/lib/git/index/base.py index ff01a3a4..86160990 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -12,14 +12,7 @@ import subprocess import glob from cStringIO import StringIO -from stat import ( - S_ISLNK, - S_ISDIR, - S_IFMT, - S_IFDIR, - S_IFLNK, - S_IFREG - ) +from stat import S_ISLNK from typ import ( BaseIndexEntry, @@ -65,7 +58,9 @@ from fun import ( write_cache, read_cache, aggressive_tree_merge, - write_tree_from_cache + write_tree_from_cache, + stat_mode_to_index_mode, + S_IFGITLINK ) from gitdb.base import IStream @@ -99,7 +94,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): before operating on it using the git command""" __slots__ = ("repo", "version", "entries", "_extension_data", "_file_path") _VERSION = 2 # latest version we support - S_IFGITLINK = 0160000 # a submodule + S_IFGITLINK = S_IFGITLINK # a submodule def __init__(self, repo, file_path=None): """Initialize this Index instance, optionally from the given ``file_path``. @@ -350,16 +345,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return index - @classmethod - def _stat_mode_to_index_mode(cls, mode): - """Convert the given mode from a stat call to the corresponding index mode - and return it""" - if S_ISLNK(mode): # symlinks - return S_IFLNK - if S_ISDIR(mode) or S_IFMT(mode) == cls.S_IFGITLINK: # submodules - return cls.S_IFGITLINK - return S_IFREG | 0644 | (mode & 0100) # blobs with or without executable bit - # UTILITIES def _iter_expand_paths(self, paths): """Expand the directories in list of paths to the corresponding paths accordingly, @@ -437,8 +422,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): for entry in self.entries.itervalues(): # TODO: is it necessary to convert the mode ? We did that when adding # it to the index, right ? - mode = self._stat_mode_to_index_mode(entry.mode) - blob = Blob(self.repo, entry.binsha, mode, entry.path) + mode = stat_mode_to_index_mode(entry.mode) + blob = entry.to_blob(self.repo) blob.size = entry.size output = (entry.stage, blob) if predicate(output): @@ -672,7 +657,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): abspath = os.path.abspath(path) gitrelative_path = abspath[len(self.repo.working_tree_dir)+1:] blob = Blob(self.repo, Blob.NULL_BIN_SHA, - self._stat_mode_to_index_mode(os.stat(abspath).st_mode), + stat_mode_to_index_mode(os.stat(abspath).st_mode), to_native_path_linux(gitrelative_path)) entries.append(BaseIndexEntry.from_blob(blob)) # END for each path @@ -692,7 +677,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): fprogress(filepath, False, filepath) istream = self.repo.odb.store(IStream(Blob.type, st.st_size, stream)) fprogress(filepath, True, filepath) - return BaseIndexEntry((self._stat_mode_to_index_mode(st.st_mode), + return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode), istream.binsha, 0, to_native_path_linux(filepath))) # END utility method diff --git a/lib/git/index/fun.py b/lib/git/index/fun.py index 4478228a..48c4fa74 100644 --- a/lib/git/index/fun.py +++ b/lib/git/index/fun.py @@ -2,7 +2,18 @@ Contains standalone functions to accompany the index implementation and make it more versatile """ -from stat import S_IFDIR +from stat import ( + S_IFDIR, + S_IFLNK, + S_ISLNK, + S_IFDIR, + S_ISDIR, + S_IFMT, + S_IFREG, + ) + +S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule + from cStringIO import StringIO from git.util import IndexFileSHA1Writer @@ -28,7 +39,19 @@ from util import ( from gitdb.base import IStream from gitdb.typ import str_tree_type -__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key' ) +__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key', + 'stat_mode_to_index_mode', 'S_IFGITLINK') + + +def stat_mode_to_index_mode(mode): + """Convert the given mode from a stat call to the corresponding index mode + and return it""" + if S_ISLNK(mode): # symlinks + return S_IFLNK + if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules + return S_IFGITLINK + return S_IFREG | 0644 | (mode & 0100) # blobs with or without executable bit + def write_cache_entry(entry, stream): """Write the given entry to the stream""" diff --git a/lib/git/index/typ.py b/lib/git/index/typ.py index 3a01cd65..ad988285 100644 --- a/lib/git/index/typ.py +++ b/lib/git/index/typ.py @@ -9,6 +9,7 @@ from binascii import ( b2a_hex, ) +from git.objects import Blob __all__ = ('BlobFilter', 'BaseIndexEntry', 'IndexEntry') #{ Invariants @@ -101,6 +102,10 @@ class BaseIndexEntry(tuple): def from_blob(cls, blob, stage = 0): """:return: Fully equipped BaseIndexEntry at the given stage""" return cls((blob.mode, blob.binsha, stage << CE_STAGESHIFT, blob.path)) + + def to_blob(self, repo): + """:return: Blob using the information of this index entry""" + return Blob(repo, self.binsha, self.mode, self.path) class IndexEntry(BaseIndexEntry): diff --git a/lib/git/repo/base.py b/lib/git/repo/base.py index 4456b1e9..790b1283 100644 --- a/lib/git/repo/base.py +++ b/lib/git/repo/base.py @@ -651,7 +651,17 @@ class Repo(object): # environment, hence we prepend its working dir if required if not os.path.isabs(path) and git.working_dir: path = join(git._working_dir, path) - return cls(os.path.abspath(path), odbt = odbt) + + # adjust remotes - there may be operating systems which use backslashes, + # These might be given as initial paths, but when handling the config file + # that contains the remote from which we were clones, git stops liking it + # as it will escape the backslashes. Hence we undo the escaping just to be + # sure + repo = cls(os.path.abspath(path), odbt = odbt) + if repo.remotes: + repo.remotes[0].config_writer.set_value('url', repo.remotes[0].url.replace("\\\\", "\\").replace("\\", "/")) + # END handle remote repo + return repo def clone(self, path, **kwargs): """Create a clone from this repository. |