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