diff options
Diffstat (limited to 'git/index')
-rw-r--r-- | git/index/base.py | 9 | ||||
-rw-r--r-- | git/index/fun.py | 6 | ||||
-rw-r--r-- | git/index/typ.py | 4 | ||||
-rw-r--r-- | git/index/util.py | 6 |
4 files changed, 17 insertions, 8 deletions
diff --git a/git/index/base.py b/git/index/base.py index 9a3e80ea..601f1c0e 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -71,6 +71,7 @@ __all__ = ( 'IndexFile', 'CheckoutError' ) class IndexFile(LazyMixin, diff.Diffable, Serializable): + """ Implements an Index that can be manipulated using a native implementation in order to save git command function calls wherever possible. @@ -174,7 +175,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): (ignore_tree_extension_data and None) or self._extension_data) return self - #} END serializable interface def write(self, file_path = None, ignore_tree_extension_data=False): @@ -273,7 +273,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): inst.entries = entries return inst - @classmethod def from_tree(cls, repo, *treeish, **kwargs): """Merge the given treeish revisions into a new index which is returned. @@ -519,7 +518,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # copy changed trees only mdb.stream_copy(mdb.sha_iter(), self.repo.odb) - # note: additional deserialization could be saved if write_tree_from_cache # would return sorted tree entries root_tree = Tree(self.repo, binsha, path='') @@ -664,7 +662,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): del(paths[:]) # END rewrite paths - def store_path(filepath): """Store file at filepath in the database and return the base index entry""" st = os.lstat(filepath) # handles non-symlinks as well @@ -681,7 +678,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): istream.binsha, 0, to_native_path_linux(filepath))) # END utility method - # HANDLE PATHS if paths: assert len(entries_added) == 0 @@ -691,7 +687,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END for each filepath # END path handling - # HANDLE ENTRIES if entries: null_mode_entries = [ e for e in entries if e.mode == 0 ] @@ -866,7 +861,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return out # END handle dryrun - # now apply the actual operation kwargs.pop('dry_run') self.repo.git.mv(args, paths, **kwargs) @@ -989,7 +983,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): raise CheckoutError("Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons) # END stderr handler - if paths is None: args.append("--all") kwargs['as_process'] = 1 diff --git a/git/index/fun.py b/git/index/fun.py index ede7e43f..2fb09675 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -99,6 +99,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1 # write the sha over the content stream.write_sha() + def read_header(stream): """Return tuple(version_long, num_entries) from the given stream""" type_id = stream.read(4) @@ -110,6 +111,7 @@ def read_header(stream): assert version in (1, 2) return version, num_entries + def entry_key(*entry): """:return: Key suitable to be used for the index.entries dictionary :param entry: One instance of type BaseIndexEntry or the path and the stage""" @@ -119,6 +121,7 @@ def entry_key(*entry): return tuple(entry) # END handle entry + def read_cache(stream): """Read a cache file from the given stream :return: tuple(version, entries_dict, extension_data, content_sha) @@ -166,6 +169,7 @@ def read_cache(stream): return (version, entries, extension_data, content_sha) + def write_tree_from_cache(entries, odb, sl, si=0): """Create a tree from the given sorted list of entries and put the respective trees into the given object database @@ -221,9 +225,11 @@ def write_tree_from_cache(entries, odb, sl, si=0): istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) return (istream.binsha, tree_items) + def _tree_entry_to_baseindexentry(tree_entry, stage): return BaseIndexEntry((tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2])) + def aggressive_tree_merge(odb, tree_shas): """ :return: list of BaseIndexEntries representing the aggressive merge of the given diff --git a/git/index/typ.py b/git/index/typ.py index 97dff59e..2dd82b62 100644 --- a/git/index/typ.py +++ b/git/index/typ.py @@ -21,7 +21,9 @@ CE_STAGESHIFT = 12 #} END invariants + class BlobFilter(object): + """ Predicate to be used by iter_blobs allowing to filter only return blobs which match the given list of directories or files. @@ -47,6 +49,7 @@ class BlobFilter(object): class BaseIndexEntry(tuple): + """Small Brother of an index entry which can be created to describe changes done to the index in which case plenty of additional information is not requried. @@ -109,6 +112,7 @@ class BaseIndexEntry(tuple): class IndexEntry(BaseIndexEntry): + """Allows convenient access to IndexEntry data without completely unpacking it. Attributes usully accessed often are cached in the tuple whereas others are diff --git a/git/index/util.py b/git/index/util.py index 7211b4fc..289a3cb1 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -13,6 +13,7 @@ unpack = struct.unpack #} END aliases class TemporaryFileSwap(object): + """Utility class moving a file to a temporary location within the same directory and moving it back on to where on object deletion.""" __slots__ = ("file_path", "tmp_file_path") @@ -45,6 +46,7 @@ def post_clear_cache(func): This decorator will not be required once all functions are implemented natively which in fact is possible, but probably not feasible performance wise. """ + def post_clear_cache_if_not_raised(self, *args, **kwargs): rval = func(self, *args, **kwargs) self._delete_entries_cache() @@ -54,10 +56,12 @@ def post_clear_cache(func): post_clear_cache_if_not_raised.__name__ = func.__name__ return post_clear_cache_if_not_raised + def default_index(func): """Decorator assuring the wrapped method may only run if we are the default repository index. This is as we rely on git commands that operate on that index only. """ + def check_default_index(self, *args, **kwargs): if self._file_path != self._index_path(): raise AssertionError( "Cannot call %r on indices that do not represent the default git index" % func.__name__ ) @@ -67,9 +71,11 @@ def default_index(func): check_default_index.__name__ = func.__name__ return check_default_index + def git_working_dir(func): """Decorator which changes the current working dir to the one of the git repository in order to assure relative paths are handled correctly""" + def set_git_working_dir(self, *args, **kwargs): cur_wd = os.getcwd() os.chdir(self.repo.working_tree_dir) |