| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c555840 commit a92ab80
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,18 @@ | |||
| 13 | 13 | ||
| 14 | 14 | __all__ = ["Reference"] | |
| 15 | 15 | ||
| 16 | + #{ Utilities | ||
| 17 | + def require_remote_ref_path(func): | ||
| 18 | + """A decorator raising a TypeError if we are not a valid remote, based on the path""" | ||
| 19 | + def wrapper(self, *args): | ||
| 20 | + if not self.path.startswith(self._remote_common_path_default + "/"): | ||
| 21 | + raise ValueError("ref path does not point to a remote reference: %s" % path) | ||
| 22 | + return func(self, *args) | ||
| 23 | + #END wrapper | ||
| 24 | + wrapper.__name__ = func.__name__ | ||
| 25 | + return wrapper | ||
| 26 | + #}END utilites | ||
| 27 | + | ||
| 16 | 28 | ||
| 17 | 29 | class Reference(SymbolicReference, LazyMixin, Iterable): | |
| 18 | 30 | """Represents a named reference to any object. Subclasses may apply restrictions though, | |
@@ -38,6 +50,8 @@ def __init__(self, repo, path, check_path = True): | |||
| 38 | 50 | ||
| 39 | 51 | def __str__(self): | |
| 40 | 52 | return self.name | |
| 53 | + | ||
| 54 | + #{ Interface | ||
| 41 | 55 | ||
| 42 | 56 | def set_object(self, object, logmsg = None): | |
| 43 | 57 | """Special version which checks if the head-log needs an update as well""" | |
@@ -84,3 +98,30 @@ def iter_items(cls, repo, common_path = None): | |||
| 84 | 98 | """Equivalent to SymbolicReference.iter_items, but will return non-detached | |
| 85 | 99 | references as well.""" | |
| 86 | 100 | return cls._iter_items(repo, common_path) | |
| 101 | + | ||
| 102 | + #}END interface | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + #{ Remote Interface | ||
| 106 | + | ||
| 107 | + @property | ||
| 108 | + @require_remote_ref_path | ||
| 109 | + def remote_name(self): | ||
| 110 | + """ | ||
| 111 | + :return: | ||
| 112 | + Name of the remote we are a reference of, such as 'origin' for a reference | ||
| 113 | + named 'origin/master'""" | ||
| 114 | + tokens = self.path.split('/') | ||
| 115 | + # /refs/remotes/<remote name>/<branch_name> | ||
| 116 | + return tokens[2] | ||
| 117 | + | ||
| 118 | + @property | ||
| 119 | + @require_remote_ref_path | ||
| 120 | + def remote_head(self): | ||
| 121 | + """:return: Name of the remote head itself, i.e. master. | ||
| 122 | + :note: The returned name is usually not qualified enough to uniquely identify | ||
| 123 | + a branch""" | ||
| 124 | + tokens = self.path.split('/') | ||
| 125 | + return '/'.join(tokens[3:]) | ||
| 126 | + | ||
| 127 | + #} END remote interface | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | class RemoteReference(Head): | |
| 12 | 12 | """Represents a reference pointing to a remote head.""" | |
| 13 | - _common_path_default = "refs/remotes" | ||
| 13 | + _common_path_default = Head._remote_common_path_default | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | @classmethod | |
@@ -22,24 +22,6 @@ def iter_items(cls, repo, common_path = None, remote=None): | |||
| 22 | 22 | # END handle remote constraint | |
| 23 | 23 | return super(RemoteReference, cls).iter_items(repo, common_path) | |
| 24 | 24 | ||
| 25 | - @property | ||
| 26 | - def remote_name(self): | ||
| 27 | - """ | ||
| 28 | - :return: | ||
| 29 | - Name of the remote we are a reference of, such as 'origin' for a reference | ||
| 30 | - named 'origin/master'""" | ||
| 31 | - tokens = self.path.split('/') | ||
| 32 | - # /refs/remotes/<remote name>/<branch_name> | ||
| 33 | - return tokens[2] | ||
| 34 | - | ||
| 35 | - @property | ||
| 36 | - def remote_head(self): | ||
| 37 | - """:return: Name of the remote head itself, i.e. master. | ||
| 38 | - :note: The returned name is usually not qualified enough to uniquely identify | ||
| 39 | - a branch""" | ||
| 40 | - tokens = self.path.split('/') | ||
| 41 | - return '/'.join(tokens[3:]) | ||
| 42 | - | ||
| 43 | 25 | @classmethod | |
| 44 | 26 | def delete(cls, repo, *refs, **kwargs): | |
| 45 | 27 | """Delete the given remote references. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ class SymbolicReference(object): | |||
| 33 | 33 | _resolve_ref_on_create = False | |
| 34 | 34 | _points_to_commits_only = True | |
| 35 | 35 | _common_path_default = "" | |
| 36 | + _remote_common_path_default = "refs/remotes" | ||
| 36 | 37 | _id_attribute_ = "name" | |
| 37 | 38 | ||
| 38 | 39 | def __init__(self, repo, path): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments