annotate rhodecode/lib/vcs/backends/git/changeset.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents a5888ca796b5
children 7e5f8c12a3fc
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
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
5
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
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
7 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
8 from rhodecode.lib.vcs.exceptions import (
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
9 RepositoryError, ChangesetError, NodeDoesNotExistError, VCSError,
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
10 ChangesetDoesNotExistError, ImproperArchiveTypeError
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
11 )
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
12 from rhodecode.lib.vcs.nodes import (
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
13 FileNode, DirNode, NodeKind, RootNode, RemovedFileNode, SubModuleNode,
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
14 ChangedFileNodesGenerator, AddedFileNodesGenerator, RemovedFileNodesGenerator
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
15 )
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
16 from rhodecode.lib.vcs.utils import (
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
17 safe_unicode, safe_str, safe_int, date_fromtimestamp
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
18 )
2007
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
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20
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 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
23 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 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
25 """
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 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
28 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
29 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
30
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 try:
3805
a5c234e934c5 synced with latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
32 commit = self.repository._repo[revision]
2543
03a770980b55 Synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 2537
diff changeset
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 self._commit = commit
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
42 self._tree_id = commit.tree
3492
0065f7fe60f6 fix spelling of committer
Mads Kiilerich <madski@unity3d.com>
parents: 3394
diff changeset
43 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
44 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
45 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
46 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
47 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
48
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 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
50 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
51
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 @LazyProperty
3805
a5c234e934c5 synced with latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
53 def message(self):
a5c234e934c5 synced with latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
54 return safe_unicode(self._commit.message)
a5c234e934c5 synced with latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
55
a5c234e934c5 synced with latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
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):
3912
91f440a11b94 fixes issues #849 IMC failed for non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 3805
diff changeset
107 path = safe_str(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
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"
3912
91f440a11b94 fixes issues #849 IMC failed for non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 3805
diff changeset
157 % (path, safe_str(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
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 """
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
190 rev_filter = _git_path = settings.GIT_REV_FILTER
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
191 so, se = self.repository.run_git_command(
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
192 "rev-list %s --children" % (rev_filter)
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
193 )
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 children = []
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
196 pat = re.compile(r'^%s' % self.raw_id)
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
197 for l in so.splitlines():
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
198 if pat.match(l):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
199 childs = l.split(' ')[1:]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
200 children.extend(childs)
3077
6d599a3c0d67 implemented children for git changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3057
diff changeset
201 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
202
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 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
204
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 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
206 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
207 '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
208
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 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
210 try:
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_ = 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
212 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
213 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
214 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
215 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
216
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 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
218 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
219
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 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
221
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 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
223
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 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
225 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
226 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
227 '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
228
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 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
230 try:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 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
232 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
233 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
234 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
235 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
236 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
237
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 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
239
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 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
241 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
242
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243 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
244
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 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
246
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
247 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
248 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
249 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
250 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
251 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
252 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
253
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254 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
255 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 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
257 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258 # ensure path is traversed
3912
91f440a11b94 fixes issues #849 IMC failed for non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 3805
diff changeset
259 path = safe_str(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
260 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
261 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
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 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
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 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
266 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 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
268 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
269 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
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 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
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 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
274 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
275 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
276 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
277 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
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 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
280 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 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
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 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
284
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
285 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
286 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 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
288 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
289
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290 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
291 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
292 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
293 """
3792
63adb3d5233a fixed some unicode problems with git file path
Marcin Kuzminski <marcin@python-works.com>
parents: 3575
diff changeset
294 self._get_filectx(path)
63adb3d5233a fixed some unicode problems with git file path
Marcin Kuzminski <marcin@python-works.com>
parents: 3575
diff changeset
295 cs_id = safe_str(self.id)
63adb3d5233a fixed some unicode problems with git file path
Marcin Kuzminski <marcin@python-works.com>
parents: 3575
diff changeset
296 f_path = safe_str(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
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 if limit:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
299 cmd = 'log -n %s --pretty="format: %%H" -s %s -- "%s"' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
300 safe_int(limit, 0), cs_id, f_path)
3792
63adb3d5233a fixed some unicode problems with git file path
Marcin Kuzminski <marcin@python-works.com>
parents: 3575
diff changeset
301
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
302 else:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
303 cmd = 'log --pretty="format: %%H" -s %s -- "%s"' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
304 cs_id, f_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
305 so, se = self.repository.run_git_command(cmd)
2276
8caaa9955f5e better regex for history
Marcin Kuzminski <marcin@python-works.com>
parents: 2274
diff changeset
306 ids = re.findall(r'[0-9a-fA-F]{40}', so)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
307 return [self.repository.get_changeset(sha) for sha in ids]
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308
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
309 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
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 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
312 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
313
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 """
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 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
316 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
317 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
318 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
319 paths=[path], max_entries=1)
3057
79c5967a1e5c whitespace and formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3044
diff changeset
320 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
321 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
322
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
323 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
324 """
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
325 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
326 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
327
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328 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
329 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
330 commits.
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 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
333 # -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
334 # --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
335 # -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
336 so, se = self.repository.run_git_command(cmd)
2448
c9b08fdcb788 fixed git annotate
Marcin Kuzminski <marcin@python-works.com>
parents: 2384
diff changeset
337
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 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
339 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
340 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
341 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
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 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
344 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
345 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
346 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
347
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 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
349 :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
350 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
351 :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
352 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
353 (``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
354 :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
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 :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
357 :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
358
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
359 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
360 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
361 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
362 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
363 '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
364
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
372 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
373 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
374 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
375 frmt = 'tar'
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
376 _git_path = settings.GIT_EXECUTABLE_PATH
3394
fe2bb88bf7ac whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3376
diff changeset
377 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
378 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
379 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
380 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
381 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
382 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
383
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
384 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
385 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
386 ' 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
387 popen = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4089
diff changeset
388 cwd=self.repository.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
389
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
390 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
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 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
393 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
394 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
395 # 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
396 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
397
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
398 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
399 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
400 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
401 " '%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
402 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
403 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
404 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
405 dirnodes = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
406 filenodes = []
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
407 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
408 for name, stat, id in tree.iteritems():
2232
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
409 if objects.S_ISGITLINK(stat):
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
410 dirnodes.append(SubModuleNode(name, url=None, changeset=id,
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
411 alias=als))
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
412 continue
49dc09e9f076 Implements subrepos view inside filebrowser
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
413
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
414 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
415 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
416 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
417 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 else:
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426 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
427 "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
428 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
429 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
430 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
431 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
432 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
433 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
434
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
435 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
436 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
437 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
438 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
439 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
440 try:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
441 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
442 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
443 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
444 "directories for a given path: %s" % path)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
445
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
446 _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
447 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
448 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
449 alias=self.repository.alias)
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
450 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
451 obj = self.repository._repo.get_object(id_)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
452
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
453 if isinstance(obj, objects.Tree):
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
454 if path == '':
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
455 node = RootNode(changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
456 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
457 node = DirNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
458 node._tree = obj
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
459 elif isinstance(obj, objects.Blob):
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
460 node = FileNode(path, changeset=self)
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
461 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
462 else:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2232
diff changeset
463 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
464 "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
465 % (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
466 # 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
467 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
468 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
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 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
471 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
472 """
4089
a5888ca796b5 Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents: 3912
diff changeset
473 Gets a fast accessible file changes for given changeset
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 """
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
475 added, modified, deleted = self._changes_cache
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
476 return list(added.union(modified).union(deleted))
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
477
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
478 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
479 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
480 output = []
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
481 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
482 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
483 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
484 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
485 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
486 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
487
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
488 @LazyProperty
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
489 def _changes_cache(self):
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
490 added = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
491 modified = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
492 deleted = set()
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
493 _r = self.repository._repo
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
494
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
495 parents = self.parents
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
496 if not self.parents:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
497 parents = [EmptyChangeset()]
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
498 for parent in parents:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
499 if isinstance(parent, EmptyChangeset):
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
500 oid = None
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
501 else:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
502 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
503 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
504 for (oldpath, newpath), (_, _), (_, _) in changes:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
505 if newpath and oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
506 modified.add(newpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
507 elif newpath and not oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
508 added.add(newpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
509 elif not newpath and oldpath:
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
510 deleted.add(oldpath)
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
511 return added, modified, deleted
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
512
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
513 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
514 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
515 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
516
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
517 :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
518 """
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
519 added, modified, deleted = self._changes_cache
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
520 return sorted({
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
521 'added': list(added),
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
522 'modified': list(modified),
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3792
diff changeset
523 'deleted': list(deleted)}[status]
2762
ba4fb9c441c6 new dulwich based implementation of added/modified/removed
Marcin Kuzminski <marcin@python-works.com>
parents: 2761
diff changeset
524 )
2007
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 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
527 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
528 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
529 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
530 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
531 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
532 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
533 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
534 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
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 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
537 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
538 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
539 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
540 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
541 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
542 return []
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
543 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
544 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
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 @LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
547 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
548 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
549 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
550 """
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
551 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
552 return []
2968
4abfb1afd9f5 fixes #630 git statistics do too much work making them slow.
Marcin Kuzminski <marcin@python-works.com>
parents: 2762
diff changeset
553 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
554 self._get_paths_for_status('deleted')], self)