##// END OF EJS Templates
fixed issues with gitsubmodule diffs
marcink -
r2233:07fce193 beta
parent child Browse files
Show More
@@ -33,8 +33,8 b' from itertools import tee, imap'
33 from pylons.i18n.translation import _
33 from pylons.i18n.translation import _
34
34
35 from rhodecode.lib.vcs.exceptions import VCSError
35 from rhodecode.lib.vcs.exceptions import VCSError
36 from rhodecode.lib.vcs.nodes import FileNode
36 from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode
37
37 from rhodecode.lib.helpers import escape
38 from rhodecode.lib.utils import EmptyChangeset
38 from rhodecode.lib.utils import EmptyChangeset
39
39
40
40
@@ -79,9 +79,13 b' def wrapped_diff(filenode_old, filenode_'
79 'diff menu to display this diff'))
79 'diff menu to display this diff'))
80 stats = (0, 0)
80 stats = (0, 0)
81 size = 0
81 size = 0
82
83 if not diff:
82 if not diff:
84 diff = wrap_to_table(_('No changes detected'))
83 submodules = filter(lambda o: isinstance(o, SubModuleNode),
84 [filenode_new, filenode_old])
85 if submodules:
86 diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
87 else:
88 diff = wrap_to_table(_('No changes detected'))
85
89
86 cs1 = filenode_old.changeset.raw_id
90 cs1 = filenode_old.changeset.raw_id
87 cs2 = filenode_new.changeset.raw_id
91 cs2 = filenode_new.changeset.raw_id
@@ -97,6 +101,10 b' def get_gitdiff(filenode_old, filenode_n'
97 """
101 """
98 # make sure we pass in default context
102 # make sure we pass in default context
99 context = context or 3
103 context = context or 3
104 submodules = filter(lambda o: isinstance(o, SubModuleNode),
105 [filenode_new, filenode_old])
106 if submodules:
107 return ''
100
108
101 for filenode in (filenode_old, filenode_new):
109 for filenode in (filenode_old, filenode_new):
102 if not isinstance(filenode, FileNode):
110 if not isinstance(filenode, FileNode):
@@ -109,7 +117,6 b' def get_gitdiff(filenode_old, filenode_n'
109
117
110 vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path,
118 vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path,
111 ignore_whitespace, context)
119 ignore_whitespace, context)
112
113 return vcs_gitdiff
120 return vcs_gitdiff
114
121
115
122
@@ -364,24 +364,31 b' class GitChangeset(BaseChangeset):'
364 path = self._fix_path(path)
364 path = self._fix_path(path)
365 if not path in self.nodes:
365 if not path in self.nodes:
366 try:
366 try:
367 id = self._get_id_for_path(path)
367 id_ = self._get_id_for_path(path)
368 except ChangesetError:
368 except ChangesetError:
369 raise NodeDoesNotExistError("Cannot find one of parents' "
369 raise NodeDoesNotExistError("Cannot find one of parents' "
370 "directories for a given path: %s" % path)
370 "directories for a given path: %s" % path)
371 obj = self.repository._repo.get_object(id)
371
372 if isinstance(obj, objects.Tree):
372 als = self.repository.alias
373 if path == '':
373 _GL = lambda m: m and objects.S_ISGITLINK(m)
374 node = RootNode(changeset=self)
374 if _GL(self._stat_modes.get(path)):
375 node = SubModuleNode(path, url=None, changeset=id_, alias=als)
376 else:
377 obj = self.repository._repo.get_object(id_)
378
379 if isinstance(obj, objects.Tree):
380 if path == '':
381 node = RootNode(changeset=self)
382 else:
383 node = DirNode(path, changeset=self)
384 node._tree = obj
385 elif isinstance(obj, objects.Blob):
386 node = FileNode(path, changeset=self)
387 node._blob = obj
375 else:
388 else:
376 node = DirNode(path, changeset=self)
389 raise NodeDoesNotExistError("There is no file nor directory "
377 node._tree = obj
390 "at the given path %r at revision %r"
378 elif isinstance(obj, objects.Blob):
391 % (path, self.short_id))
379 node = FileNode(path, changeset=self)
380 node._blob = obj
381 else:
382 raise NodeDoesNotExistError("There is no file nor directory "
383 "at the given path %r at revision %r"
384 % (path, self.short_id))
385 # cache node
392 # cache node
386 self.nodes[path] = node
393 self.nodes[path] = node
387 return self.nodes[path]
394 return self.nodes[path]
@@ -423,7 +430,6 b' class GitChangeset(BaseChangeset):'
423 line))
430 line))
424 _path = splitted[1].strip()
431 _path = splitted[1].strip()
425 paths.add(_path)
432 paths.add(_path)
426
427 return sorted(paths)
433 return sorted(paths)
428
434
429 @LazyProperty
435 @LazyProperty
@@ -411,7 +411,7 b' class GitRepository(BaseRepository):'
411 yield self.get_changeset(rev)
411 yield self.get_changeset(rev)
412
412
413 def get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
413 def get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
414 context=3):
414 context=3):
415 """
415 """
416 Returns (git like) *diff*, as plain text. Shows changes introduced by
416 Returns (git like) *diff*, as plain text. Shows changes introduced by
417 ``rev2`` since ``rev1``.
417 ``rev2`` since ``rev1``.
@@ -19,6 +19,7 b' from rhodecode.lib.vcs.utils.lazy import'
19 from rhodecode.lib.vcs.utils import safe_unicode, safe_str
19 from rhodecode.lib.vcs.utils import safe_unicode, safe_str
20 from rhodecode.lib.vcs.exceptions import NodeError
20 from rhodecode.lib.vcs.exceptions import NodeError
21 from rhodecode.lib.vcs.exceptions import RemovedFileNodeError
21 from rhodecode.lib.vcs.exceptions import RemovedFileNodeError
22 from rhodecode.lib.utils import EmptyChangeset
22
23
23
24
24 class NodeKind:
25 class NodeKind:
@@ -576,16 +577,26 b' class SubModuleNode(Node):'
576 """
577 """
577 represents a SubModule of Git or SubRepo of Mercurial
578 represents a SubModule of Git or SubRepo of Mercurial
578 """
579 """
580 is_binary = False
581 size = 0
582
579 def __init__(self, name, url=None, changeset=None, alias=None):
583 def __init__(self, name, url=None, changeset=None, alias=None):
580 self.path = name
584 self.path = name
581 self.kind = NodeKind.SUBMODULE
585 self.kind = NodeKind.SUBMODULE
582 self.alias = alias
586 self.alias = alias
583 # changeset MUST be STR !! since it can point to non-valid SCM
587 # we have to use emptyChangeset here since this can point to svn/git/hg
584 self.changeset = str(changeset)
588 # submodules we cannot get from repository
589 self.changeset = EmptyChangeset(str(changeset), alias=alias)
585 self.url = url or self._extract_submodule_url()
590 self.url = url or self._extract_submodule_url()
586
591
592 def __repr__(self):
593 return '<%s %r @ %s>' % (self.__class__.__name__, self.path,
594 self.changeset.short_id)
595
587 def _extract_submodule_url(self):
596 def _extract_submodule_url(self):
588 if self.alias == 'git':
597 if self.alias == 'git':
598 #TODO: find a way to parse gits submodule file and extract the
599 # linking URL
589 return self.path
600 return self.path
590 if self.alias == 'hg':
601 if self.alias == 'hg':
591 return self.path
602 return self.path
@@ -597,4 +608,4 b' class SubModuleNode(Node):'
597 then only last part is returned.
608 then only last part is returned.
598 """
609 """
599 org = safe_unicode(self.path.rstrip('/').split('/')[-1])
610 org = safe_unicode(self.path.rstrip('/').split('/')[-1])
600 return u'%s @ %s' % (org, self.changeset[:12])
611 return u'%s @ %s' % (org, self.changeset.short_id)
General Comments 0
You need to be logged in to leave comments. Login now