##// END OF EJS Templates
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files...
marcink -
r2199:31ebf701 beta
parent child Browse files
Show More
@@ -306,10 +306,10 b' class FilesController(BaseRepoController'
306
306
307 try:
307 try:
308 self.scm_model.create_node(repo=c.rhodecode_repo,
308 self.scm_model.create_node(repo=c.rhodecode_repo,
309 repo_name=repo_name, cs=c.cs,
309 repo_name=repo_name, cs=c.cs,
310 user=self.rhodecode_user,
310 user=self.rhodecode_user,
311 author=author, message=message,
311 author=author, message=message,
312 content=content, f_path=node_path)
312 content=content, f_path=node_path)
313 h.flash(_('Successfully committed to %s' % node_path),
313 h.flash(_('Successfully committed to %s' % node_path),
314 category='success')
314 category='success')
315 except NodeAlreadyExistsError, e:
315 except NodeAlreadyExistsError, e:
@@ -73,7 +73,6 b' class GitChangeset(BaseChangeset):'
73 if ref:
73 if ref:
74 return safe_unicode(ref)
74 return safe_unicode(ref)
75
75
76
77 def _fix_path(self, path):
76 def _fix_path(self, path):
78 """
77 """
79 Paths are stored without trailing slash so we need to get rid off it if
78 Paths are stored without trailing slash so we need to get rid off it if
@@ -131,7 +130,6 b' class GitChangeset(BaseChangeset):'
131 name = item
130 name = item
132 self._paths[name] = id
131 self._paths[name] = id
133 self._stat_modes[name] = stat
132 self._stat_modes[name] = stat
134
135 if not path in self._paths:
133 if not path in self._paths:
136 raise NodeDoesNotExistError("There is no file nor directory "
134 raise NodeDoesNotExistError("There is no file nor directory "
137 "at the given path %r at revision %r"
135 "at the given path %r at revision %r"
@@ -393,7 +391,7 b' class GitChangeset(BaseChangeset):'
393 def _diff_name_status(self):
391 def _diff_name_status(self):
394 output = []
392 output = []
395 for parent in self.parents:
393 for parent in self.parents:
396 cmd = 'diff --name-status %s %s' % (parent.raw_id, self.raw_id)
394 cmd = 'diff --name-status %s %s --encoding=utf8' % (parent.raw_id, self.raw_id)
397 so, se = self.repository.run_git_command(cmd)
395 so, se = self.repository.run_git_command(cmd)
398 output.append(so.strip())
396 output.append(so.strip())
399 return '\n'.join(output)
397 return '\n'.join(output)
@@ -409,13 +407,16 b' class GitChangeset(BaseChangeset):'
409 for line in self._diff_name_status.splitlines():
407 for line in self._diff_name_status.splitlines():
410 if not line:
408 if not line:
411 continue
409 continue
410
412 if line.startswith(char):
411 if line.startswith(char):
413 splitted = line.split(char,1)
412 splitted = line.split(char, 1)
414 if not len(splitted) == 2:
413 if not len(splitted) == 2:
415 raise VCSError("Couldn't parse diff result:\n%s\n\n and "
414 raise VCSError("Couldn't parse diff result:\n%s\n\n and "
416 "particularly that line: %s" % (self._diff_name_status,
415 "particularly that line: %s" % (self._diff_name_status,
417 line))
416 line))
418 paths.add(splitted[1].strip())
417 _path = splitted[1].strip()
418 paths.add(_path)
419
419 return sorted(paths)
420 return sorted(paths)
420
421
421 @LazyProperty
422 @LazyProperty
@@ -5,12 +5,13 b' from dulwich import objects'
5 from dulwich.repo import Repo
5 from dulwich.repo import Repo
6 from rhodecode.lib.vcs.backends.base import BaseInMemoryChangeset
6 from rhodecode.lib.vcs.backends.base import BaseInMemoryChangeset
7 from rhodecode.lib.vcs.exceptions import RepositoryError
7 from rhodecode.lib.vcs.exceptions import RepositoryError
8 from rhodecode.lib.vcs.utils import safe_str
8
9
9
10
10 class GitInMemoryChangeset(BaseInMemoryChangeset):
11 class GitInMemoryChangeset(BaseInMemoryChangeset):
11
12
12 def commit(self, message, author, parents=None, branch=None, date=None,
13 def commit(self, message, author, parents=None, branch=None, date=None,
13 **kwargs):
14 **kwargs):
14 """
15 """
15 Performs in-memory commit (doesn't check workdir in any way) and
16 Performs in-memory commit (doesn't check workdir in any way) and
16 returns newly created ``Changeset``. Updates repository's
17 returns newly created ``Changeset``. Updates repository's
@@ -120,9 +121,9 b' class GitInMemoryChangeset(BaseInMemoryC'
120 commit = objects.Commit()
121 commit = objects.Commit()
121 commit.tree = commit_tree.id
122 commit.tree = commit_tree.id
122 commit.parents = [p._commit.id for p in self.parents if p]
123 commit.parents = [p._commit.id for p in self.parents if p]
123 commit.author = commit.committer = author
124 commit.author = commit.committer = safe_str(author)
124 commit.encoding = ENCODING
125 commit.encoding = ENCODING
125 commit.message = message + ' '
126 commit.message = safe_str(message) + ' '
126
127
127 # Compute date
128 # Compute date
128 if date is None:
129 if date is None:
@@ -79,11 +79,13 b' class GitRepository(BaseRepository):'
79 :param cmd: git command to be executed
79 :param cmd: git command to be executed
80 """
80 """
81
81
82 #cmd = '(cd %s && git %s)' % (self.path, cmd)
82 _copts = ['-c', 'core.quotepath=false', ]
83
83 if isinstance(cmd, basestring):
84 if isinstance(cmd, basestring):
84 cmd = 'GIT_CONFIG_NOGLOBAL=1 git %s' % cmd
85 cmd = [cmd]
85 else:
86
86 cmd = ['GIT_CONFIG_NOGLOBAL=1', 'git'] + cmd
87 cmd = ['GIT_CONFIG_NOGLOBAL=1', 'git'] + _copts + cmd
88
87 try:
89 try:
88 opts = dict(
90 opts = dict(
89 shell=isinstance(cmd, basestring),
91 shell=isinstance(cmd, basestring),
@@ -4,7 +4,7 b' import errno'
4 from rhodecode.lib.vcs.backends.base import BaseInMemoryChangeset
4 from rhodecode.lib.vcs.backends.base import BaseInMemoryChangeset
5 from rhodecode.lib.vcs.exceptions import RepositoryError
5 from rhodecode.lib.vcs.exceptions import RepositoryError
6
6
7 from ...utils.hgcompat import memfilectx, memctx, hex
7 from ...utils.hgcompat import memfilectx, memctx, hex, tolocal
8
8
9
9
10 class MercurialInMemoryChangeset(BaseInMemoryChangeset):
10 class MercurialInMemoryChangeset(BaseInMemoryChangeset):
@@ -30,9 +30,9 b' class MercurialInMemoryChangeset(BaseInM'
30 self.check_integrity(parents)
30 self.check_integrity(parents)
31
31
32 from .repository import MercurialRepository
32 from .repository import MercurialRepository
33 if not isinstance(message, str) or not isinstance(author, str):
33 if not isinstance(message, unicode) or not isinstance(author, unicode):
34 raise RepositoryError('Given message and author needs to be '
34 raise RepositoryError('Given message and author needs to be '
35 'an <str> instance')
35 'an <unicode> instance')
36
36
37 if branch is None:
37 if branch is None:
38 branch = MercurialRepository.DEFAULT_BRANCH_NAME
38 branch = MercurialRepository.DEFAULT_BRANCH_NAME
@@ -70,7 +70,7 b' class MercurialInMemoryChangeset(BaseInM'
70 copied=False)
70 copied=False)
71
71
72 raise RepositoryError("Given path haven't been marked as added,"
72 raise RepositoryError("Given path haven't been marked as added,"
73 "changed or removed (%s)" % path)
73 "changed or removed (%s)" % path)
74
74
75 parents = [None, None]
75 parents = [None, None]
76 for i, parent in enumerate(self.parents):
76 for i, parent in enumerate(self.parents):
@@ -89,9 +89,11 b' class MercurialInMemoryChangeset(BaseInM'
89 date=date,
89 date=date,
90 extra=kwargs)
90 extra=kwargs)
91
91
92 loc = lambda u: tolocal(u.encode('utf-8'))
93
92 # injecting given _repo params
94 # injecting given _repo params
93 commit_ctx._text = message
95 commit_ctx._text = loc(message)
94 commit_ctx._user = author
96 commit_ctx._user = loc(author)
95 commit_ctx._date = date
97 commit_ctx._date = date
96
98
97 # TODO: Catch exceptions!
99 # TODO: Catch exceptions!
@@ -120,6 +120,10 b' class Node(object):'
120 return None
120 return None
121
121
122 @LazyProperty
122 @LazyProperty
123 def unicode_path(self):
124 return safe_unicode(self.path)
125
126 @LazyProperty
123 def name(self):
127 def name(self):
124 """
128 """
125 Returns name of the node so if its path
129 Returns name of the node so if its path
@@ -1,6 +1,7 b''
1 """Mercurial libs compatibility
1 """
2 Mercurial libs compatibility
3 """
2
4
3 """
4 from mercurial import archival, merge as hg_merge, patch, ui
5 from mercurial import archival, merge as hg_merge, patch, ui
5 from mercurial.commands import clone, nullid, pull
6 from mercurial.commands import clone, nullid, pull
6 from mercurial.context import memctx, memfilectx
7 from mercurial.context import memctx, memfilectx
@@ -10,3 +11,4 b' from mercurial.localrepo import localrep'
10 from mercurial.match import match
11 from mercurial.match import match
11 from mercurial.mdiff import diffopts
12 from mercurial.mdiff import diffopts
12 from mercurial.node import hex
13 from mercurial.node import hex
14 from mercurial.encoding import tolocal No newline at end of file
@@ -35,7 +35,7 b' from rhodecode.lib.vcs.nodes import File'
35
35
36 from rhodecode import BACKENDS
36 from rhodecode import BACKENDS
37 from rhodecode.lib import helpers as h
37 from rhodecode.lib import helpers as h
38 from rhodecode.lib.utils2 import safe_str
38 from rhodecode.lib.utils2 import safe_str, safe_unicode
39 from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
39 from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
40 from rhodecode.lib.utils import get_repos as get_filesystem_repos, make_ui, \
40 from rhodecode.lib.utils import get_repos as get_filesystem_repos, make_ui, \
41 action_logger, EmptyChangeset, REMOVED_REPO_PAT
41 action_logger, EmptyChangeset, REMOVED_REPO_PAT
@@ -369,14 +369,16 b' class ScmModel(BaseModel):'
369 # decoding here will force that we have proper encoded values
369 # decoding here will force that we have proper encoded values
370 # in any other case this will throw exceptions and deny commit
370 # in any other case this will throw exceptions and deny commit
371 content = safe_str(content)
371 content = safe_str(content)
372 message = safe_str(message)
373 path = safe_str(f_path)
372 path = safe_str(f_path)
374 author = safe_str(author)
373 # message and author needs to be unicode
374 # proper backend should then translate that into required type
375 message = safe_unicode(message)
376 author = safe_unicode(author)
375 m = IMC(repo)
377 m = IMC(repo)
376 m.change(FileNode(path, content))
378 m.change(FileNode(path, content))
377 tip = m.commit(message=message,
379 tip = m.commit(message=message,
378 author=author,
380 author=author,
379 parents=[cs], branch=cs.branch)
381 parents=[cs], branch=cs.branch)
380
382
381 new_cs = tip.short_id
383 new_cs = tip.short_id
382 action = 'push_local:%s' % new_cs
384 action = 'push_local:%s' % new_cs
@@ -403,21 +405,21 b' class ScmModel(BaseModel):'
403 type(content)
405 type(content)
404 ))
406 ))
405
407
406 message = safe_str(message)
408 message = safe_unicode(message)
409 author = safe_unicode(author)
407 path = safe_str(f_path)
410 path = safe_str(f_path)
408 author = safe_str(author)
409 m = IMC(repo)
411 m = IMC(repo)
410
412
411 if isinstance(cs, EmptyChangeset):
413 if isinstance(cs, EmptyChangeset):
412 # Emptychangeset means we we're editing empty repository
414 # EmptyChangeset means we we're editing empty repository
413 parents = None
415 parents = None
414 else:
416 else:
415 parents = [cs]
417 parents = [cs]
416
418
417 m.add(FileNode(path, content=content))
419 m.add(FileNode(path, content=content))
418 tip = m.commit(message=message,
420 tip = m.commit(message=message,
419 author=author,
421 author=author,
420 parents=parents, branch=cs.branch)
422 parents=parents, branch=cs.branch)
421 new_cs = tip.short_id
423 new_cs = tip.short_id
422 action = 'push_local:%s' % new_cs
424 action = 'push_local:%s' % new_cs
423
425
@@ -56,7 +56,7 b''
56 % endif
56 % endif
57 </div>
57 </div>
58 </div>
58 </div>
59 <div class="commit">${_('Editing file')}: ${c.file.path}</div>
59 <div class="commit">${_('Editing file')}: ${c.file.unicode_path}</div>
60 </div>
60 </div>
61 <pre id="editor_pre"></pre>
61 <pre id="editor_pre"></pre>
62 <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
62 <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
General Comments 0
You need to be logged in to leave comments. Login now