| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dbc18b9 commit 3cb5ba1
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,15 +27,6 @@ Object | |||
| 27 | 27 | It would be good to improve things there as cat-file keeps all the data in a buffer | |
| 28 | 28 | before it writes it. Hence it does not write to a stream directly, which can be | |
| 29 | 29 | bad if files are large, say 1GB :). | |
| 30 | - * Effectively Objects only store hexsha's in their id attributes, so in fact | ||
| 31 | - it should be renamed to 'sha'. There was a time when references where allowed as | ||
| 32 | - well, but now objects will be 'baked' to the actual sha to assure comparisons work. | ||
| 33 | - | ||
| 34 | - Commit | ||
| 35 | - ------ | ||
| 36 | - * message is stipped during parsing, which is wrong unless we parse from | ||
| 37 | - rev-list output. In fact we don't know that, and can't really tell either. | ||
| 38 | - Currently we strip away white space that might actually belong to the message | ||
| 39 | 30 | ||
| 40 | 31 | Config | |
| 41 | 32 | ------ | |
@@ -115,7 +106,9 @@ Repo | |||
| 115 | 106 | * Blame: Read the blame format making assumptions about its structure, | |
| 116 | 107 | currently regex are used a lot although we can deduct what will be next. | |
| 117 | 108 | - Read data from a stream directly from git command | |
| 118 | - * Figure out how to implement a proper merge API | ||
| 109 | + * Figure out how to implement a proper merge API. It should be index based, but provide | ||
| 110 | + all necessary information to the ones willing to ask for it. The index implementation | ||
| 111 | + actually provides this already, but some real use-cases would be great to have a least. | ||
| 119 | 112 | * repo.checkout should be added that does everything HEAD.reset does, but in addition | |
| 120 | 113 | it allows to checkout heads beforehand, hence its more like a repo.head.reference = other_head. | |
| 121 | 114 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,11 +186,11 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, | |||
| 186 | 186 | if not a_blob_id or self.re_is_null_hexsha.search(a_blob_id): | |
| 187 | 187 | self.a_blob = None | |
| 188 | 188 | else: | |
| 189 | - self.a_blob = blob.Blob(repo, id=a_blob_id, mode=a_mode, path=a_path) | ||
| 189 | + self.a_blob = blob.Blob(repo, a_blob_id, mode=a_mode, path=a_path) | ||
| 190 | 190 | if not b_blob_id or self.re_is_null_hexsha.search(b_blob_id): | |
| 191 | 191 | self.b_blob = None | |
| 192 | 192 | else: | |
| 193 | - self.b_blob = blob.Blob(repo, id=b_blob_id, mode=b_mode, path=b_path) | ||
| 193 | + self.b_blob = blob.Blob(repo, b_blob_id, mode=b_mode, path=b_path) | ||
| 194 | 194 | ||
| 195 | 195 | self.a_mode = a_mode | |
| 196 | 196 | self.b_mode = b_mode | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,7 +92,7 @@ def from_blob(cls, blob, stage = 0): | |||
| 92 | 92 | Returns | |
| 93 | 93 | Fully equipped BaseIndexEntry at the given stage | |
| 94 | 94 | """ | |
| 95 | - return cls((blob.mode, blob.id, stage, blob.path)) | ||
| 95 | + return cls((blob.mode, blob.sha, stage, blob.path)) | ||
| 96 | 96 | ||
| 97 | 97 | ||
| 98 | 98 | class IndexEntry(BaseIndexEntry): | |
@@ -165,7 +165,7 @@ def from_blob(cls, blob): | |||
| 165 | 165 | Minimal entry resembling the given blob objecft | |
| 166 | 166 | """ | |
| 167 | 167 | time = struct.pack(">LL", 0, 0) | |
| 168 | - return IndexEntry((blob.mode, blob.id, 0, blob.path, time, time, 0, 0, 0, 0, blob.size)) | ||
| 168 | + return IndexEntry((blob.mode, blob.sha, 0, blob.path, time, time, 0, 0, 0, 0, blob.size)) | ||
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | 171 | def clear_cache(func): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,13 +16,13 @@ class Object(LazyMixin): | |||
| 16 | 16 | This Object also serves as a constructor for instances of the correct type:: | |
| 17 | 17 | ||
| 18 | 18 | inst = Object.new(repo,id) | |
| 19 | - inst.id # objects sha in hex | ||
| 19 | + inst.sha # objects sha in hex | ||
| 20 | 20 | inst.size # objects uncompressed data size | |
| 21 | 21 | inst.data # byte string containing the whole data of the object | |
| 22 | 22 | """ | |
| 23 | 23 | NULL_HEX_SHA = '0'*40 | |
| 24 | 24 | TYPES = ("blob", "tree", "commit", "tag") | |
| 25 | - __slots__ = ("repo", "id", "size", "data" ) | ||
| 25 | + __slots__ = ("repo", "sha", "size", "data" ) | ||
| 26 | 26 | type = None # to be set by subclass | |
| 27 | 27 | ||
| 28 | 28 | def __init__(self, repo, id): | |
@@ -38,7 +38,7 @@ def __init__(self, repo, id): | |||
| 38 | 38 | """ | |
| 39 | 39 | super(Object,self).__init__() | |
| 40 | 40 | self.repo = repo | |
| 41 | - self.id = id | ||
| 41 | + self.sha = id | ||
| 42 | 42 | ||
| 43 | 43 | @classmethod | |
| 44 | 44 | def new(cls, repo, id): | |
@@ -76,11 +76,11 @@ def _set_cache_(self, attr): | |||
| 76 | 76 | Retrieve object information | |
| 77 | 77 | """ | |
| 78 | 78 | if attr == "size": | |
| 79 | - hexsha, typename, self.size = self.repo.git.get_object_header(self.id) | ||
| 80 | - assert typename == self.type, _assertion_msg_format % (self.id, typename, self.type) | ||
| 79 | + hexsha, typename, self.size = self.repo.git.get_object_header(self.sha) | ||
| 80 | + assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type) | ||
| 81 | 81 | elif attr == "data": | |
| 82 | - hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.id) | ||
| 83 | - assert typename == self.type, _assertion_msg_format % (self.id, typename, self.type) | ||
| 82 | + hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.sha) | ||
| 83 | + assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type) | ||
| 84 | 84 | else: | |
| 85 | 85 | super(Object,self)._set_cache_(attr) | |
| 86 | 86 | ||
@@ -89,43 +89,43 @@ def __eq__(self, other): | |||
| 89 | 89 | Returns | |
| 90 | 90 | True if the objects have the same SHA1 | |
| 91 | 91 | """ | |
| 92 | - return self.id == other.id | ||
| 92 | + return self.sha == other.sha | ||
| 93 | 93 | ||
| 94 | 94 | def __ne__(self, other): | |
| 95 | 95 | """ | |
| 96 | 96 | Returns | |
| 97 | 97 | True if the objects do not have the same SHA1 | |
| 98 | 98 | """ | |
| 99 | - return self.id != other.id | ||
| 99 | + return self.sha != other.sha | ||
| 100 | 100 | ||
| 101 | 101 | def __hash__(self): | |
| 102 | 102 | """ | |
| 103 | 103 | Returns | |
| 104 | 104 | Hash of our id allowing objects to be used in dicts and sets | |
| 105 | 105 | """ | |
| 106 | - return hash(self.id) | ||
| 106 | + return hash(self.sha) | ||
| 107 | 107 | ||
| 108 | 108 | def __str__(self): | |
| 109 | 109 | """ | |
| 110 | 110 | Returns | |
| 111 | 111 | string of our SHA1 as understood by all git commands | |
| 112 | 112 | """ | |
| 113 | - return self.id | ||
| 113 | + return self.sha | ||
| 114 | 114 | ||
| 115 | 115 | def __repr__(self): | |
| 116 | 116 | """ | |
| 117 | 117 | Returns | |
| 118 | 118 | string with pythonic representation of our object | |
| 119 | 119 | """ | |
| 120 | - return '<git.%s "%s">' % (self.__class__.__name__, self.id) | ||
| 120 | + return '<git.%s "%s">' % (self.__class__.__name__, self.sha) | ||
| 121 | 121 | ||
| 122 | 122 | @property | |
| 123 | 123 | def data_stream(self): | |
| 124 | 124 | """ | |
| 125 | 125 | Returns | |
| 126 | 126 | File Object compatible stream to the uncompressed raw data of the object | |
| 127 | 127 | """ | |
| 128 | - proc = self.repo.git.cat_file(self.type, self.id, as_process=True) | ||
| 128 | + proc = self.repo.git.cat_file(self.type, self.sha, as_process=True) | ||
| 129 | 129 | return utils.ProcessStreamAdapter(proc, "stdout") | |
| 130 | 130 | ||
| 131 | 131 | def stream_data(self, ostream): | |
@@ -138,7 +138,7 @@ def stream_data(self, ostream): | |||
| 138 | 138 | Returns | |
| 139 | 139 | self | |
| 140 | 140 | """ | |
| 141 | - self.repo.git.cat_file(self.type, self.id, output_stream=ostream) | ||
| 141 | + self.repo.git.cat_file(self.type, self.sha, output_stream=ostream) | ||
| 142 | 142 | return self | |
| 143 | 143 | ||
| 144 | 144 | class IndexObject(Object): | |
@@ -148,13 +148,13 @@ class IndexObject(Object): | |||
| 148 | 148 | """ | |
| 149 | 149 | __slots__ = ("path", "mode") | |
| 150 | 150 | ||
| 151 | - def __init__(self, repo, id, mode=None, path=None): | ||
| 151 | + def __init__(self, repo, sha, mode=None, path=None): | ||
| 152 | 152 | """ | |
| 153 | 153 | Initialize a newly instanced IndexObject | |
| 154 | 154 | ``repo`` | |
| 155 | 155 | is the Repo we are located in | |
| 156 | 156 | ||
| 157 | - ``id`` : string | ||
| 157 | + ``sha`` : string | ||
| 158 | 158 | is the git object id as hex sha | |
| 159 | 159 | ||
| 160 | 160 | ``mode`` : int | |
@@ -168,7 +168,7 @@ def __init__(self, repo, id, mode=None, path=None): | |||
| 168 | 168 | Path may not be set of the index object has been created directly as it cannot | |
| 169 | 169 | be retrieved without knowing the parent tree. | |
| 170 | 170 | """ | |
| 171 | - super(IndexObject, self).__init__(repo, id) | ||
| 171 | + super(IndexObject, self).__init__(repo, sha) | ||
| 172 | 172 | self._set_self_from_args_(locals()) | |
| 173 | 173 | if isinstance(mode, basestring): | |
| 174 | 174 | self.mode = self._mode_str_to_int(mode) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,4 +33,4 @@ def mime_type(self): | |||
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | 35 | def __repr__(self): | |
| 36 | - return '<git.Blob "%s">' % self.id | ||
| 36 | + return '<git.Blob "%s">' % self.sha | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,17 +23,17 @@ class Commit(base.Object, Iterable, diff.Diffable): | |||
| 23 | 23 | type = "commit" | |
| 24 | 24 | __slots__ = ("tree", "author", "authored_date", "committer", "committed_date", | |
| 25 | 25 | "message", "parents") | |
| 26 | - _id_attribute_ = "id" | ||
| 26 | + _id_attribute_ = "sha" | ||
| 27 | 27 | ||
| 28 | - def __init__(self, repo, id, tree=None, author=None, authored_date=None, | ||
| 28 | + def __init__(self, repo, sha, tree=None, author=None, authored_date=None, | ||
| 29 | 29 | committer=None, committed_date=None, message=None, parents=None): | |
| 30 | 30 | """ | |
| 31 | 31 | Instantiate a new Commit. All keyword arguments taking None as default will | |
| 32 | 32 | be implicitly set if id names a valid sha. | |
| 33 | 33 | ||
| 34 | 34 | The parameter documentation indicates the type of the argument after a colon ':'. | |
| 35 | 35 | ||
| 36 | - ``id`` | ||
| 36 | + ``sha`` | ||
| 37 | 37 | is the sha id of the commit or a ref | |
| 38 | 38 | ||
| 39 | 39 | ``parents`` : tuple( Commit, ... ) | |
@@ -62,15 +62,15 @@ def __init__(self, repo, id, tree=None, author=None, authored_date=None, | |||
| 62 | 62 | Returns | |
| 63 | 63 | git.Commit | |
| 64 | 64 | """ | |
| 65 | - super(Commit,self).__init__(repo, id) | ||
| 65 | + super(Commit,self).__init__(repo, sha) | ||
| 66 | 66 | self._set_self_from_args_(locals()) | |
| 67 | 67 | ||
| 68 | 68 | if parents is not None: | |
| 69 | 69 | self.parents = tuple( self.__class__(repo, p) for p in parents ) | |
| 70 | 70 | # END for each parent to convert | |
| 71 | 71 | ||
| 72 | - if self.id and tree is not None: | ||
| 73 | - self.tree = Tree(repo, id=tree, path='') | ||
| 72 | + if self.sha and tree is not None: | ||
| 73 | + self.tree = Tree(repo, tree, path='') | ||
| 74 | 74 | # END id to tree conversion | |
| 75 | 75 | ||
| 76 | 76 | def _set_cache_(self, attr): | |
@@ -82,7 +82,7 @@ def _set_cache_(self, attr): | |||
| 82 | 82 | if attr in Commit.__slots__: | |
| 83 | 83 | # prepare our data lines to match rev-list | |
| 84 | 84 | data_lines = self.data.splitlines() | |
| 85 | - data_lines.insert(0, "commit %s" % self.id) | ||
| 85 | + data_lines.insert(0, "commit %s" % self.sha) | ||
| 86 | 86 | temp = self._iter_from_process_or_stream(self.repo, iter(data_lines), False).next() | |
| 87 | 87 | self.parents = temp.parents | |
| 88 | 88 | self.tree = temp.tree | |
@@ -116,7 +116,7 @@ def count(self, paths='', **kwargs): | |||
| 116 | 116 | Returns | |
| 117 | 117 | int | |
| 118 | 118 | """ | |
| 119 | - return len(self.repo.git.rev_list(self.id, '--', paths, **kwargs).strip().splitlines()) | ||
| 119 | + return len(self.repo.git.rev_list(self.sha, '--', paths, **kwargs).strip().splitlines()) | ||
| 120 | 120 | ||
| 121 | 121 | @property | |
| 122 | 122 | def name_rev(self): | |
@@ -189,14 +189,14 @@ def stats(self): | |||
| 189 | 189 | git.Stats | |
| 190 | 190 | """ | |
| 191 | 191 | if not self.parents: | |
| 192 | - text = self.repo.git.diff_tree(self.id, '--', numstat=True, root=True) | ||
| 192 | + text = self.repo.git.diff_tree(self.sha, '--', numstat=True, root=True) | ||
| 193 | 193 | text2 = "" | |
| 194 | 194 | for line in text.splitlines()[1:]: | |
| 195 | 195 | (insertions, deletions, filename) = line.split("\t") | |
| 196 | 196 | text2 += "%s\t%s\t%s\n" % (insertions, deletions, filename) | |
| 197 | 197 | text = text2 | |
| 198 | 198 | else: | |
| 199 | - text = self.repo.git.diff(self.parents[0].id, self.id, '--', numstat=True) | ||
| 199 | + text = self.repo.git.diff(self.parents[0].sha, self.sha, '--', numstat=True) | ||
| 200 | 200 | return stats.Stats._list_from_string(self.repo, text) | |
| 201 | 201 | ||
| 202 | 202 | @classmethod | |
@@ -259,15 +259,15 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream, from_rev_list): | |||
| 259 | 259 | # END message parsing | |
| 260 | 260 | message = '\n'.join(message_lines) | |
| 261 | 261 | ||
| 262 | - yield Commit(repo, id=id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date, | ||
| 262 | + yield Commit(repo, id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date, | ||
| 263 | 263 | committer=committer, committed_date=committed_date, message=message) | |
| 264 | 264 | # END for each line in stream | |
| 265 | 265 | ||
| 266 | 266 | ||
| 267 | 267 | def __str__(self): | |
| 268 | 268 | """ Convert commit to string which is SHA1 """ | |
| 269 | - return self.id | ||
| 269 | + return self.sha | ||
| 270 | 270 | ||
| 271 | 271 | def __repr__(self): | |
| 272 | - return '<git.Commit "%s">' % self.id | ||
| 272 | + return '<git.Commit "%s">' % self.sha | ||
| 273 | 273 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,15 +17,15 @@ class TagObject(base.Object): | |||
| 17 | 17 | type = "tag" | |
| 18 | 18 | __slots__ = ( "object", "tag", "tagger", "tagged_date", "message" ) | |
| 19 | 19 | ||
| 20 | - def __init__(self, repo, id, object=None, tag=None, | ||
| 20 | + def __init__(self, repo, sha, object=None, tag=None, | ||
| 21 | 21 | tagger=None, tagged_date=None, message=None): | |
| 22 | 22 | """ | |
| 23 | 23 | Initialize a tag object with additional data | |
| 24 | 24 | ||
| 25 | 25 | ``repo`` | |
| 26 | 26 | repository this object is located in | |
| 27 | 27 | ||
| 28 | - ``id`` | ||
| 28 | + ``sha`` | ||
| 29 | 29 | SHA1 or ref suitable for git-rev-parse | |
| 30 | 30 | ||
| 31 | 31 | ``object`` | |
@@ -41,7 +41,7 @@ def __init__(self, repo, id, object=None, tag=None, | |||
| 41 | 41 | is the DateTime of the tag creation - use time.gmtime to convert | |
| 42 | 42 | it into a different format | |
| 43 | 43 | """ | |
| 44 | - super(TagObject, self).__init__(repo, id ) | ||
| 44 | + super(TagObject, self).__init__(repo, sha ) | ||
| 45 | 45 | self._set_self_from_args_(locals()) | |
| 46 | 46 | ||
| 47 | 47 | def _set_cache_(self, attr): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,8 +43,8 @@ class Tree(base.IndexObject, diff.Diffable): | |||
| 43 | 43 | tree_id = 040 | |
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | - def __init__(self, repo, id, mode=0, path=None): | ||
| 47 | - super(Tree, self).__init__(repo, id, mode, path) | ||
| 46 | + def __init__(self, repo, sha, mode=0, path=None): | ||
| 47 | + super(Tree, self).__init__(repo, sha, mode, path) | ||
| 48 | 48 | ||
| 49 | 49 | def _set_cache_(self, attr): | |
| 50 | 50 | if attr == "_cache": | |
@@ -150,7 +150,7 @@ def __div__(self, file): | |||
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | 152 | def __repr__(self): | |
| 153 | - return '<git.Tree "%s">' % self.id | ||
| 153 | + return '<git.Tree "%s">' % self.sha | ||
| 154 | 154 | ||
| 155 | 155 | @classmethod | |
| 156 | 156 | def _iter_recursive(cls, repo, tree, cur_depth, max_depth, predicate, prune ): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -312,17 +312,17 @@ def _set_reference(self, ref): | |||
| 312 | 312 | if isinstance(ref, Head): | |
| 313 | 313 | write_value = "ref: %s" % ref.path | |
| 314 | 314 | elif isinstance(ref, Commit): | |
| 315 | - write_value = ref.id | ||
| 315 | + write_value = ref.sha | ||
| 316 | 316 | else: | |
| 317 | 317 | try: | |
| 318 | - write_value = ref.commit.id | ||
| 318 | + write_value = ref.commit.sha | ||
| 319 | 319 | except AttributeError: | |
| 320 | 320 | sha = str(ref) | |
| 321 | 321 | try: | |
| 322 | 322 | obj = Object.new(self.repo, sha) | |
| 323 | 323 | if obj.type != "commit": | |
| 324 | 324 | raise TypeError("Invalid object type behind sha: %s" % sha) | |
| 325 | - write_value = obj.id | ||
| 325 | + write_value = obj.sha | ||
| 326 | 326 | except Exception: | |
| 327 | 327 | raise ValueError("Could not extract object from %s" % ref) | |
| 328 | 328 | # END end try string | |
@@ -428,7 +428,7 @@ class Head(Reference): | |||
| 428 | 428 | >>> head.commit | |
| 429 | 429 | <git.Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455"> | |
| 430 | 430 | ||
| 431 | - >>> head.commit.id | ||
| 431 | + >>> head.commit.sha | ||
| 432 | 432 | '1c09f116cbc2cb4100fb6935bb162daa4723f455' | |
| 433 | 433 | """ | |
| 434 | 434 | _common_path_default = "refs/heads" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -622,7 +622,7 @@ def blame(self, rev, file): | |||
| 622 | 622 | sha = info['id'] | |
| 623 | 623 | c = commits.get(sha) | |
| 624 | 624 | if c is None: | |
| 625 | - c = Commit( self, id=sha, | ||
| 625 | + c = Commit( self, sha, | ||
| 626 | 626 | author=Actor._from_string(info['author'] + ' ' + info['author_email']), | |
| 627 | 627 | authored_date=info['author_date'], | |
| 628 | 628 | committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments