| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,11 +23,13 @@ | |||
| 23 | 23 | ||
| 24 | 24 | __all__ = ('Git', ) | |
| 25 | 25 | ||
| 26 | + | ||
| 26 | 27 | def dashify(string): | |
| 27 | 28 | return string.replace('_', '-') | |
| 28 | 29 | ||
| 29 | 30 | ||
| 30 | 31 | class Git(LazyMixin): | |
| 32 | + | ||
| 31 | 33 | """ | |
| 32 | 34 | The Git class manages communication with the Git binary. | |
| 33 | 35 | ||
@@ -59,8 +61,8 @@ class Git(LazyMixin): | |||
| 59 | 61 | _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE" | |
| 60 | 62 | GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name) | |
| 61 | 63 | ||
| 62 | - | ||
| 63 | 64 | class AutoInterrupt(object): | |
| 65 | + | ||
| 64 | 66 | """Kill/Interrupt the stored process instance once this instance goes out of scope. It is | |
| 65 | 67 | used to prevent processes piling up in case iterators stop reading. | |
| 66 | 68 | Besides all attributes are wired through to the contained process object. | |
@@ -114,6 +116,7 @@ def wait(self): | |||
| 114 | 116 | # END auto interrupt | |
| 115 | 117 | ||
| 116 | 118 | class CatFileContentStream(object): | |
| 119 | + | ||
| 117 | 120 | """Object representing a sized read-only stream returning the contents of | |
| 118 | 121 | an object. | |
| 119 | 122 | It behaves like a stream, but counts the data read and simulates an empty | |
@@ -213,7 +216,6 @@ def __del__(self): | |||
| 213 | 216 | self._stream.read(bytes_left + 1) | |
| 214 | 217 | # END handle incomplete read | |
| 215 | 218 | ||
| 216 | - | ||
| 217 | 219 | def __init__(self, working_dir=None): | |
| 218 | 220 | """Initialize this instance with: | |
| 219 | 221 | ||
@@ -247,7 +249,6 @@ def _set_cache_(self, attr): | |||
| 247 | 249 | super(Git, self)._set_cache_(attr) | |
| 248 | 250 | #END handle version info | |
| 249 | 251 | ||
| 250 | - | ||
| 251 | 252 | @property | |
| 252 | 253 | def working_dir(self): | |
| 253 | 254 | """:return: Git directory we are working on""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,9 @@ | |||
| 17 | 17 | ||
| 18 | 18 | __all__ = ('GitConfigParser', 'SectionConstraint') | |
| 19 | 19 | ||
| 20 | + | ||
| 20 | 21 | class MetaParserBuilder(type): | |
| 22 | + | ||
| 21 | 23 | """Utlity class wrapping base-class methods into decorators that assure read-only properties""" | |
| 22 | 24 | def __new__(metacls, name, bases, clsdict): | |
| 23 | 25 | """ | |
@@ -45,20 +47,22 @@ def __new__(metacls, name, bases, clsdict): | |||
| 45 | 47 | return new_type | |
| 46 | 48 | ||
| 47 | 49 | ||
| 48 | - | ||
| 49 | 50 | def needs_values(func): | |
| 50 | 51 | """Returns method assuring we read values (on demand) before we try to access them""" | |
| 52 | + | ||
| 51 | 53 | def assure_data_present(self, *args, **kwargs): | |
| 52 | 54 | self.read() | |
| 53 | 55 | return func(self, *args, **kwargs) | |
| 54 | 56 | # END wrapper method | |
| 55 | 57 | assure_data_present.__name__ = func.__name__ | |
| 56 | 58 | return assure_data_present | |
| 57 | 59 | ||
| 60 | + | ||
| 58 | 61 | def set_dirty_and_flush_changes(non_const_func): | |
| 59 | 62 | """Return method that checks whether given non constant function may be called. | |
| 60 | 63 | If so, the instance will be set dirty. | |
| 61 | 64 | Additionally, we flush the changes right to disk""" | |
| 65 | + | ||
| 62 | 66 | def flush_changes(self, *args, **kwargs): | |
| 63 | 67 | rval = non_const_func(self, *args, **kwargs) | |
| 64 | 68 | self.write() | |
@@ -69,6 +73,7 @@ def flush_changes(self, *args, **kwargs): | |||
| 69 | 73 | ||
| 70 | 74 | ||
| 71 | 75 | class SectionConstraint(object): | |
| 76 | + | ||
| 72 | 77 | """Constrains a ConfigParser to only option commands which are constrained to | |
| 73 | 78 | always use the section we have been initialized with. | |
| 74 | 79 | ||
@@ -98,6 +103,7 @@ def config(self): | |||
| 98 | 103 | ||
| 99 | 104 | ||
| 100 | 105 | class GitConfigParser(cp.RawConfigParser, object): | |
| 106 | + | ||
| 101 | 107 | """Implements specifics required to read git style configuration files. | |
| 102 | 108 | ||
| 103 | 109 | This variation behaves much like the git.config command such that the configuration | |
@@ -114,7 +120,6 @@ class GitConfigParser(cp.RawConfigParser, object): | |||
| 114 | 120 | must match perfectly.""" | |
| 115 | 121 | __metaclass__ = MetaParserBuilder | |
| 116 | 122 | ||
| 117 | - | ||
| 118 | 123 | #{ Configuration | |
| 119 | 124 | # The lock type determines the type of lock to use in new configuration readers. | |
| 120 | 125 | # They must be compatible to the LockFile interface. | |
@@ -172,7 +177,6 @@ def __init__(self, file_or_files, read_only=True): | |||
| 172 | 177 | self._lock._obtain_lock() | |
| 173 | 178 | # END read-only check | |
| 174 | 179 | ||
| 175 | - | ||
| 176 | 180 | def __del__(self): | |
| 177 | 181 | """Write pending changes if required and release locks""" | |
| 178 | 182 | # checking for the lock here makes sure we do not raise during write() | |
@@ -261,7 +265,6 @@ def _read(self, fp, fpname): | |||
| 261 | 265 | if e: | |
| 262 | 266 | raise e | |
| 263 | 267 | ||
| 264 | - | ||
| 265 | 268 | def read(self): | |
| 266 | 269 | """Reads the data stored in the files we have been initialized with. It will | |
| 267 | 270 | ignore files that cannot be read, possibly leaving an empty configuration | |
@@ -311,7 +314,6 @@ def write_section(name, section_dict): | |||
| 311 | 314 | write_section(cp.DEFAULTSECT, self._defaults) | |
| 312 | 315 | map(lambda t: write_section(t[0],t[1]), self._sections.items()) | |
| 313 | 316 | ||
| 314 | - | ||
| 315 | 317 | @needs_values | |
| 316 | 318 | def write(self): | |
| 317 | 319 | """Write changes to our file, if there are changes at all | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,14 +20,18 @@ | |||
| 20 | 20 | __all__ = ('GitCmdObjectDB', 'GitDB' ) | |
| 21 | 21 | ||
| 22 | 22 | #class GitCmdObjectDB(CompoundDB, ObjectDBW): | |
| 23 | + | ||
| 24 | + | ||
| 23 | 25 | class GitCmdObjectDB(LooseObjectDB): | |
| 26 | + | ||
| 24 | 27 | """A database representing the default git object store, which includes loose | |
| 25 | 28 | objects, pack files and an alternates file | |
| 26 | 29 | ||
| 27 | 30 | It will create objects only in the loose object database. | |
| 28 | 31 | :note: for now, we use the git command to do all the lookup, just until he | |
| 29 | 32 | have packs and the other implementations | |
| 30 | 33 | """ | |
| 34 | + | ||
| 31 | 35 | def __init__(self, root_path, git): | |
| 32 | 36 | """Initialize this instance with the root and a git command""" | |
| 33 | 37 | super(GitCmdObjectDB, self).__init__(root_path) | |
@@ -42,7 +46,6 @@ def stream(self, sha): | |||
| 42 | 46 | hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha)) | |
| 43 | 47 | return OStream(hex_to_bin(hexsha), typename, size, stream) | |
| 44 | 48 | ||
| 45 | - | ||
| 46 | 49 | # { Interface | |
| 47 | 50 | ||
| 48 | 51 | def partial_to_complete_sha_hex(self, partial_hexsha): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,9 @@ | |||
| 14 | 14 | ||
| 15 | 15 | __all__ = ('Diffable', 'DiffIndex', 'Diff') | |
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | class Diffable(object): | |
| 19 | + | ||
| 18 | 20 | """Common interface for all object that can be diffed against another object of compatible type. | |
| 19 | 21 | ||
| 20 | 22 | :note: | |
@@ -109,6 +111,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 109 | 111 | ||
| 110 | 112 | ||
| 111 | 113 | class DiffIndex(list): | |
| 114 | + | ||
| 112 | 115 | """Implements an Index for diffs, allowing a list of Diffs to be queried by | |
| 113 | 116 | the diff properties. | |
| 114 | 117 | ||
@@ -120,7 +123,6 @@ class DiffIndex(list): | |||
| 120 | 123 | # M = modified | |
| 121 | 124 | change_type = ("A", "D", "R", "M") | |
| 122 | 125 | ||
| 123 | - | ||
| 124 | 126 | def iter_change_type(self, change_type): | |
| 125 | 127 | """ | |
| 126 | 128 | :return: | |
@@ -149,6 +151,7 @@ def iter_change_type(self, change_type): | |||
| 149 | 151 | ||
| 150 | 152 | ||
| 151 | 153 | class Diff(object): | |
| 154 | + | ||
| 152 | 155 | """A Diff contains diff information between two Trees. | |
| 153 | 156 | ||
| 154 | 157 | It contains two sides a and b of the diff, members are prefixed with | |
@@ -228,7 +231,6 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, | |||
| 228 | 231 | ||
| 229 | 232 | self.diff = diff | |
| 230 | 233 | ||
| 231 | - | ||
| 232 | 234 | def __eq__(self, other): | |
| 233 | 235 | for name in self.__slots__: | |
| 234 | 236 | if getattr(self, name) != getattr(other, name): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,16 +7,21 @@ | |||
| 7 | 7 | ||
| 8 | 8 | from gitdb.exc import * | |
| 9 | 9 | ||
| 10 | + | ||
| 10 | 11 | class InvalidGitRepositoryError(Exception): | |
| 12 | + | ||
| 11 | 13 | """ Thrown if the given repository appears to have an invalid format. """ | |
| 12 | 14 | ||
| 13 | 15 | ||
| 14 | 16 | class NoSuchPathError(OSError): | |
| 17 | + | ||
| 15 | 18 | """ Thrown if a path could not be access by the system. """ | |
| 16 | 19 | ||
| 17 | 20 | ||
| 18 | 21 | class GitCommandError(Exception): | |
| 22 | + | ||
| 19 | 23 | """ Thrown if execution of the git command fails with non-zero status code. """ | |
| 24 | + | ||
| 20 | 25 | def __init__(self, command, status, stderr=None, stdout=None): | |
| 21 | 26 | self.stderr = stderr | |
| 22 | 27 | self.stdout = stdout | |
@@ -32,6 +37,7 @@ def __str__(self): | |||
| 32 | 37 | ||
| 33 | 38 | ||
| 34 | 39 | class CheckoutError( Exception ): | |
| 40 | + | ||
| 35 | 41 | """Thrown if a file could not be checked out from the index as it contained | |
| 36 | 42 | changes. | |
| 37 | 43 | ||
@@ -44,6 +50,7 @@ class CheckoutError( Exception ): | |||
| 44 | 50 | The .valid_files attribute contains a list of relative paths to files that | |
| 45 | 51 | were checked out successfully and hence match the version stored in the | |
| 46 | 52 | index""" | |
| 53 | + | ||
| 47 | 54 | def __init__(self, message, failed_files, valid_files, failed_reasons): | |
| 48 | 55 | Exception.__init__(self, message) | |
| 49 | 56 | self.failed_files = failed_files | |
@@ -55,8 +62,11 @@ def __str__(self): | |||
| 55 | 62 | ||
| 56 | 63 | ||
| 57 | 64 | class CacheError(Exception): | |
| 65 | + | ||
| 58 | 66 | """Base for all errors related to the git index, which is called cache internally""" | |
| 59 | 67 | ||
| 68 | + | ||
| 60 | 69 | class UnmergedEntriesError(CacheError): | |
| 70 | + | ||
| 61 | 71 | """Thrown if an operation cannot proceed as there are still unmerged | |
| 62 | 72 | entries in the cache""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,6 +71,7 @@ | |||
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | 73 | class IndexFile(LazyMixin, diff.Diffable, Serializable): | |
| 74 | + | ||
| 74 | 75 | """ | |
| 75 | 76 | Implements an Index that can be manipulated using a native implementation in | |
| 76 | 77 | order to save git command function calls wherever possible. | |
@@ -174,7 +175,6 @@ def _serialize(self, stream, ignore_tree_extension_data=False): | |||
| 174 | 175 | (ignore_tree_extension_data and None) or self._extension_data) | |
| 175 | 176 | return self | |
| 176 | 177 | ||
| 177 | - | ||
| 178 | 178 | #} END serializable interface | |
| 179 | 179 | ||
| 180 | 180 | def write(self, file_path = None, ignore_tree_extension_data=False): | |
@@ -273,7 +273,6 @@ def new(cls, repo, *tree_sha): | |||
| 273 | 273 | inst.entries = entries | |
| 274 | 274 | return inst | |
| 275 | 275 | ||
| 276 | - | ||
| 277 | 276 | @classmethod | |
| 278 | 277 | def from_tree(cls, repo, *treeish, **kwargs): | |
| 279 | 278 | """Merge the given treeish revisions into a new index which is returned. | |
@@ -519,7 +518,6 @@ def write_tree(self): | |||
| 519 | 518 | # copy changed trees only | |
| 520 | 519 | mdb.stream_copy(mdb.sha_iter(), self.repo.odb) | |
| 521 | 520 | ||
| 522 | - | ||
| 523 | 521 | # note: additional deserialization could be saved if write_tree_from_cache | |
| 524 | 522 | # would return sorted tree entries | |
| 525 | 523 | root_tree = Tree(self.repo, binsha, path='') | |
@@ -664,7 +662,6 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non | |||
| 664 | 662 | del(paths[:]) | |
| 665 | 663 | # END rewrite paths | |
| 666 | 664 | ||
| 667 | - | ||
| 668 | 665 | def store_path(filepath): | |
| 669 | 666 | """Store file at filepath in the database and return the base index entry""" | |
| 670 | 667 | st = os.lstat(filepath) # handles non-symlinks as well | |
@@ -681,7 +678,6 @@ def store_path(filepath): | |||
| 681 | 678 | istream.binsha, 0, to_native_path_linux(filepath))) | |
| 682 | 679 | # END utility method | |
| 683 | 680 | ||
| 684 | - | ||
| 685 | 681 | # HANDLE PATHS | |
| 686 | 682 | if paths: | |
| 687 | 683 | assert len(entries_added) == 0 | |
@@ -691,7 +687,6 @@ def store_path(filepath): | |||
| 691 | 687 | # END for each filepath | |
| 692 | 688 | # END path handling | |
| 693 | 689 | ||
| 694 | - | ||
| 695 | 690 | # HANDLE ENTRIES | |
| 696 | 691 | if entries: | |
| 697 | 692 | null_mode_entries = [ e for e in entries if e.mode == 0 ] | |
@@ -866,7 +861,6 @@ def move(self, items, skip_errors=False, **kwargs): | |||
| 866 | 861 | return out | |
| 867 | 862 | # END handle dryrun | |
| 868 | 863 | ||
| 869 | - | ||
| 870 | 864 | # now apply the actual operation | |
| 871 | 865 | kwargs.pop('dry_run') | |
| 872 | 866 | self.repo.git.mv(args, paths, **kwargs) | |
@@ -989,7 +983,6 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 989 | 983 | raise CheckoutError("Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons) | |
| 990 | 984 | # END stderr handler | |
| 991 | 985 | ||
| 992 | - | ||
| 993 | 986 | if paths is None: | |
| 994 | 987 | args.append("--all") | |
| 995 | 988 | kwargs['as_process'] = 1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,6 +99,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1 | |||
| 99 | 99 | # write the sha over the content | |
| 100 | 100 | stream.write_sha() | |
| 101 | 101 | ||
| 102 | + | ||
| 102 | 103 | def read_header(stream): | |
| 103 | 104 | """Return tuple(version_long, num_entries) from the given stream""" | |
| 104 | 105 | type_id = stream.read(4) | |
@@ -110,6 +111,7 @@ def read_header(stream): | |||
| 110 | 111 | assert version in (1, 2) | |
| 111 | 112 | return version, num_entries | |
| 112 | 113 | ||
| 114 | + | ||
| 113 | 115 | def entry_key(*entry): | |
| 114 | 116 | """:return: Key suitable to be used for the index.entries dictionary | |
| 115 | 117 | :param entry: One instance of type BaseIndexEntry or the path and the stage""" | |
@@ -119,6 +121,7 @@ def entry_key(*entry): | |||
| 119 | 121 | return tuple(entry) | |
| 120 | 122 | # END handle entry | |
| 121 | 123 | ||
| 124 | + | ||
| 122 | 125 | def read_cache(stream): | |
| 123 | 126 | """Read a cache file from the given stream | |
| 124 | 127 | :return: tuple(version, entries_dict, extension_data, content_sha) | |
@@ -166,6 +169,7 @@ def read_cache(stream): | |||
| 166 | 169 | ||
| 167 | 170 | return (version, entries, extension_data, content_sha) | |
| 168 | 171 | ||
| 172 | + | ||
| 169 | 173 | def write_tree_from_cache(entries, odb, sl, si=0): | |
| 170 | 174 | """Create a tree from the given sorted list of entries and put the respective | |
| 171 | 175 | trees into the given object database | |
@@ -221,9 +225,11 @@ def write_tree_from_cache(entries, odb, sl, si=0): | |||
| 221 | 225 | istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) | |
| 222 | 226 | return (istream.binsha, tree_items) | |
| 223 | 227 | ||
| 228 | + | ||
| 224 | 229 | def _tree_entry_to_baseindexentry(tree_entry, stage): | |
| 225 | 230 | return BaseIndexEntry((tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2])) | |
| 226 | 231 | ||
| 232 | + | ||
| 227 | 233 | def aggressive_tree_merge(odb, tree_shas): | |
| 228 | 234 | """ | |
| 229 | 235 | :return: list of BaseIndexEntries representing the aggressive merge of the given | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,9 @@ | |||
| 21 | 21 | ||
| 22 | 22 | #} END invariants | |
| 23 | 23 | ||
| 24 | + | ||
| 24 | 25 | class BlobFilter(object): | |
| 26 | + | ||
| 25 | 27 | """ | |
| 26 | 28 | Predicate to be used by iter_blobs allowing to filter only return blobs which | |
| 27 | 29 | match the given list of directories or files. | |
@@ -47,6 +49,7 @@ def __call__(self, stage_blob): | |||
| 47 | 49 | ||
| 48 | 50 | ||
| 49 | 51 | class BaseIndexEntry(tuple): | |
| 52 | + | ||
| 50 | 53 | """Small Brother of an index entry which can be created to describe changes | |
| 51 | 54 | done to the index in which case plenty of additional information is not requried. | |
| 52 | 55 | ||
@@ -109,6 +112,7 @@ def to_blob(self, repo): | |||
| 109 | 112 | ||
| 110 | 113 | ||
| 111 | 114 | class IndexEntry(BaseIndexEntry): | |
| 115 | + | ||
| 112 | 116 | """Allows convenient access to IndexEntry data without completely unpacking it. | |
| 113 | 117 | ||
| 114 | 118 | Attributes usully accessed often are cached in the tuple whereas others are | |
| Back | FazBrowse Home | New Git URL |
0 commit comments