| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,15 @@ Index | |||
| 58 | 58 | creating several tree objects, so in the end it might be slower. | |
| 59 | 59 | Hmm, probably its okay to use the command unless we go c(++) | |
| 60 | 60 | ||
| 61 | + | ||
| 62 | + Head.reset | ||
| 63 | + ---------- | ||
| 64 | + * Should better be an instance method. Problem was that there is no class specifying | ||
| 65 | + the HEAD - in a way reset would always effect the active branch. | ||
| 66 | + Probably it would be okay to have a special type called SymbolicReference | ||
| 67 | + which represents items like HEAD. These could naturally carry the reset | ||
| 68 | + instance method. | ||
| 69 | + | ||
| 61 | 70 | Remote | |
| 62 | 71 | ------ | |
| 63 | 72 | * 'push' method needs a test, a true test repository is required though, a fork | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,12 @@ | |||
| 11 | 11 | import re | |
| 12 | 12 | import os | |
| 13 | 13 | import ConfigParser as cp | |
| 14 | - from git.odict import OrderedDict | ||
| 15 | 14 | import inspect | |
| 16 | 15 | import cStringIO | |
| 17 | 16 | ||
| 17 | + from git.odict import OrderedDict | ||
| 18 | + from git.utils import LockFile | ||
| 19 | + | ||
| 18 | 20 | class _MetaParserBuilder(type): | |
| 19 | 21 | """ | |
| 20 | 22 | Utlity class wrapping base-class methods into decorators that assure read-only properties | |
@@ -70,7 +72,7 @@ def flush_changes(self, *args, **kwargs): | |||
| 70 | 72 | ||
| 71 | 73 | ||
| 72 | 74 | ||
| 73 | - class GitConfigParser(cp.RawConfigParser, object): | ||
| 75 | + class GitConfigParser(cp.RawConfigParser, LockFile): | ||
| 74 | 76 | """ | |
| 75 | 77 | Implements specifics required to read git style configuration files. | |
| 76 | 78 | ||
@@ -100,6 +102,7 @@ class GitConfigParser(cp.RawConfigParser, object): | |||
| 100 | 102 | ||
| 101 | 103 | # list of RawConfigParser methods able to change the instance | |
| 102 | 104 | _mutating_methods_ = ("add_section", "remove_section", "remove_option", "set") | |
| 105 | + __slots__ = ("_sections", "_defaults", "_file_or_files", "_read_only","_is_initialized") | ||
| 103 | 106 | ||
| 104 | 107 | def __init__(self, file_or_files, read_only=True): | |
| 105 | 108 | """ | |
@@ -120,7 +123,6 @@ def __init__(self, file_or_files, read_only=True): | |||
| 120 | 123 | ||
| 121 | 124 | self._file_or_files = file_or_files | |
| 122 | 125 | self._read_only = read_only | |
| 123 | - self._owns_lock = False | ||
| 124 | 126 | self._is_initialized = False | |
| 125 | 127 | ||
| 126 | 128 | ||
@@ -129,10 +131,11 @@ def __init__(self, file_or_files, read_only=True): | |||
| 129 | 131 | raise ValueError("Write-ConfigParsers can operate on a single file only, multiple files have been passed") | |
| 130 | 132 | # END single file check | |
| 131 | 133 | ||
| 132 | - self._file_name = file_or_files | ||
| 133 | - if not isinstance(self._file_name, basestring): | ||
| 134 | - self._file_name = file_or_files.name | ||
| 135 | - # END get filename | ||
| 134 | + if not isinstance(file_or_files, basestring): | ||
| 135 | + file_or_files = file_or_files.name | ||
| 136 | + # END get filename from handle/stream | ||
| 137 | + # initialize lock base - we want to write | ||
| 138 | + LockFile.__init__(self, file_or_files) | ||
| 136 | 139 | ||
| 137 | 140 | self._obtain_lock_or_raise() | |
| 138 | 141 | # END read-only check | |
@@ -155,67 +158,6 @@ def __del__(self): | |||
| 155 | 158 | finally: | |
| 156 | 159 | self._release_lock() | |
| 157 | 160 | ||
| 158 | - def _lock_file_path(self): | ||
| 159 | - """ | ||
| 160 | - Return | ||
| 161 | - Path to lockfile | ||
| 162 | - """ | ||
| 163 | - return "%s.lock" % (self._file_name) | ||
| 164 | - | ||
| 165 | - def _has_lock(self): | ||
| 166 | - """ | ||
| 167 | - Return | ||
| 168 | - True if we have a lock and if the lockfile still exists | ||
| 169 | - | ||
| 170 | - Raise | ||
| 171 | - AssertionError if our lock-file does not exist | ||
| 172 | - """ | ||
| 173 | - if not self._owns_lock: | ||
| 174 | - return False | ||
| 175 | - | ||
| 176 | - lock_file = self._lock_file_path() | ||
| 177 | - try: | ||
| 178 | - fp = open(lock_file, "r") | ||
| 179 | - pid = int(fp.read()) | ||
| 180 | - fp.close() | ||
| 181 | - except IOError: | ||
| 182 | - raise AssertionError("GitConfigParser has a lock but the lock file at %s could not be read" % lock_file) | ||
| 183 | - | ||
| 184 | - if pid != os.getpid(): | ||
| 185 | - raise AssertionError("We claim to own the lock at %s, but it was not owned by our process: %i" % (lock_file, os.getpid())) | ||
| 186 | - | ||
| 187 | - return True | ||
| 188 | - | ||
| 189 | - def _obtain_lock_or_raise(self): | ||
| 190 | - """ | ||
| 191 | - Create a lock file as flag for other instances, mark our instance as lock-holder | ||
| 192 | - | ||
| 193 | - Raise | ||
| 194 | - IOError if a lock was already present or a lock file could not be written | ||
| 195 | - """ | ||
| 196 | - if self._has_lock(): | ||
| 197 | - return | ||
| 198 | - | ||
| 199 | - lock_file = self._lock_file_path() | ||
| 200 | - if os.path.exists(lock_file): | ||
| 201 | - raise IOError("Lock for file %r did already exist, delete %r in case the lock is illegal" % (self._file_name, lock_file)) | ||
| 202 | - | ||
| 203 | - fp = open(lock_file, "w") | ||
| 204 | - fp.write(str(os.getpid())) | ||
| 205 | - fp.close() | ||
| 206 | - | ||
| 207 | - self._owns_lock = True | ||
| 208 | - | ||
| 209 | - def _release_lock(self): | ||
| 210 | - """ | ||
| 211 | - Release our lock if we have one | ||
| 212 | - """ | ||
| 213 | - if not self._has_lock(): | ||
| 214 | - return | ||
| 215 | - | ||
| 216 | - os.remove(self._lock_file_path()) | ||
| 217 | - self._owns_lock = False | ||
| 218 | - | ||
| 219 | 161 | def optionxform(self, optionstr): | |
| 220 | 162 | """ | |
| 221 | 163 | Do not transform options in any way when writing | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,13 +18,18 @@ class Diffable(object): | |||
| 18 | 18 | """ | |
| 19 | 19 | __slots__ = tuple() | |
| 20 | 20 | ||
| 21 | - # subclasses provide additional arguments to the git-diff comamnd by supplynig | ||
| 22 | - # them in this tuple | ||
| 23 | - _diff_args = tuple() | ||
| 24 | - | ||
| 25 | - # Temporary standin for Index type until we have a real index type | ||
| 21 | + # standin indicating you want to diff against the index | ||
| 26 | 22 | class Index(object): | |
| 27 | 23 | pass | |
| 24 | + | ||
| 25 | + def _process_diff_args(self, args): | ||
| 26 | + """ | ||
| 27 | + Returns | ||
| 28 | + possibly altered version of the given args list. | ||
| 29 | + Method is called right before git command execution. | ||
| 30 | + Subclasses can use it to alter the behaviour of the superclass | ||
| 31 | + """ | ||
| 32 | + return args | ||
| 28 | 33 | ||
| 29 | 34 | def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |
| 30 | 35 | """ | |
@@ -60,13 +65,13 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 60 | 65 | On a bare repository, 'other' needs to be provided as Index or as | |
| 61 | 66 | as Tree/Commit, or a git command error will occour | |
| 62 | 67 | """ | |
| 63 | - args = list(self._diff_args[:]) | ||
| 68 | + args = list() | ||
| 64 | 69 | args.append( "--abbrev=40" ) # we need full shas | |
| 65 | 70 | args.append( "--full-index" ) # get full index paths, not only filenames | |
| 66 | 71 | ||
| 67 | 72 | if create_patch: | |
| 68 | 73 | args.append("-p") | |
| 69 | - args.append("-M") # check for renames | ||
| 74 | + args.append("-M") # check for renames | ||
| 70 | 75 | else: | |
| 71 | 76 | args.append("--raw") | |
| 72 | 77 | ||
@@ -87,7 +92,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 87 | 92 | # END paths handling | |
| 88 | 93 | ||
| 89 | 94 | kwargs['as_process'] = True | |
| 90 | - proc = self.repo.git.diff(*args, **kwargs) | ||
| 95 | + proc = self.repo.git.diff(*self._process_diff_args(args), **kwargs) | ||
| 91 | 96 | ||
| 92 | 97 | diff_method = Diff._index_from_raw_format | |
| 93 | 98 | if create_patch: | |
@@ -96,7 +101,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 96 | 101 | ||
| 97 | 102 | status = proc.wait() | |
| 98 | 103 | if status != 0: | |
| 99 | - raise GitCommandError("git-diff", status, proc.stderr ) | ||
| 104 | + raise GitCommandError(("git diff",)+tuple(args), status, proc.stderr.read()) | ||
| 100 | 105 | ||
| 101 | 106 | return index | |
| 102 | 107 | ||
@@ -207,6 +212,20 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, | |||
| 207 | 212 | ||
| 208 | 213 | self.diff = diff | |
| 209 | 214 | ||
| 215 | + | ||
| 216 | + def __eq__(self, other): | ||
| 217 | + for name in self.__slots__: | ||
| 218 | + if getattr(self, name) != getattr(other, name): | ||
| 219 | + return False | ||
| 220 | + # END for each name | ||
| 221 | + return True | ||
| 222 | + | ||
| 223 | + def __ne__(self, other): | ||
| 224 | + return not ( self == other ) | ||
| 225 | + | ||
| 226 | + def __hash__(self): | ||
| 227 | + return hash(tuple(getattr(self,n) for n in self.__slots__)) | ||
| 228 | + | ||
| 210 | 229 | @property | |
| 211 | 230 | def renamed(self): | |
| 212 | 231 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,8 @@ def __init__(self, command, status, stderr=None): | |||
| 25 | 25 | self.stderr = stderr | |
| 26 | 26 | self.status = status | |
| 27 | 27 | self.command = command | |
| 28 | - | ||
| 28 | + | ||
| 29 | 29 | def __str__(self): | |
| 30 | - return repr("'%s' returned exit status %d: %r" % | ||
| 31 | - (' '.join(self.command), self.status, str(self.stderr))) | ||
| 30 | + return ("'%s' returned exit status %i: %s" % | ||
| 31 | + (' '.join(str(i) for i in self.command), self.status, self.stderr)) | ||
| 32 | 32 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments