comparison mercurial/subrepo.py @ 13181:413bef846806

subrepo: fix subrelpath for git subrepos This patch conforms gitsubrepo code to the variable naming scheme of the other subrepo implementations. All user-facing path references should be relative to the root repository.
author Eric Eisner <ede@mit.edu>
date Mon, 20 Dec 2010 13:59:33 -0500
parents a79e0688a5ee
children 2537bd17421d
comparison
equal deleted inserted replaced
13180:a79e0688a5ee 13181:413bef846806
170 parent = parent._subparent 170 parent = parent._subparent
171 return repo.root[len(parent.root)+1:] 171 return repo.root[len(parent.root)+1:]
172 172
173 def subrelpath(sub): 173 def subrelpath(sub):
174 """return path to this subrepo as seen from outermost repo""" 174 """return path to this subrepo as seen from outermost repo"""
175 if hasattr(sub, '_relpath'):
176 return sub._relpath
175 if not hasattr(sub, '_repo'): 177 if not hasattr(sub, '_repo'):
176 return sub._path 178 return sub._path
177 return reporelpath(sub._repo) 179 return reporelpath(sub._repo)
178 180
179 def _abssource(repo, push=False, abort=True): 181 def _abssource(repo, push=False, abort=True):
615 class gitsubrepo(abstractsubrepo): 617 class gitsubrepo(abstractsubrepo):
616 def __init__(self, ctx, path, state): 618 def __init__(self, ctx, path, state):
617 # TODO add git version check. 619 # TODO add git version check.
618 self._state = state 620 self._state = state
619 self._ctx = ctx 621 self._ctx = ctx
620 self._relpath = path 622 self._path = path
621 self._path = ctx._repo.wjoin(path) 623 self._relpath = os.path.join(reporelpath(ctx._repo), path)
624 self._abspath = ctx._repo.wjoin(path)
622 self._ui = ctx._repo.ui 625 self._ui = ctx._repo.ui
623 626
624 def _gitcommand(self, commands, env=None, stream=False): 627 def _gitcommand(self, commands, env=None, stream=False):
625 return self._gitdir(commands, env=env, stream=stream)[0] 628 return self._gitdir(commands, env=env, stream=stream)[0]
626 629
627 def _gitdir(self, commands, env=None, stream=False): 630 def _gitdir(self, commands, env=None, stream=False):
628 return self._gitnodir(commands, env=env, stream=stream, cwd=self._path) 631 return self._gitnodir(commands, env=env, stream=stream,
632 cwd=self._abspath)
629 633
630 def _gitnodir(self, commands, env=None, stream=False, cwd=None): 634 def _gitnodir(self, commands, env=None, stream=False, cwd=None):
631 """Calls the git command 635 """Calls the git command
632 636
633 The methods tries to call the git command. versions previor to 1.6.0 637 The methods tries to call the git command. versions previor to 1.6.0
709 tracking['refs/remotes/%s/%s' % 713 tracking['refs/remotes/%s/%s' %
710 (remote, ref.split('/', 2)[2])] = b 714 (remote, ref.split('/', 2)[2])] = b
711 return tracking 715 return tracking
712 716
713 def _fetch(self, source, revision): 717 def _fetch(self, source, revision):
714 if not os.path.exists('%s/.git' % self._path): 718 if not os.path.exists(os.path.join(self._abspath, '.git')):
715 self._ui.status(_('cloning subrepo %s\n') % self._relpath) 719 self._ui.status(_('cloning subrepo %s\n') % self._relpath)
716 self._gitnodir(['clone', source, self._path]) 720 self._gitnodir(['clone', source, self._abspath])
717 if self._githavelocally(revision): 721 if self._githavelocally(revision):
718 return 722 return
719 self._ui.status(_('pulling subrepo %s\n') % self._relpath) 723 self._ui.status(_('pulling subrepo %s\n') % self._relpath)
720 # first try from origin 724 # first try from origin
721 self._gitcommand(['fetch']) 725 self._gitcommand(['fetch'])
723 return 727 return
724 # then try from known subrepo source 728 # then try from known subrepo source
725 self._gitcommand(['fetch', source]) 729 self._gitcommand(['fetch', source])
726 if not self._githavelocally(revision): 730 if not self._githavelocally(revision):
727 raise util.Abort(_("revision %s does not exist in subrepo %s\n") % 731 raise util.Abort(_("revision %s does not exist in subrepo %s\n") %
728 (revision, self._path)) 732 (revision, self._relpath))
729 733
730 def dirty(self, ignoreupdate=False): 734 def dirty(self, ignoreupdate=False):
731 # version checked out changed? 735 # version checked out changed?
732 if not ignoreupdate and self._state[1] != self._gitstate(): 736 if not ignoreupdate and self._state[1] != self._gitstate():
733 return True 737 return True
857 return False 861 return False
858 862
859 def remove(self): 863 def remove(self):
860 if self.dirty(): 864 if self.dirty():
861 self._ui.warn(_('not removing repo %s because ' 865 self._ui.warn(_('not removing repo %s because '
862 'it has changes.\n') % self._path) 866 'it has changes.\n') % self._relpath)
863 return 867 return
864 # we can't fully delete the repository as it may contain 868 # we can't fully delete the repository as it may contain
865 # local-only history 869 # local-only history
866 self._ui.note(_('removing subrepo %s\n') % self._path) 870 self._ui.note(_('removing subrepo %s\n') % self._relpath)
867 self._gitcommand(['config', 'core.bare', 'true']) 871 self._gitcommand(['config', 'core.bare', 'true'])
868 for f in os.listdir(self._path): 872 for f in os.listdir(self._abspath):
869 if f == '.git': 873 if f == '.git':
870 continue 874 continue
871 path = os.path.join(self._path, f) 875 path = os.path.join(self._abspath, f)
872 if os.path.isdir(path) and not os.path.islink(path): 876 if os.path.isdir(path) and not os.path.islink(path):
873 shutil.rmtree(path) 877 shutil.rmtree(path)
874 else: 878 else:
875 os.remove(path) 879 os.remove(path)
876 880
890 continue 894 continue
891 if info.issym(): 895 if info.issym():
892 data = info.linkname 896 data = info.linkname
893 else: 897 else:
894 data = tar.extractfile(info).read() 898 data = tar.extractfile(info).read()
895 archiver.addfile(os.path.join(prefix, self._relpath, info.name), 899 archiver.addfile(os.path.join(prefix, self._path, info.name),
896 info.mode, info.issym(), data) 900 info.mode, info.issym(), data)
897 ui.progress(_('archiving (%s)') % relpath, i + 1, 901 ui.progress(_('archiving (%s)') % relpath, i + 1,
898 unit=_('files')) 902 unit=_('files'))
899 ui.progress(_('archiving (%s)') % relpath, None) 903 ui.progress(_('archiving (%s)') % relpath, None)
900 904