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