annotate rhodecode/lib/vcs/backends/git/changeset.py @ 3575:ca7785fae354 beta

avoid %r markup of unicode strings in user facing messages Improves Revision u'b7f4...' does not exist for this repository
author Mads Kiilerich <madski@unity3d.com>
date Wed, 20 Mar 2013 15:32:23 +0100
parents c04d1d9b6193
children 63adb3d5233a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import re
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 from itertools import chain
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 from dulwich import objects
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from subprocess import Popen, PIPE
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3077
diff changeset
5 import rhodecode
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.lib.vcs.conf import settings
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from rhodecode.lib.vcs.exceptions import RepositoryError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from rhodecode.lib.vcs.exceptions import ChangesetError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.lib.vcs.exceptions import VCSError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
13 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
14 from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
15 RemovedFileNode, SubModuleNode, ChangedFileNodesGenerator,\
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
16 AddedFileNodesGenerator, RemovedFileNodesGenerator
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 from rhodecode.lib.vcs.utils import safe_unicode
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 from rhodecode.lib.vcs.utils import date_fromtimestamp
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 from rhodecode.lib.vcs.utils.lazy import LazyProperty
3496
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
20 from rhodecode.lib.utils2 import safe_int
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 class GitChangeset(BaseChangeset):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 Represents state of the repository at single revision.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 def __init__(self, repository, revision):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 self._stat_modes = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 self.repository = repository
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
31
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 try:
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
33 commit = self.repository._repo.get_object(revision)
2543
03a770980b55 Synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 2537
diff changeset
34 if isinstance(commit, objects.Tag):
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
35 revision = commit.object[1]
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
36 commit = self.repository._repo.get_object(commit.object[1])
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 except KeyError:
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
38 raise RepositoryError("Cannot get object with id %s" % revision)
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
39 self.raw_id = revision
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
40 self.id = self.raw_id
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
41 self.short_id = self.raw_id[:12]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 self._commit = commit
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
43
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
44 self._tree_id = commit.tree
3492
0065f7fe60f6 fix spelling of committer
Mads Kiilerich <madski@unity3d.com>
parents: 3394
diff changeset
45 self._committer_property = 'committer'
3004
3bfd5852c218 implements #649 added two seperate method for author and commiter to VCS changeset class
Marcin Kuzminski <marcin@python-works.com>
parents: 2975
diff changeset
46 self._author_property = 'author'
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
47 self._date_property = 'commit_time'
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
48 self._date_tz_property = 'commit_timezone'
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
49 self.revision = repository.revisions.index(revision)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
2297
4747af4ce203 safe_unicode never fails. No need to catch decode exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 2281
diff changeset
51 self.message = safe_unicode(commit.message)
2975
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
52
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 self.nodes = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 self._paths = {}
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 @LazyProperty
3492
0065f7fe60f6 fix spelling of committer
Mads Kiilerich <madski@unity3d.com>
parents: 3394
diff changeset
57 def committer(self):
0065f7fe60f6 fix spelling of committer
Mads Kiilerich <madski@unity3d.com>
parents: 3394
diff changeset
58 return safe_unicode(getattr(self._commit, self._committer_property))
3004
3bfd5852c218 implements #649 added two seperate method for author and commiter to VCS changeset class
Marcin Kuzminski <marcin@python-works.com>
parents: 2975
diff changeset
59
3bfd5852c218 implements #649 added two seperate method for author and commiter to VCS changeset class
Marcin Kuzminski <marcin@python-works.com>
parents: 2975
diff changeset
60 @LazyProperty
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 def author(self):
3004
3bfd5852c218 implements #649 added two seperate method for author and commiter to VCS changeset class
Marcin Kuzminski <marcin@python-works.com>
parents: 2975
diff changeset
62 return safe_unicode(getattr(self._commit, self._author_property))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 def date(self):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
66 return date_fromtimestamp(getattr(self._commit, self._date_property),
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
67 getattr(self._commit, self._date_tz_property))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 @LazyProperty
2693
66c778b8cb54 Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents: 2543
diff changeset
70 def _timestamp(self):
66c778b8cb54 Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents: 2543
diff changeset
71 return getattr(self._commit, self._date_property)
66c778b8cb54 Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents: 2543
diff changeset
72
66c778b8cb54 Extended commit search schema with date of commit
Marcin Kuzminski <marcin@python-works.com>
parents: 2543
diff changeset
73 @LazyProperty
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 def status(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 Returns modified, added, removed, deleted files for current changeset
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 return self.changed, self.added, self.removed
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 @LazyProperty
2975
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
81 def tags(self):
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
82 _tags = []
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
83 for tname, tsha in self.repository.tags.iteritems():
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
84 if tsha == self.raw_id:
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
85 _tags.append(tname)
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
86 return _tags
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
87
e0da2c0ecee1 fixes #625 Git-Tags are not displayed in Shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2968
diff changeset
88 @LazyProperty
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 def branch(self):
2198
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
90
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
91 heads = self.repository._heads(reverse=False)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92
2198
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
93 ref = heads.get(self.raw_id)
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
94 if ref:
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
95 return safe_unicode(ref)
9784a54a0f5b display current heads of branches for git in changelog and shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 2116
diff changeset
96
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 def _fix_path(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 Paths are stored without trailing slash so we need to get rid off it if
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 needed.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 if path.endswith('/'):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 path = path.rstrip('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 return path
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 def _get_id_for_path(self, path):
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
107
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 # FIXME: Please, spare a couple of minutes and make those codes cleaner;
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 if not path in self._paths:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 path = path.strip('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 # set root tree
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
112 tree = self.repository._repo[self._tree_id]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 if path == '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 self._paths[''] = tree.id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 return tree.id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 splitted = path.split('/')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 dirs, name = splitted[:-1], splitted[-1]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 curdir = ''
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
119
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
120 # initially extract things from root dir
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
121 for item, stat, id in tree.iteritems():
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
122 if curdir:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
123 name = '/'.join((curdir, item))
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
124 else:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
125 name = item
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
126 self._paths[name] = id
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
127 self._stat_modes[name] = stat
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
128
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 for dir in dirs:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 if curdir:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 curdir = '/'.join((curdir, dir))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 curdir = dir
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 dir_id = None
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 for item, stat, id in tree.iteritems():
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 if dir == item:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 dir_id = id
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 if dir_id:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 # Update tree
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 tree = self.repository._repo[dir_id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 if not isinstance(tree, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 raise ChangesetError('%s is not a directory' % curdir)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 raise ChangesetError('%s have not been found' % curdir)
2116
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
145
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
146 # cache all items from the given traversed tree
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
147 for item, stat, id in tree.iteritems():
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
148 if curdir:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
149 name = '/'.join((curdir, item))
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
150 else:
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
151 name = item
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
152 self._paths[name] = id
048811568c19 temporarly fixed git _get_id_for_path problem in vcs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2089
diff changeset
153 self._stat_modes[name] = stat
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 if not path in self._paths:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 raise NodeDoesNotExistError("There is no file nor directory "
3575
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
156 "at the given path '%s' at revision %s"
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 % (path, self.short_id))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 return self._paths[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 def _get_kind(self, path):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
161 obj = self.repository._repo[self._get_id_for_path(path)]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 if isinstance(obj, objects.Blob):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 return NodeKind.FILE
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 elif isinstance(obj, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 return NodeKind.DIR
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166
3039
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
167 def _get_filectx(self, path):
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
168 path = self._fix_path(path)
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
169 if self._get_kind(path) != NodeKind.FILE:
3575
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
170 raise ChangesetError("File does not exist for revision %s at "
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
171 " '%s'" % (self.raw_id, path))
3039
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
172 return path
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
173
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 def _get_file_nodes(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 return chain(*(t[2] for t in self.walk()))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 def parents(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 Returns list of parents changesets.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 return [self.repository.get_changeset(parent)
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
183 for parent in self._commit.parents]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
185 @LazyProperty
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
186 def children(self):
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
187 """
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
188 Returns list of children changesets.
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
189 """
3561
c04d1d9b6193 made git refs filter configurable ref issue #797
Marcin Kuzminski <marcin@python-works.com>
parents: 3496
diff changeset
190 rev_filter = _git_path = rhodecode.CONFIG.get('git_rev_filter',
c04d1d9b6193 made git refs filter configurable ref issue #797
Marcin Kuzminski <marcin@python-works.com>
parents: 3496
diff changeset
191 '--all').strip()
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
192 so, se = self.repository.run_git_command(
3561
c04d1d9b6193 made git refs filter configurable ref issue #797
Marcin Kuzminski <marcin@python-works.com>
parents: 3496
diff changeset
193 "rev-list %s --children | grep '^%s'" % (rev_filter, self.raw_id)
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
194 )
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
195
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
196 children = []
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
197 for l in so.splitlines():
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
198 childs = l.split(' ')[1:]
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
199 children.extend(childs)
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
200 return [self.repository.get_changeset(cs) for cs in children]
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
201
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 def next(self, branch=None):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 if branch and self.branch != branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 raise VCSError('Branch option used on changeset not belonging '
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 'to that branch')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 def _next(changeset, branch):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 try:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 next_ = changeset.revision + 1
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 next_rev = changeset.repository.revisions[next_]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 except IndexError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 raise ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 cs = changeset.repository.get_changeset(next_rev)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 if branch and branch != cs.branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 return _next(cs, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 return cs
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 return _next(self, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 def prev(self, branch=None):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 if branch and self.branch != branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 raise VCSError('Branch option used on changeset not belonging '
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 'to that branch')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 def _prev(changeset, branch):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 try:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 prev_ = changeset.revision - 1
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 if prev_ < 0:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 raise IndexError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 prev_rev = changeset.repository.revisions[prev_]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234 except IndexError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235 raise ChangesetDoesNotExistError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 cs = changeset.repository.get_changeset(prev_rev)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239 if branch and branch != cs.branch:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 return _prev(cs, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242 return cs
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244 return _prev(self, branch)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245
2384
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
246 def diff(self, ignore_whitespace=True, context=3):
2499
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
247 rev1 = self.parents[0] if self.parents else self.repository.EMPTY_CHANGESET
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
248 rev2 = self
c919d8c4f6a2 fixed git diff function when initial revision had no parents to compare with
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
249 return ''.join(self.repository.get_diff(rev1, rev2,
2384
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
250 ignore_whitespace=ignore_whitespace,
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
251 context=context))
5563af834d92 Added diff option into git and hg changeset objects, representing git formated patch against parent1
Marcin Kuzminski <marcin@python-works.com>
parents: 2297
diff changeset
252
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 def get_file_mode(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 Returns stat mode of the file at the given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
257 # ensure path is traversed
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258 self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259 return self._stat_modes[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261 def get_file_content(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263 Returns content of the file at given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
265 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 blob = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 return blob.as_pretty_string()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
269 def get_file_size(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
270 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
271 Returns size of the file at given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 blob = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 return blob.raw_length()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277 def get_file_changeset(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 Returns last commit of the file at the given ``path``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 """
3496
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
281 return self.get_file_history(path, limit=1)[0]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282
3496
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
283 def get_file_history(self, path, limit=None):
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
285 Returns history of file as reversed list of ``Changeset`` objects for
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 which file at given ``path`` has been modified.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 TODO: This function now uses os underlying 'git' and 'grep' commands
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 which is generally not good. Should be replaced with algorithm
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290 iterating commits.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 """
3496
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
292
3039
a520d542697e Implemented file history page for showing detailed changelog for a given file
Marcin Kuzminski <marcin@python-works.com>
parents: 3004
diff changeset
293 self._get_filectx(path)
3496
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
294 if limit:
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
295 cmd = 'log -n %s --pretty="format: %%H" -s -p %s -- "%s"' % (
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
296 safe_int(limit, 0), self.id, path
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
297 )
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
298 else:
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
299 cmd = 'log --pretty="format: %%H" -s -p %s -- "%s"' % (
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
300 self.id, path
58905069da21 Speed up of last_changeset extraction in VCS, in edge cases for git we can get 10x speed improvement by limiting the history extraction if we only need last changeset
Marcin Kuzminski <marcin@python-works.com>
parents: 3492
diff changeset
301 )
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 so, se = self.repository.run_git_command(cmd)
2276
8caaa9955f5e better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents: 2274
diff changeset
303 ids = re.findall(r'[0-9a-fA-F]{40}', so)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 return [self.repository.get_changeset(id) for id in ids]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305
3044
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
306 def get_file_history_2(self, path):
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
307 """
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
308 Returns history of file as reversed list of ``Changeset`` objects for
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
309 which file at given ``path`` has been modified.
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
310
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
311 """
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
312 self._get_filectx(path)
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
313 from dulwich.walk import Walker
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
314 include = [self.id]
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
315 walker = Walker(self.repository._repo.object_store, include,
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
316 paths=[path], max_entries=1)
3057
79c5967a1e5c whitespace and formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3044
diff changeset
317 return [self.repository.get_changeset(sha)
3044
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
318 for sha in (x.commit.id for x in walker)]
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
319
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
320 def get_file_annotate(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
321 """
3044
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
322 Returns a generator of four element tuples with
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
323 lineno, sha, changeset lazy loader and line
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 TODO: This function now uses os underlying 'git' command which is
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326 generally not good. Should be replaced with algorithm iterating
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327 commits.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329 cmd = 'blame -l --root -r %s -- "%s"' % (self.id, path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330 # -l ==> outputs long shas (and we need all 40 characters)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 # --root ==> doesn't put '^' character for bounderies
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 # -r sha ==> blames for the given revision
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
333 so, se = self.repository.run_git_command(cmd)
2448
c9b08fdcb788 fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents: 2384
diff changeset
334
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
335 for i, blame_line in enumerate(so.split('\n')[:-1]):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
336 ln_no = i + 1
3044
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
337 sha, line = re.split(r' ', blame_line, 1)
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 3039
diff changeset
338 yield (ln_no, sha, lambda: self.repository.get_changeset(sha), line)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
339
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
340 def fill_archive(self, stream=None, kind='tgz', prefix=None,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
341 subrepos=False):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
342 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
343 Fills up given stream.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
344
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
345 :param stream: file like object.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
346 :param kind: one of following: ``zip``, ``tgz`` or ``tbz2``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
347 Default: ``tgz``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
348 :param prefix: name of root directory in archive.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
349 Default is repository name and changeset's raw_id joined with dash
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
350 (``repo-tip.<KIND>``).
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
351 :param subrepos: include subrepos in this archive.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
352
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
353 :raise ImproperArchiveTypeError: If given kind is wrong.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
354 :raise VcsError: If given stream is None
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
355
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
356 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
357 allowed_kinds = settings.ARCHIVE_SPECS.keys()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
358 if kind not in allowed_kinds:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
359 raise ImproperArchiveTypeError('Archive kind not supported use one'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
360 'of %s', allowed_kinds)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
361
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
362 if prefix is None:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
363 prefix = '%s-%s' % (self.repository.name, self.short_id)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
364 elif prefix.startswith('/'):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
365 raise VCSError("Prefix cannot start with leading slash")
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
366 elif prefix.strip() == '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
367 raise VCSError("Prefix cannot be empty")
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
368
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
369 if kind == 'zip':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
370 frmt = 'zip'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
371 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
372 frmt = 'tar'
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3077
diff changeset
373 _git_path = rhodecode.CONFIG.get('git_path', 'git')
3394
fe2bb88bf7ac whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3376
diff changeset
374 cmd = '%s archive --format=%s --prefix=%s/ %s' % (_git_path,
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3077
diff changeset
375 frmt, prefix, self.raw_id)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
376 if kind == 'tgz':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
377 cmd += ' | gzip -9'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
378 elif kind == 'tbz2':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
379 cmd += ' | bzip2 -9'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
380
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
381 if stream is None:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
382 raise VCSError('You need to pass in a valid stream for filling'
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
383 ' with archival data')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
384 popen = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
385 cwd=self.repository.path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
386
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
387 buffer_size = 1024 * 8
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
388 chunk = popen.stdout.read(buffer_size)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
389 while chunk:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
390 stream.write(chunk)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
391 chunk = popen.stdout.read(buffer_size)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
392 # Make sure all descriptors would be read
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
393 popen.communicate()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
394
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
395 def get_nodes(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
396 if self._get_kind(path) != NodeKind.DIR:
3575
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
397 raise ChangesetError("Directory does not exist for revision %s at "
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
398 " '%s'" % (self.revision, path))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
399 path = self._fix_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
400 id = self._get_id_for_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
401 tree = self.repository._repo[id]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
402 dirnodes = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
403 filenodes = []
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
404 als = self.repository.alias
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
405 for name, stat, id in tree.iteritems():
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
406 if objects.S_ISGITLINK(stat):
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
407 dirnodes.append(SubModuleNode(name, url=None, changeset=id,
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
408 alias=als))
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
409 continue
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
410
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
411 obj = self.repository._repo.get_object(id)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
412 if path != '':
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
413 obj_path = '/'.join((path, name))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
414 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
415 obj_path = name
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
416 if obj_path not in self._stat_modes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
417 self._stat_modes[obj_path] = stat
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
418 if isinstance(obj, objects.Tree):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
419 dirnodes.append(DirNode(obj_path, changeset=self))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
420 elif isinstance(obj, objects.Blob):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
421 filenodes.append(FileNode(obj_path, changeset=self, mode=stat))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
422 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
423 raise ChangesetError("Requested object should be Tree "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
424 "or Blob, is %r" % type(obj))
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
425 nodes = dirnodes + filenodes
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426 for node in nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
427 if not node.path in self.nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
428 self.nodes[node.path] = node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
429 nodes.sort()
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
430 return nodes
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
431
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
432 def get_node(self, path):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
433 if isinstance(path, unicode):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
434 path = path.encode('utf-8')
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
435 path = self._fix_path(path)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
436 if not path in self.nodes:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
437 try:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
438 id_ = self._get_id_for_path(path)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
439 except ChangesetError:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
440 raise NodeDoesNotExistError("Cannot find one of parents' "
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
441 "directories for a given path: %s" % path)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
442
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
443 _GL = lambda m: m and objects.S_ISGITLINK(m)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
444 if _GL(self._stat_modes.get(path)):
2536
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
445 node = SubModuleNode(path, url=None, changeset=id_,
aaa41736ae51 Fixed lookup by Tag sha in git backend
Marcin Kuzminski <marcin@python-works.com>
parents: 2499
diff changeset
446 alias=self.repository.alias)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
447 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
448 obj = self.repository._repo.get_object(id_)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
449
2537
952dd2c95e45 When using tags in git use the link to Commit instead of messing with Tag object
Marcin Kuzminski <marcin@python-works.com>
parents: 2536
diff changeset
450 if isinstance(obj, objects.Tree):
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
451 if path == '':
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
452 node = RootNode(changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
453 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
454 node = DirNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
455 node._tree = obj
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
456 elif isinstance(obj, objects.Blob):
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
457 node = FileNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
458 node._blob = obj
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
459 else:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
460 raise NodeDoesNotExistError("There is no file nor directory "
3575
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3561
diff changeset
461 "at the given path '%s' at revision %s"
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
462 % (path, self.short_id))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
463 # cache node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
464 self.nodes[path] = node
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
465 return self.nodes[path]
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
466
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
467 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
468 def affected_files(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
469 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
470 Get's a fast accessible file changes for given changeset
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
471 """
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
472 a, m, d = self._changes_cache
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
473 return list(a.union(m).union(d))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
474
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
475 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
476 def _diff_name_status(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
477 output = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
478 for parent in self.parents:
2761
e64c64e2b8aa re implemented affected_files function for git using dulwich
Marcin Kuzminski <marcin@python-works.com>
parents: 2693
diff changeset
479 cmd = 'diff --name-status %s %s --encoding=utf8' % (parent.raw_id,
e64c64e2b8aa re implemented affected_files function for git using dulwich
Marcin Kuzminski <marcin@python-works.com>
parents: 2693
diff changeset
480 self.raw_id)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
481 so, se = self.repository.run_git_command(cmd)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
482 output.append(so.strip())
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
483 return '\n'.join(output)
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
484
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
485 @LazyProperty
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
486 def _changes_cache(self):
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
487 added = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
488 modified = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
489 deleted = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
490 _r = self.repository._repo
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
491
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
492 parents = self.parents
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
493 if not self.parents:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
494 parents = [EmptyChangeset()]
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
495 for parent in parents:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
496 if isinstance(parent, EmptyChangeset):
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
497 oid = None
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
498 else:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
499 oid = _r[parent.raw_id].tree
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
500 changes = _r.object_store.tree_changes(oid, _r[self.raw_id].tree)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
501 for (oldpath, newpath), (_, _), (_, _) in changes:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
502 if newpath and oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
503 modified.add(newpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
504 elif newpath and not oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
505 added.add(newpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
506 elif not newpath and oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
507 deleted.add(oldpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
508 return added, modified, deleted
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
509
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
510 def _get_paths_for_status(self, status):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
511 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
512 Returns sorted list of paths for given ``status``.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
513
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
514 :param status: one of: *added*, *modified* or *deleted*
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
515 """
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
516 a, m, d = self._changes_cache
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
517 return sorted({
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
518 'added': list(a),
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
519 'modified': list(m),
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
520 'deleted': list(d)}[status]
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
521 )
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
522
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
523 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
524 def added(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
525 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
526 Returns list of added ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
527 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
528 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
529 return list(self._get_file_nodes())
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
530 return AddedFileNodesGenerator([n for n in
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
531 self._get_paths_for_status('added')], self)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
532
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
533 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
534 def changed(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
535 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
536 Returns list of modified ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
537 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
538 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
539 return []
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
540 return ChangedFileNodesGenerator([n for n in
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
541 self._get_paths_for_status('modified')], self)
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
542
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
543 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
544 def removed(self):
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
545 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
546 Returns list of removed ``FileNode`` objects.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
547 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
548 if not self.parents:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
549 return []
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
550 return RemovedFileNodesGenerator([n for n in
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
551 self._get_paths_for_status('deleted')], self)