comparison mercurial/subrepo.py @ 14052:ecaa78594983

merge with stable
author Matt Mackall <mpm@selenic.com>
date Sat, 30 Apr 2011 03:44:31 -0500
parents 92db9667d15a 9e8a9d45945c
children 924c82157d46
comparison
equal deleted inserted replaced
14049:92db9667d15a 14052:ecaa78594983
8 import errno, os, re, xml.dom.minidom, shutil, posixpath 8 import errno, os, re, xml.dom.minidom, shutil, posixpath
9 import stat, subprocess, tarfile 9 import stat, subprocess, tarfile
10 from i18n import _ 10 from i18n import _
11 import config, scmutil, util, node, error, cmdutil, url, bookmarks 11 import config, scmutil, util, node, error, cmdutil, url, bookmarks
12 hg = None 12 hg = None
13 propertycache = util.propertycache
13 14
14 nullstate = ('', '', 'empty') 15 nullstate = ('', '', 'empty')
15 16
16 def state(ctx, ui): 17 def state(ctx, ui):
17 """return a state dict, mapping subrepo paths configured in .hgsub 18 """return a state dict, mapping subrepo paths configured in .hgsub
509 self._state = state 510 self._state = state
510 self._ctx = ctx 511 self._ctx = ctx
511 self._ui = ctx._repo.ui 512 self._ui = ctx._repo.ui
512 513
513 def _svncommand(self, commands, filename=''): 514 def _svncommand(self, commands, filename=''):
514 path = os.path.join(self._ctx._repo.origroot, self._path, filename)
515 cmd = ['svn'] 515 cmd = ['svn']
516 # Starting in svn 1.5 --non-interactive is a global flag 516 # Starting in svn 1.5 --non-interactive is a global flag
517 # instead of being per-command, but we need to support 1.4 so 517 # instead of being per-command, but we need to support 1.4 so
518 # we have to be intelligent about what commands take 518 # we have to be intelligent about what commands take
519 # --non-interactive. 519 # --non-interactive.
520 if (not self._ui.interactive() and 520 if (not self._ui.interactive() and
521 commands[0] in ('update', 'checkout', 'commit')): 521 commands[0] in ('update', 'checkout', 'commit')):
522 cmd.append('--non-interactive') 522 cmd.append('--non-interactive')
523 cmd.extend(commands) 523 cmd.extend(commands)
524 cmd.append(path) 524 if filename is not None:
525 path = os.path.join(self._ctx._repo.origroot, self._path, filename)
526 cmd.append(path)
525 env = dict(os.environ) 527 env = dict(os.environ)
526 # Avoid localized output, preserve current locale for everything else. 528 # Avoid localized output, preserve current locale for everything else.
527 env['LC_MESSAGES'] = 'C' 529 env['LC_MESSAGES'] = 'C'
528 p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds, 530 p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds,
529 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 531 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
531 stdout, stderr = p.communicate() 533 stdout, stderr = p.communicate()
532 stderr = stderr.strip() 534 stderr = stderr.strip()
533 if stderr: 535 if stderr:
534 raise util.Abort(stderr) 536 raise util.Abort(stderr)
535 return stdout 537 return stdout
538
539 @propertycache
540 def _svnversion(self):
541 output = self._svncommand(['--version'], filename=None)
542 m = re.search(r'^svn,\s+version\s+(\d+)\.(\d+)', output)
543 if not m:
544 raise util.Abort(_('cannot retrieve svn tool version'))
545 return (int(m.group(1)), int(m.group(2)))
536 546
537 def _wcrevs(self): 547 def _wcrevs(self):
538 # Get the working directory revision as well as the last 548 # Get the working directory revision as well as the last
539 # commit revision so we can compare the subrepo state with 549 # commit revision so we can compare the subrepo state with
540 # both. We used to store the working directory one. 550 # both. We used to store the working directory one.
626 pass 636 pass
627 637
628 def get(self, state, overwrite=False): 638 def get(self, state, overwrite=False):
629 if overwrite: 639 if overwrite:
630 self._svncommand(['revert', '--recursive']) 640 self._svncommand(['revert', '--recursive'])
631 status = self._svncommand(['checkout', state[0], '--revision', state[1]]) 641 args = ['checkout']
642 if self._svnversion >= (1, 5):
643 args.append('--force')
644 args.extend([state[0], '--revision', state[1]])
645 status = self._svncommand(args)
632 if not re.search('Checked out revision [0-9]+.', status): 646 if not re.search('Checked out revision [0-9]+.', status):
633 raise util.Abort(status.splitlines()[-1]) 647 raise util.Abort(status.splitlines()[-1])
634 self._ui.status(status) 648 self._ui.status(status)
635 649
636 def merge(self, state): 650 def merge(self, state):