##// END OF EJS Templates
Implements subrepos view inside filebrowser...
marcink -
r2232:49dc09e9 beta
parent child Browse files
Show More
@@ -10,7 +10,8 b' from rhodecode.lib.vcs.exceptions import'
10 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
10 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
11 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
11 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
12 from rhodecode.lib.vcs.backends.base import BaseChangeset
12 from rhodecode.lib.vcs.backends.base import BaseChangeset
13 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, RemovedFileNode
13 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
14 RemovedFileNode, SubModuleNode
14 from rhodecode.lib.vcs.utils import safe_unicode
15 from rhodecode.lib.vcs.utils import safe_unicode
15 from rhodecode.lib.vcs.utils import date_fromtimestamp
16 from rhodecode.lib.vcs.utils import date_fromtimestamp
16 from rhodecode.lib.vcs.utils.lazy import LazyProperty
17 from rhodecode.lib.vcs.utils.lazy import LazyProperty
@@ -329,7 +330,13 b' class GitChangeset(BaseChangeset):'
329 tree = self.repository._repo[id]
330 tree = self.repository._repo[id]
330 dirnodes = []
331 dirnodes = []
331 filenodes = []
332 filenodes = []
333 als = self.repository.alias
332 for name, stat, id in tree.iteritems():
334 for name, stat, id in tree.iteritems():
335 if objects.S_ISGITLINK(stat):
336 dirnodes.append(SubModuleNode(name, url=None, changeset=id,
337 alias=als))
338 continue
339
333 obj = self.repository._repo.get_object(id)
340 obj = self.repository._repo.get_object(id)
334 if path != '':
341 if path != '':
335 obj_path = '/'.join((path, name))
342 obj_path = '/'.join((path, name))
@@ -5,8 +5,9 b' from rhodecode.lib.vcs.backends.base imp'
5 from rhodecode.lib.vcs.conf import settings
5 from rhodecode.lib.vcs.conf import settings
6 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError, \
6 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError, \
7 ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
7 ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
8 from rhodecode.lib.vcs.nodes import AddedFileNodesGenerator, ChangedFileNodesGenerator, \
8 from rhodecode.lib.vcs.nodes import AddedFileNodesGenerator, \
9 DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode
9 ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, \
10 RemovedFileNodesGenerator, RootNode, SubModuleNode
10
11
11 from rhodecode.lib.vcs.utils import safe_str, safe_unicode, date_fromtimestamp
12 from rhodecode.lib.vcs.utils import safe_str, safe_unicode, date_fromtimestamp
12 from rhodecode.lib.vcs.utils.lazy import LazyProperty
13 from rhodecode.lib.vcs.utils.lazy import LazyProperty
@@ -159,6 +160,13 b' class MercurialChangeset(BaseChangeset):'
159 " %r" % (self.revision, path))
160 " %r" % (self.revision, path))
160 return self._ctx.filectx(path)
161 return self._ctx.filectx(path)
161
162
163 def _extract_submodules(self):
164 """
165 returns a dictionary with submodule information from substate file
166 of hg repository
167 """
168 return self._ctx.substate
169
162 def get_file_mode(self, path):
170 def get_file_mode(self, path):
163 """
171 """
164 Returns stat mode of the file at the given ``path``.
172 Returns stat mode of the file at the given ``path``.
@@ -271,17 +279,27 b' class MercurialChangeset(BaseChangeset):'
271 raise ChangesetError("Directory does not exist for revision %r at "
279 raise ChangesetError("Directory does not exist for revision %r at "
272 " %r" % (self.revision, path))
280 " %r" % (self.revision, path))
273 path = self._fix_path(path)
281 path = self._fix_path(path)
282
274 filenodes = [FileNode(f, changeset=self) for f in self._file_paths
283 filenodes = [FileNode(f, changeset=self) for f in self._file_paths
275 if os.path.dirname(f) == path]
284 if os.path.dirname(f) == path]
276 dirs = path == '' and '' or [d for d in self._dir_paths
285 dirs = path == '' and '' or [d for d in self._dir_paths
277 if d and posixpath.dirname(d) == path]
286 if d and posixpath.dirname(d) == path]
278 dirnodes = [DirNode(d, changeset=self) for d in dirs
287 dirnodes = [DirNode(d, changeset=self) for d in dirs
279 if os.path.dirname(d) == path]
288 if os.path.dirname(d) == path]
289
290 als = self.repository.alias
291 for k, vals in self._extract_submodules().iteritems():
292 #vals = url,rev,type
293 loc = vals[0]
294 cs = vals[1]
295 dirnodes.append(SubModuleNode(k, url=loc, changeset=cs,
296 alias=als))
280 nodes = dirnodes + filenodes
297 nodes = dirnodes + filenodes
281 # cache nodes
298 # cache nodes
282 for node in nodes:
299 for node in nodes:
283 self.nodes[node.path] = node
300 self.nodes[node.path] = node
284 nodes.sort()
301 nodes.sort()
302
285 return nodes
303 return nodes
286
304
287 def get_node(self, path):
305 def get_node(self, path):
@@ -8,19 +8,21 b''
8 :created_on: Apr 8, 2010
8 :created_on: Apr 8, 2010
9 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
9 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
10 """
10 """
11 import os
11 import stat
12 import stat
12 import posixpath
13 import posixpath
13 import mimetypes
14 import mimetypes
14
15
16 from pygments import lexers
17
15 from rhodecode.lib.vcs.utils.lazy import LazyProperty
18 from rhodecode.lib.vcs.utils.lazy import LazyProperty
16 from rhodecode.lib.vcs.utils import safe_unicode
19 from rhodecode.lib.vcs.utils import safe_unicode, safe_str
17 from rhodecode.lib.vcs.exceptions import NodeError
20 from rhodecode.lib.vcs.exceptions import NodeError
18 from rhodecode.lib.vcs.exceptions import RemovedFileNodeError
21 from rhodecode.lib.vcs.exceptions import RemovedFileNodeError
19
22
20 from pygments import lexers
21
22
23
23 class NodeKind:
24 class NodeKind:
25 SUBMODULE = -1
24 DIR = 1
26 DIR = 1
25 FILE = 2
27 FILE = 2
26
28
@@ -209,6 +211,13 b' class Node(object):'
209 """
211 """
210 return self.kind == NodeKind.DIR and self.path == ''
212 return self.kind == NodeKind.DIR and self.path == ''
211
213
214 def is_submodule(self):
215 """
216 Returns ``True`` if node's kind is ``NodeKind.SUBMODULE``, ``False``
217 otherwise.
218 """
219 return self.kind == NodeKind.SUBMODULE
220
212 @LazyProperty
221 @LazyProperty
213 def added(self):
222 def added(self):
214 return self.state is NodeState.ADDED
223 return self.state is NodeState.ADDED
@@ -561,3 +570,31 b' class RootNode(DirNode):'
561
570
562 def __repr__(self):
571 def __repr__(self):
563 return '<%s>' % self.__class__.__name__
572 return '<%s>' % self.__class__.__name__
573
574
575 class SubModuleNode(Node):
576 """
577 represents a SubModule of Git or SubRepo of Mercurial
578 """
579 def __init__(self, name, url=None, changeset=None, alias=None):
580 self.path = name
581 self.kind = NodeKind.SUBMODULE
582 self.alias = alias
583 # changeset MUST be STR !! since it can point to non-valid SCM
584 self.changeset = str(changeset)
585 self.url = url or self._extract_submodule_url()
586
587 def _extract_submodule_url(self):
588 if self.alias == 'git':
589 return self.path
590 if self.alias == 'hg':
591 return self.path
592
593 @LazyProperty
594 def name(self):
595 """
596 Returns name of the node so if its path
597 then only last part is returned.
598 """
599 org = safe_unicode(self.path.rstrip('/').split('/')[-1])
600 return u'%s @ %s' % (org, self.changeset[:12])
@@ -2718,6 +2718,14 b' table.code-browser .browser-dir {'
2718 text-align: left;
2718 text-align: left;
2719 }
2719 }
2720
2720
2721 table.code-browser .submodule-dir {
2722 background: url("../images/icons/disconnect.png") no-repeat scroll 3px;
2723 height: 16px;
2724 padding-left: 20px;
2725 text-align: left;
2726 }
2727
2728
2721 .box .search {
2729 .box .search {
2722 clear: both;
2730 clear: both;
2723 overflow: hidden;
2731 overflow: hidden;
@@ -70,7 +70,11 b''
70 %for cnt,node in enumerate(c.file):
70 %for cnt,node in enumerate(c.file):
71 <tr class="parity${cnt%2}">
71 <tr class="parity${cnt%2}">
72 <td>
72 <td>
73 ${h.link_to(node.name,h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=h.safe_unicode(node.path)),class_=file_class(node)+" ypjax-link")}
73 %if node.is_submodule():
74 ${h.link_to(node.name,node.url or '#',class_="submodule-dir ypjax-link")}
75 %else:
76 ${h.link_to(node.name, h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=h.safe_unicode(node.path)),class_=file_class(node)+" ypjax-link")}
77 %endif:
74 </td>
78 </td>
75 <td>
79 <td>
76 %if node.is_file():
80 %if node.is_file():
General Comments 0
You need to be logged in to leave comments. Login now