2009-06-15 11:45:38 +04:00
|
|
|
# subrepo.py - sub-repository handling for Mercurial
|
|
|
|
#
|
2010-02-06 12:23:18 +03:00
|
|
|
# Copyright 2009-2010 Matt Mackall <mpm@selenic.com>
|
2009-06-15 11:45:38 +04:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2014-12-01 06:47:53 +03:00
|
|
|
import copy
|
2015-04-10 18:47:09 +03:00
|
|
|
import errno, os, re, posixpath, sys
|
2013-09-20 18:15:37 +04:00
|
|
|
import xml.dom.minidom
|
2010-11-19 03:20:21 +03:00
|
|
|
import stat, subprocess, tarfile
|
2009-06-15 11:45:38 +04:00
|
|
|
from i18n import _
|
2014-10-14 09:52:27 +04:00
|
|
|
import config, util, node, error, cmdutil, scmutil, match as matchmod
|
2013-11-13 10:55:30 +04:00
|
|
|
import phases
|
2013-11-07 03:19:04 +04:00
|
|
|
import pathutil
|
2014-09-25 12:42:49 +04:00
|
|
|
import exchange
|
2009-07-04 17:18:15 +04:00
|
|
|
hg = None
|
2011-03-04 16:00:49 +03:00
|
|
|
propertycache = util.propertycache
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2010-01-01 02:10:03 +03:00
|
|
|
nullstate = ('', '', 'empty')
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2013-02-16 04:21:40 +04:00
|
|
|
def _expandedabspath(path):
|
|
|
|
'''
|
|
|
|
get a path or url and if it is a path expand it and return an absolute path
|
|
|
|
'''
|
|
|
|
expandedpath = util.urllocalpath(util.expandpath(path))
|
|
|
|
u = util.url(expandedpath)
|
|
|
|
if not u.scheme:
|
|
|
|
path = util.normpath(os.path.abspath(u.path))
|
|
|
|
return path
|
2013-02-16 03:07:00 +04:00
|
|
|
|
|
|
|
def _getstorehashcachename(remotepath):
|
|
|
|
'''get a unique filename for the store hash cache of a remote repository'''
|
2013-02-16 04:21:40 +04:00
|
|
|
return util.sha1(_expandedabspath(remotepath)).hexdigest()[0:12]
|
2013-02-16 03:07:00 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
class SubrepoAbort(error.Abort):
|
|
|
|
"""Exception class used to avoid handling a subrepo error more than once"""
|
2013-01-03 20:35:58 +04:00
|
|
|
def __init__(self, *args, **kw):
|
2013-01-10 22:35:37 +04:00
|
|
|
error.Abort.__init__(self, *args, **kw)
|
2013-01-03 20:35:58 +04:00
|
|
|
self.subrepo = kw.get('subrepo')
|
2013-02-07 07:54:09 +04:00
|
|
|
self.cause = kw.get('cause')
|
2012-12-14 02:37:53 +04:00
|
|
|
|
|
|
|
def annotatesubrepoerror(func):
|
|
|
|
def decoratedmethod(self, *args, **kargs):
|
|
|
|
try:
|
|
|
|
res = func(self, *args, **kargs)
|
|
|
|
except SubrepoAbort, ex:
|
|
|
|
# This exception has already been handled
|
|
|
|
raise ex
|
|
|
|
except error.Abort, ex:
|
2013-01-03 20:35:58 +04:00
|
|
|
subrepo = subrelpath(self)
|
2013-01-03 20:42:25 +04:00
|
|
|
errormsg = str(ex) + ' ' + _('(in subrepo %s)') % subrepo
|
2012-12-14 02:37:53 +04:00
|
|
|
# avoid handling this exception by raising a SubrepoAbort exception
|
2013-02-07 07:54:09 +04:00
|
|
|
raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo,
|
|
|
|
cause=sys.exc_info())
|
2012-12-14 02:37:53 +04:00
|
|
|
return res
|
|
|
|
return decoratedmethod
|
|
|
|
|
2010-07-15 20:10:05 +04:00
|
|
|
def state(ctx, ui):
|
2010-07-15 15:24:02 +04:00
|
|
|
"""return a state dict, mapping subrepo paths configured in .hgsub
|
|
|
|
to tuple: (source from .hgsub, revision from .hgsubstate, kind
|
|
|
|
(key in types dict))
|
|
|
|
"""
|
2009-06-15 11:45:38 +04:00
|
|
|
p = config.config()
|
|
|
|
def read(f, sections=None, remap=None):
|
|
|
|
if f in ctx:
|
2010-11-19 01:05:10 +03:00
|
|
|
try:
|
|
|
|
data = ctx[f].data()
|
|
|
|
except IOError, err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
# handle missing subrepo spec files as removed
|
2015-04-05 22:08:55 +03:00
|
|
|
ui.warn(_("warning: subrepo spec file \'%s\' not found\n") %
|
|
|
|
util.pathto(ctx.repo().root, ctx.repo().getcwd(), f))
|
2010-11-19 01:05:10 +03:00
|
|
|
return
|
|
|
|
p.parse(f, data, sections, remap, read)
|
2010-01-01 02:25:46 +03:00
|
|
|
else:
|
2015-04-05 22:08:55 +03:00
|
|
|
repo = ctx.repo()
|
|
|
|
raise util.Abort(_("subrepo spec file \'%s\' not found") %
|
|
|
|
util.pathto(repo.root, repo.getcwd(), f))
|
2010-01-01 02:25:46 +03:00
|
|
|
|
|
|
|
if '.hgsub' in ctx:
|
|
|
|
read('.hgsub')
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2010-07-15 20:10:05 +04:00
|
|
|
for path, src in ui.configitems('subpaths'):
|
|
|
|
p.set('subpaths', path, src, ui.configsource('subpaths', path))
|
|
|
|
|
2010-12-17 15:38:15 +03:00
|
|
|
rev = {}
|
|
|
|
if '.hgsubstate' in ctx:
|
|
|
|
try:
|
2012-05-04 16:19:55 +04:00
|
|
|
for i, l in enumerate(ctx['.hgsubstate'].data().splitlines()):
|
2012-05-04 16:19:52 +04:00
|
|
|
l = l.lstrip()
|
|
|
|
if not l:
|
|
|
|
continue
|
2012-05-04 16:19:55 +04:00
|
|
|
try:
|
|
|
|
revision, path = l.split(" ", 1)
|
|
|
|
except ValueError:
|
2015-04-05 22:08:55 +03:00
|
|
|
repo = ctx.repo()
|
2012-05-04 16:19:55 +04:00
|
|
|
raise util.Abort(_("invalid subrepository revision "
|
2015-04-05 22:08:55 +03:00
|
|
|
"specifier in \'%s\' line %d")
|
|
|
|
% (util.pathto(repo.root, repo.getcwd(),
|
|
|
|
'.hgsubstate'), (i + 1)))
|
2010-12-17 15:38:15 +03:00
|
|
|
rev[path] = revision
|
|
|
|
except IOError, err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2011-09-22 16:39:49 +04:00
|
|
|
def remap(src):
|
2010-07-15 20:10:05 +04:00
|
|
|
for pattern, repl in p.items('subpaths'):
|
2010-08-19 15:25:46 +04:00
|
|
|
# Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
|
|
|
|
# does a string decode.
|
|
|
|
repl = repl.encode('string-escape')
|
|
|
|
# However, we still want to allow back references to go
|
|
|
|
# through unharmed, so we turn r'\\1' into r'\1'. Again,
|
|
|
|
# extra escapes are needed because re.sub string decodes.
|
|
|
|
repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl)
|
2010-07-15 20:10:05 +04:00
|
|
|
try:
|
|
|
|
src = re.sub(pattern, repl, src, 1)
|
|
|
|
except re.error, e:
|
|
|
|
raise util.Abort(_("bad subrepository pattern in %s: %s")
|
|
|
|
% (p.source('subpaths', pattern), e))
|
2011-09-22 16:39:49 +04:00
|
|
|
return src
|
2010-07-15 20:10:05 +04:00
|
|
|
|
2011-09-22 16:39:49 +04:00
|
|
|
state = {}
|
|
|
|
for path, src in p[''].items():
|
|
|
|
kind = 'hg'
|
|
|
|
if src.startswith('['):
|
|
|
|
if ']' not in src:
|
|
|
|
raise util.Abort(_('missing ] in subrepo source'))
|
|
|
|
kind, src = src.split(']', 1)
|
|
|
|
kind = kind[1:]
|
2011-09-22 17:15:18 +04:00
|
|
|
src = src.lstrip() # strip any extra whitespace after ']'
|
|
|
|
|
|
|
|
if not util.url(src).isabs():
|
2015-03-13 05:59:52 +03:00
|
|
|
parent = _abssource(ctx.repo(), abort=False)
|
2011-09-22 17:15:18 +04:00
|
|
|
if parent:
|
|
|
|
parent = util.url(parent)
|
|
|
|
parent.path = posixpath.join(parent.path or '', src)
|
|
|
|
parent.path = posixpath.normpath(parent.path)
|
|
|
|
joined = str(parent)
|
|
|
|
# Remap the full joined path and use it if it changes,
|
|
|
|
# else remap the original source.
|
|
|
|
remapped = remap(joined)
|
|
|
|
if remapped == joined:
|
|
|
|
src = remap(src)
|
|
|
|
else:
|
|
|
|
src = remapped
|
|
|
|
|
2011-09-22 16:39:49 +04:00
|
|
|
src = remap(src)
|
2011-12-24 14:05:35 +04:00
|
|
|
state[util.pconvert(path)] = (src.strip(), rev.get(path, ''), kind)
|
2009-06-15 11:45:38 +04:00
|
|
|
|
|
|
|
return state
|
2009-06-15 11:45:38 +04:00
|
|
|
|
|
|
|
def writestate(repo, state):
|
2010-07-15 15:24:02 +04:00
|
|
|
"""rewrite .hgsubstate in (outer) repo with these subrepo states"""
|
2011-05-27 13:01:44 +04:00
|
|
|
lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)]
|
|
|
|
repo.wwrite('.hgsubstate', ''.join(lines), '')
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2011-01-31 15:33:41 +03:00
|
|
|
def submerge(repo, wctx, mctx, actx, overwrite):
|
2010-07-15 15:24:02 +04:00
|
|
|
"""delegated from merge.applyupdates: merging of .hgsubstate file
|
|
|
|
in working context, merging context and ancestor context"""
|
2009-06-15 11:45:38 +04:00
|
|
|
if mctx == actx: # backwards?
|
|
|
|
actx = wctx.p1()
|
|
|
|
s1 = wctx.substate
|
|
|
|
s2 = mctx.substate
|
|
|
|
sa = actx.substate
|
|
|
|
sm = {}
|
|
|
|
|
2009-11-08 19:24:18 +03:00
|
|
|
repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx))
|
|
|
|
|
2009-11-08 01:29:49 +03:00
|
|
|
def debug(s, msg, r=""):
|
|
|
|
if r:
|
2010-01-01 02:10:03 +03:00
|
|
|
r = "%s:%s:%s" % r
|
2009-11-08 19:24:18 +03:00
|
|
|
repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r))
|
2009-11-08 01:29:49 +03:00
|
|
|
|
2012-12-12 05:38:14 +04:00
|
|
|
for s, l in sorted(s1.iteritems()):
|
2010-07-01 08:56:35 +04:00
|
|
|
a = sa.get(s, nullstate)
|
2010-06-30 02:30:42 +04:00
|
|
|
ld = l # local state with possible dirty flag for compares
|
2010-07-01 08:56:35 +04:00
|
|
|
if wctx.sub(s).dirty():
|
2010-06-30 02:30:42 +04:00
|
|
|
ld = (l[0], l[1] + "+")
|
2010-07-01 08:56:35 +04:00
|
|
|
if wctx == actx: # overwrite
|
|
|
|
a = ld
|
2010-06-30 02:30:42 +04:00
|
|
|
|
2009-06-15 11:45:38 +04:00
|
|
|
if s in s2:
|
|
|
|
r = s2[s]
|
2010-06-30 02:30:42 +04:00
|
|
|
if ld == r or r == a: # no change or local is newer
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = l
|
|
|
|
continue
|
2010-06-30 02:30:42 +04:00
|
|
|
elif ld == a: # other side changed
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "other changed, get", r)
|
2011-01-31 15:33:41 +03:00
|
|
|
wctx.sub(s).get(r, overwrite)
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = r
|
2010-06-30 02:30:42 +04:00
|
|
|
elif ld[0] != r[0]: # sources differ
|
2009-06-21 03:13:19 +04:00
|
|
|
if repo.ui.promptchoice(
|
2009-06-15 11:45:38 +04:00
|
|
|
_(' subrepository sources for %s differ\n'
|
2013-05-23 02:31:43 +04:00
|
|
|
'use (l)ocal source (%s) or (r)emote source (%s)?'
|
|
|
|
'$$ &Local $$ &Remote') % (s, l[0], r[0]), 0):
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "prompt changed, get", r)
|
2011-01-31 15:33:41 +03:00
|
|
|
wctx.sub(s).get(r, overwrite)
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = r
|
2010-06-30 02:30:42 +04:00
|
|
|
elif ld[1] == a[1]: # local side is unchanged
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "other side changed, get", r)
|
2011-01-31 15:33:41 +03:00
|
|
|
wctx.sub(s).get(r, overwrite)
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = r
|
|
|
|
else:
|
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1378420708 -7200
# Fri Sep 06 00:38:28 2013 +0200
# Node ID 2fb9cb0c7b26303ac3178b7739975e663075857d
# Parent 796d34e1b749b79834321ef1181ed8433a5515d9
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
2013-09-06 02:38:28 +04:00
|
|
|
debug(s, "both sides changed")
|
2014-05-07 02:13:22 +04:00
|
|
|
srepo = wctx.sub(s)
|
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1378420708 -7200
# Fri Sep 06 00:38:28 2013 +0200
# Node ID 2fb9cb0c7b26303ac3178b7739975e663075857d
# Parent 796d34e1b749b79834321ef1181ed8433a5515d9
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
2013-09-06 02:38:28 +04:00
|
|
|
option = repo.ui.promptchoice(
|
|
|
|
_(' subrepository %s diverged (local revision: %s, '
|
|
|
|
'remote revision: %s)\n'
|
|
|
|
'(M)erge, keep (l)ocal or keep (r)emote?'
|
|
|
|
'$$ &Merge $$ &Local $$ &Remote')
|
2014-05-07 02:13:22 +04:00
|
|
|
% (s, srepo.shortid(l[1]), srepo.shortid(r[1])), 0)
|
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1378420708 -7200
# Fri Sep 06 00:38:28 2013 +0200
# Node ID 2fb9cb0c7b26303ac3178b7739975e663075857d
# Parent 796d34e1b749b79834321ef1181ed8433a5515d9
merge: let the user choose to merge, keep local or keep remote subrepo revisions
When a subrepo has changed on the local and remote revisions, prompt the user
whether it wants to merge those subrepo revisions, keep the local revision or
keep the remote revision.
Up until now mercurial would always perform a merge on a subrepo that had
changed on the local and the remote revisions. This is often inconvenient. For
example:
- You may want to perform the actual subrepo merge after you have merged the
parent subrepo files.
- Some subrepos may be considered "read only", in the sense that you are not
supposed to add new revisions to them. In those cases "merging a subrepo" means
choosing which _existing_ revision you want to use on the merged revision. This
is often the case for subrepos that contain binary dependencies (such as DLLs,
etc).
This new prompt makes mercurial better cope with those common scenarios.
Notes:
- The default behavior (which is the one that is used when ui is not
interactive) remains unchanged (i.e. merge is the default action).
- This prompt will be shown even if the ui --tool flag is set.
- I don't know of a way to test the "keep local" and "keep remote" options (i.e.
to force the test to choose those options).
2013-09-06 02:38:28 +04:00
|
|
|
if option == 0:
|
|
|
|
wctx.sub(s).merge(r)
|
|
|
|
sm[s] = l
|
|
|
|
debug(s, "merge with", r)
|
|
|
|
elif option == 1:
|
|
|
|
sm[s] = l
|
|
|
|
debug(s, "keep local subrepo revision", l)
|
|
|
|
else:
|
|
|
|
wctx.sub(s).get(r, overwrite)
|
|
|
|
sm[s] = r
|
|
|
|
debug(s, "get remote subrepo revision", r)
|
2010-06-30 02:30:42 +04:00
|
|
|
elif ld == a: # remote removed, local unchanged
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "remote removed, remove")
|
2009-06-15 11:45:38 +04:00
|
|
|
wctx.sub(s).remove()
|
2011-05-24 07:49:10 +04:00
|
|
|
elif a == nullstate: # not present in remote or ancestor
|
|
|
|
debug(s, "local added, keep")
|
|
|
|
sm[s] = l
|
|
|
|
continue
|
2009-06-15 11:45:38 +04:00
|
|
|
else:
|
2009-06-21 03:13:19 +04:00
|
|
|
if repo.ui.promptchoice(
|
2009-06-15 11:45:38 +04:00
|
|
|
_(' local changed subrepository %s which remote removed\n'
|
2013-05-23 02:31:43 +04:00
|
|
|
'use (c)hanged version or (d)elete?'
|
|
|
|
'$$ &Changed $$ &Delete') % s, 0):
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "prompt remove")
|
2009-06-15 11:45:38 +04:00
|
|
|
wctx.sub(s).remove()
|
|
|
|
|
2011-04-03 03:57:17 +04:00
|
|
|
for s, r in sorted(s2.items()):
|
2009-06-15 11:45:38 +04:00
|
|
|
if s in s1:
|
|
|
|
continue
|
|
|
|
elif s not in sa:
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "remote added, get", r)
|
2010-01-01 01:30:34 +03:00
|
|
|
mctx.sub(s).get(r)
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = r
|
|
|
|
elif r != sa[s]:
|
2009-06-21 03:13:19 +04:00
|
|
|
if repo.ui.promptchoice(
|
2009-06-15 11:45:38 +04:00
|
|
|
_(' remote changed subrepository %s which local removed\n'
|
2013-05-23 02:31:43 +04:00
|
|
|
'use (c)hanged version or (d)elete?'
|
|
|
|
'$$ &Changed $$ &Delete') % s, 0) == 0:
|
2009-11-08 19:24:18 +03:00
|
|
|
debug(s, "prompt recreate", r)
|
2015-02-18 10:20:55 +03:00
|
|
|
mctx.sub(s).get(r)
|
2009-06-15 11:45:38 +04:00
|
|
|
sm[s] = r
|
|
|
|
|
|
|
|
# record merged .hgsubstate
|
|
|
|
writestate(repo, sm)
|
2013-08-22 00:34:04 +04:00
|
|
|
return sm
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2011-02-09 12:53:09 +03:00
|
|
|
def _updateprompt(ui, sub, dirty, local, remote):
|
|
|
|
if dirty:
|
|
|
|
msg = (_(' subrepository sources for %s differ\n'
|
2014-10-01 03:08:17 +04:00
|
|
|
'use (l)ocal source (%s) or (r)emote source (%s)?'
|
2013-05-23 02:31:43 +04:00
|
|
|
'$$ &Local $$ &Remote')
|
2011-02-09 12:53:09 +03:00
|
|
|
% (subrelpath(sub), local, remote))
|
|
|
|
else:
|
2012-05-12 17:54:54 +04:00
|
|
|
msg = (_(' subrepository sources for %s differ (in checked out '
|
|
|
|
'version)\n'
|
2014-10-01 03:08:17 +04:00
|
|
|
'use (l)ocal source (%s) or (r)emote source (%s)?'
|
2013-05-23 02:31:43 +04:00
|
|
|
'$$ &Local $$ &Remote')
|
2011-02-09 12:53:09 +03:00
|
|
|
% (subrelpath(sub), local, remote))
|
2013-05-23 02:31:43 +04:00
|
|
|
return ui.promptchoice(msg, 0)
|
2011-02-09 12:53:09 +03:00
|
|
|
|
2010-10-19 05:55:28 +04:00
|
|
|
def subrelpath(sub):
|
2010-07-15 15:24:02 +04:00
|
|
|
"""return path to this subrepo as seen from outermost repo"""
|
2015-04-09 18:36:42 +03:00
|
|
|
return sub._relpath
|
2010-05-02 01:05:22 +04:00
|
|
|
|
2010-10-19 05:56:20 +04:00
|
|
|
def _abssource(repo, push=False, abort=True):
|
|
|
|
"""return pull/push path of repo - either based on parent repo .hgsub info
|
|
|
|
or on the top repo config. Abort or return None if no source found."""
|
2011-07-26 00:53:22 +04:00
|
|
|
if util.safehasattr(repo, '_subparent'):
|
2011-04-30 20:43:20 +04:00
|
|
|
source = util.url(repo._subsource)
|
2011-06-30 01:01:06 +04:00
|
|
|
if source.isabs():
|
2011-03-26 08:59:04 +03:00
|
|
|
return str(source)
|
2011-06-30 01:01:06 +04:00
|
|
|
source.path = posixpath.normpath(source.path)
|
2010-10-19 05:56:20 +04:00
|
|
|
parent = _abssource(repo._subparent, push, abort=False)
|
|
|
|
if parent:
|
2011-11-15 05:16:30 +04:00
|
|
|
parent = util.url(util.pconvert(parent))
|
2011-08-26 18:23:35 +04:00
|
|
|
parent.path = posixpath.join(parent.path or '', source.path)
|
2011-03-26 08:59:04 +03:00
|
|
|
parent.path = posixpath.normpath(parent.path)
|
|
|
|
return str(parent)
|
2010-10-19 05:56:20 +04:00
|
|
|
else: # recursion reached top repo
|
2011-07-26 00:53:22 +04:00
|
|
|
if util.safehasattr(repo, '_subtoppath'):
|
2010-10-27 02:28:40 +04:00
|
|
|
return repo._subtoppath
|
2010-10-19 05:56:20 +04:00
|
|
|
if push and repo.ui.config('paths', 'default-push'):
|
|
|
|
return repo.ui.config('paths', 'default-push')
|
|
|
|
if repo.ui.config('paths', 'default'):
|
|
|
|
return repo.ui.config('paths', 'default')
|
2014-12-21 02:19:10 +03:00
|
|
|
if repo.shared():
|
subrepo: use sharepath if available when locating the source repo
This is an alternative fix for issue3518, enabling sharing of repositories with
subrepos, without unconditionally setting the default path in the resulting
repo's hgrc file. Better test coverage is added here, but won't prove this code
is working until f48752441ca0 is backed out.
The problem with the original fix is, if a default path is not available to be
copied over from the share source, the default path on the resulting repo is set
to the source location. Since that's where the actual repository is stored, the
path is essentially self-referential, so push, pull, incoming and outgoing
effectively operate on itself. While incoming and outgoing make it look like
nothing was changed, push currently hangs (see issue3657). In this case where
there is not a real default path, these operations should abort with
"default(-push) not found", like the source repo would. Note this problem with
the original fix affected repos without subrepos too.
2012-11-28 05:56:27 +04:00
|
|
|
# chop off the .hg component to get the default path form
|
|
|
|
return os.path.dirname(repo.sharedpath)
|
2010-10-19 05:56:20 +04:00
|
|
|
if abort:
|
2012-12-14 02:37:53 +04:00
|
|
|
raise util.Abort(_("default path for subrepository not found"))
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2015-04-11 17:00:04 +03:00
|
|
|
def _sanitize(ui, vfs, ignore):
|
2015-04-11 17:00:04 +03:00
|
|
|
for dirname, dirs, names in vfs.walk():
|
2014-05-08 14:03:00 +04:00
|
|
|
for i, d in enumerate(dirs):
|
|
|
|
if d.lower() == ignore:
|
|
|
|
del dirs[i]
|
|
|
|
break
|
2013-11-25 23:50:36 +04:00
|
|
|
if os.path.basename(dirname).lower() != '.hg':
|
2014-05-08 14:03:00 +04:00
|
|
|
continue
|
2013-11-25 23:50:36 +04:00
|
|
|
for f in names:
|
|
|
|
if f.lower() == 'hgrc':
|
2014-05-08 14:03:00 +04:00
|
|
|
ui.warn(_("warning: removing potentially hostile 'hgrc' "
|
2015-04-11 17:00:04 +03:00
|
|
|
"in '%s'\n") % vfs.join(dirname))
|
|
|
|
vfs.unlink(vfs.reljoin(dirname, f))
|
2013-11-25 23:50:36 +04:00
|
|
|
|
2009-06-15 11:45:38 +04:00
|
|
|
def subrepo(ctx, path):
|
2010-07-15 15:24:02 +04:00
|
|
|
"""return instance of the right subrepo class for subrepo in path"""
|
2009-06-15 11:45:38 +04:00
|
|
|
# subrepo inherently violates our import layering rules
|
|
|
|
# because it wants to make repo objects from deep inside the stack
|
|
|
|
# so we manually delay the circular imports to not break
|
|
|
|
# scripts that don't use our demand-loading
|
2009-07-04 17:18:15 +04:00
|
|
|
global hg
|
|
|
|
import hg as h
|
2009-06-15 11:45:38 +04:00
|
|
|
hg = h
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2015-03-13 05:59:52 +03:00
|
|
|
pathutil.pathauditor(ctx.repo().root)(path)
|
2012-05-20 22:11:34 +04:00
|
|
|
state = ctx.substate[path]
|
2010-01-01 02:10:03 +03:00
|
|
|
if state[2] not in types:
|
2010-01-31 20:02:16 +03:00
|
|
|
raise util.Abort(_('unknown subrepo type %s') % state[2])
|
2010-01-01 02:10:03 +03:00
|
|
|
return types[state[2]](ctx, path, state[:2])
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2013-11-13 10:55:30 +04:00
|
|
|
def newcommitphase(ui, ctx):
|
|
|
|
commitphase = phases.newcommitphase(ui)
|
|
|
|
substate = getattr(ctx, "substate", None)
|
|
|
|
if not substate:
|
|
|
|
return commitphase
|
|
|
|
check = ui.config('phases', 'checksubrepos', 'follow')
|
|
|
|
if check not in ('ignore', 'follow', 'abort'):
|
|
|
|
raise util.Abort(_('invalid phases.checksubrepos configuration: %s')
|
|
|
|
% (check))
|
|
|
|
if check == 'ignore':
|
|
|
|
return commitphase
|
|
|
|
maxphase = phases.public
|
|
|
|
maxsub = None
|
|
|
|
for s in sorted(substate):
|
|
|
|
sub = ctx.sub(s)
|
|
|
|
subphase = sub.phase(substate[s][1])
|
|
|
|
if maxphase < subphase:
|
|
|
|
maxphase = subphase
|
|
|
|
maxsub = s
|
|
|
|
if commitphase < maxphase:
|
|
|
|
if check == 'abort':
|
|
|
|
raise util.Abort(_("can't commit in %s phase"
|
|
|
|
" conflicting %s from subrepository %s") %
|
|
|
|
(phases.phasenames[commitphase],
|
|
|
|
phases.phasenames[maxphase], maxsub))
|
|
|
|
ui.warn(_("warning: changes are committed in"
|
|
|
|
" %s phase from subrepository %s\n") %
|
|
|
|
(phases.phasenames[maxphase], maxsub))
|
|
|
|
return maxphase
|
|
|
|
return commitphase
|
|
|
|
|
2010-07-14 22:25:31 +04:00
|
|
|
# subrepo classes need to implement the following abstract class:
|
|
|
|
|
|
|
|
class abstractsubrepo(object):
|
|
|
|
|
2015-04-09 18:36:42 +03:00
|
|
|
def __init__(self, ctx, path):
|
|
|
|
"""Initialize abstractsubrepo part
|
|
|
|
|
|
|
|
``ctx`` is the context referring this subrepository in the
|
|
|
|
parent repository.
|
|
|
|
|
|
|
|
``path`` is the path to this subrepositiry as seen from
|
|
|
|
innermost repository.
|
|
|
|
"""
|
|
|
|
self.ui = ctx.repo().ui
|
|
|
|
self._ctx = ctx
|
|
|
|
self._path = path
|
2014-11-27 00:13:38 +03:00
|
|
|
|
2013-02-16 04:11:20 +04:00
|
|
|
def storeclean(self, path):
|
|
|
|
"""
|
|
|
|
returns true if the repository has not changed since it was last
|
|
|
|
cloned from or pushed to a given repository.
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2010-12-08 07:14:43 +03:00
|
|
|
def dirty(self, ignoreupdate=False):
|
|
|
|
"""returns true if the dirstate of the subrepo is dirty or does not
|
|
|
|
match current stored state. If ignoreupdate is true, only check
|
|
|
|
whether the subrepo has uncommitted changes in its dirstate.
|
2010-07-14 22:25:31 +04:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2015-03-25 07:55:32 +03:00
|
|
|
def dirtyreason(self, ignoreupdate=False):
|
|
|
|
"""return reason string if it is ``dirty()``
|
|
|
|
|
|
|
|
Returned string should have enough information for the message
|
|
|
|
of exception.
|
|
|
|
|
|
|
|
This returns None, otherwise.
|
|
|
|
"""
|
|
|
|
if self.dirty(ignoreupdate=ignoreupdate):
|
|
|
|
return _("uncommitted changes in subrepository '%s'"
|
|
|
|
) % subrelpath(self)
|
|
|
|
|
2015-03-25 07:55:35 +03:00
|
|
|
def bailifchanged(self, ignoreupdate=False):
|
|
|
|
"""raise Abort if subrepository is ``dirty()``
|
|
|
|
"""
|
|
|
|
dirtyreason = self.dirtyreason(ignoreupdate=ignoreupdate)
|
|
|
|
if dirtyreason:
|
|
|
|
raise util.Abort(dirtyreason)
|
|
|
|
|
2012-02-07 01:00:08 +04:00
|
|
|
def basestate(self):
|
|
|
|
"""current working directory base state, disregarding .hgsubstate
|
|
|
|
state and working directory modifications"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2010-09-27 01:11:04 +04:00
|
|
|
def checknested(self, path):
|
2010-09-03 14:58:51 +04:00
|
|
|
"""check if path is a subrepository within this repository"""
|
|
|
|
return False
|
|
|
|
|
2010-07-14 22:25:31 +04:00
|
|
|
def commit(self, text, user, date):
|
|
|
|
"""commit the current changes to the subrepo with the given
|
|
|
|
log message. Use given user and date if possible. Return the
|
|
|
|
new state of the subrepo.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-11-13 10:55:30 +04:00
|
|
|
def phase(self, state):
|
|
|
|
"""returns phase of specified state in the subrepository.
|
|
|
|
"""
|
|
|
|
return phases.public
|
|
|
|
|
2010-07-14 22:25:31 +04:00
|
|
|
def remove(self):
|
|
|
|
"""remove the subrepo
|
|
|
|
|
|
|
|
(should verify the dirstate is not dirty first)
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2011-01-31 15:33:41 +03:00
|
|
|
def get(self, state, overwrite=False):
|
2010-07-14 22:25:31 +04:00
|
|
|
"""run whatever commands are needed to put the subrepo into
|
|
|
|
this state
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2011-02-09 15:37:21 +03:00
|
|
|
def merge(self, state):
|
2010-07-14 22:25:31 +04:00
|
|
|
"""merge currently-saved state with the new state."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2011-09-29 19:20:04 +04:00
|
|
|
def push(self, opts):
|
2010-07-15 16:11:14 +04:00
|
|
|
"""perform whatever action is analogous to 'hg push'
|
2010-07-14 22:25:31 +04:00
|
|
|
|
|
|
|
This may be a no-op on some systems.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2015-01-28 04:57:43 +03:00
|
|
|
def add(self, ui, match, prefix, explicitonly, **opts):
|
2010-09-13 15:09:20 +04:00
|
|
|
return []
|
2010-07-14 22:25:31 +04:00
|
|
|
|
2014-11-25 06:27:49 +03:00
|
|
|
def addremove(self, matcher, prefix, opts, dry_run, similarity):
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn("%s: %s" % (prefix, _("addremove is not supported")))
|
2014-11-25 06:27:49 +03:00
|
|
|
return 1
|
|
|
|
|
2014-12-13 22:26:38 +03:00
|
|
|
def cat(self, match, prefix, **opts):
|
2014-03-15 05:32:05 +04:00
|
|
|
return 1
|
|
|
|
|
2010-09-03 14:58:51 +04:00
|
|
|
def status(self, rev2, **opts):
|
2014-10-14 09:52:27 +04:00
|
|
|
return scmutil.status([], [], [], [], [], [], [])
|
2010-09-03 14:58:51 +04:00
|
|
|
|
2012-11-29 19:43:55 +04:00
|
|
|
def diff(self, ui, diffopts, node2, match, prefix, **opts):
|
2010-09-03 14:58:51 +04:00
|
|
|
pass
|
|
|
|
|
2010-09-13 15:09:26 +04:00
|
|
|
def outgoing(self, ui, dest, opts):
|
|
|
|
return 1
|
|
|
|
|
2010-09-13 15:09:31 +04:00
|
|
|
def incoming(self, ui, source, opts):
|
|
|
|
return 1
|
|
|
|
|
2010-09-20 17:44:30 +04:00
|
|
|
def files(self):
|
|
|
|
"""return filename iterator"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def filedata(self, name):
|
|
|
|
"""return file data"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def fileflags(self, name):
|
|
|
|
"""return file flags"""
|
|
|
|
return ''
|
|
|
|
|
2015-03-19 06:03:41 +03:00
|
|
|
def printfiles(self, ui, m, fm, fmt):
|
|
|
|
"""handle the files command for this subrepo"""
|
|
|
|
return 1
|
|
|
|
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
def archive(self, archiver, prefix, match=None):
|
2012-06-17 06:34:06 +04:00
|
|
|
if match is not None:
|
|
|
|
files = [f for f in self.files() if match(f)]
|
|
|
|
else:
|
|
|
|
files = self.files()
|
2010-11-29 18:34:10 +03:00
|
|
|
total = len(files)
|
|
|
|
relpath = subrelpath(self)
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, 0,
|
|
|
|
unit=_('files'), total=total)
|
2010-11-29 18:34:10 +03:00
|
|
|
for i, name in enumerate(files):
|
2010-09-20 17:46:17 +04:00
|
|
|
flags = self.fileflags(name)
|
|
|
|
mode = 'x' in flags and 0755 or 0644
|
|
|
|
symlink = 'l' in flags
|
2015-04-09 18:36:42 +03:00
|
|
|
archiver.addfile(self.wvfs.reljoin(prefix, self._path, name),
|
2010-09-20 17:46:17 +04:00
|
|
|
mode, symlink, self.filedata(name))
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, i + 1,
|
|
|
|
unit=_('files'), total=total)
|
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, None)
|
2013-03-22 01:09:15 +04:00
|
|
|
return total
|
2010-09-20 17:46:17 +04:00
|
|
|
|
2011-11-02 09:17:11 +04:00
|
|
|
def walk(self, match):
|
|
|
|
'''
|
|
|
|
walk recursively through the directory tree, finding all files
|
|
|
|
matched by the match function
|
|
|
|
'''
|
|
|
|
pass
|
2010-09-20 17:46:17 +04:00
|
|
|
|
2014-12-14 03:23:30 +03:00
|
|
|
def forget(self, match, prefix):
|
2012-04-27 13:02:16 +04:00
|
|
|
return ([], [])
|
2011-11-10 04:46:51 +04:00
|
|
|
|
2014-12-14 03:36:50 +03:00
|
|
|
def removefiles(self, matcher, prefix, after, force, subrepos):
|
2014-11-16 05:36:19 +03:00
|
|
|
"""remove the matched files from the subrepository and the filesystem,
|
|
|
|
possibly by force and/or after the file has been removed from the
|
|
|
|
filesystem. Return 0 on success, 1 on any warning.
|
|
|
|
"""
|
|
|
|
return 1
|
|
|
|
|
2014-12-14 03:44:55 +03:00
|
|
|
def revert(self, substate, *pats, **opts):
|
|
|
|
self.ui.warn('%s: reverting %s subrepos is unsupported\n' \
|
2012-04-20 01:36:42 +04:00
|
|
|
% (substate[0], substate[2]))
|
2012-03-28 13:42:17 +04:00
|
|
|
return []
|
|
|
|
|
2014-05-07 02:08:20 +04:00
|
|
|
def shortid(self, revid):
|
|
|
|
return revid
|
|
|
|
|
2015-04-09 18:36:42 +03:00
|
|
|
@propertycache
|
|
|
|
def wvfs(self):
|
|
|
|
"""return vfs to access the working directory of this subrepository
|
|
|
|
"""
|
|
|
|
return scmutil.vfs(self._ctx.repo().wvfs.join(self._path))
|
|
|
|
|
2015-04-09 18:36:42 +03:00
|
|
|
@propertycache
|
|
|
|
def _relpath(self):
|
|
|
|
"""return path to this subrepository as seen from outermost repository
|
|
|
|
"""
|
2015-04-09 18:36:42 +03:00
|
|
|
repo = self._ctx.repo()
|
|
|
|
parent = repo
|
|
|
|
while util.safehasattr(parent, '_subparent'):
|
|
|
|
parent = parent._subparent
|
|
|
|
reporelpath = repo.root[len(pathutil.normasprefix(parent.root)):]
|
|
|
|
|
|
|
|
return self.wvfs.reljoin(reporelpath, self._path)
|
2015-04-09 18:36:42 +03:00
|
|
|
|
2010-07-14 22:25:31 +04:00
|
|
|
class hgsubrepo(abstractsubrepo):
|
2009-06-15 11:45:38 +04:00
|
|
|
def __init__(self, ctx, path, state):
|
2015-04-09 18:36:42 +03:00
|
|
|
super(hgsubrepo, self).__init__(ctx, path)
|
2009-06-15 11:45:38 +04:00
|
|
|
self._state = state
|
2015-03-13 05:59:52 +03:00
|
|
|
r = ctx.repo()
|
2009-06-15 11:45:38 +04:00
|
|
|
root = r.wjoin(path)
|
2014-11-19 12:35:14 +03:00
|
|
|
create = not r.wvfs.exists('%s/.hg' % path)
|
2012-09-29 15:11:24 +04:00
|
|
|
self._repo = hg.repository(r.baseui, root, create=create)
|
2014-12-14 04:43:01 +03:00
|
|
|
self.ui = self._repo.ui
|
2012-09-29 15:11:24 +04:00
|
|
|
for s, k in [('ui', 'commitsubrepos')]:
|
|
|
|
v = r.ui.config(s, k)
|
|
|
|
if v:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.setconfig(s, k, v, 'subrepo')
|
|
|
|
self.ui.setconfig('ui', '_usedassubrepo', 'True', 'subrepo')
|
2011-05-09 19:15:44 +04:00
|
|
|
self._initrepo(r, state[0], create)
|
|
|
|
|
2013-02-16 04:18:53 +04:00
|
|
|
def storeclean(self, path):
|
|
|
|
lock = self._repo.lock()
|
2014-06-19 19:21:19 +04:00
|
|
|
try:
|
|
|
|
return self._storeclean(path)
|
|
|
|
finally:
|
|
|
|
lock.release()
|
|
|
|
|
|
|
|
def _storeclean(self, path):
|
|
|
|
clean = True
|
2013-02-16 04:18:53 +04:00
|
|
|
itercache = self._calcstorehash(path)
|
|
|
|
try:
|
|
|
|
for filehash in self._readstorehashcache(path):
|
|
|
|
if filehash != itercache.next():
|
|
|
|
clean = False
|
|
|
|
break
|
|
|
|
except StopIteration:
|
|
|
|
# the cached and current pull states have a different size
|
|
|
|
clean = False
|
|
|
|
if clean:
|
|
|
|
try:
|
|
|
|
itercache.next()
|
|
|
|
# the cached and current pull states have a different size
|
|
|
|
clean = False
|
|
|
|
except StopIteration:
|
|
|
|
pass
|
|
|
|
return clean
|
|
|
|
|
|
|
|
def _calcstorehash(self, remotepath):
|
|
|
|
'''calculate a unique "store hash"
|
|
|
|
|
|
|
|
This method is used to to detect when there are changes that may
|
|
|
|
require a push to a given remote path.'''
|
|
|
|
# sort the files that will be hashed in increasing (likely) file size
|
|
|
|
filelist = ('bookmarks', 'store/phaseroots', 'store/00changelog.i')
|
2013-02-16 04:21:40 +04:00
|
|
|
yield '# %s\n' % _expandedabspath(remotepath)
|
2014-11-19 12:35:14 +03:00
|
|
|
vfs = self._repo.vfs
|
2013-02-16 04:18:53 +04:00
|
|
|
for relname in filelist:
|
2014-11-19 12:35:14 +03:00
|
|
|
filehash = util.sha1(vfs.tryread(relname)).hexdigest()
|
|
|
|
yield '%s = %s\n' % (relname, filehash)
|
2013-02-16 04:18:53 +04:00
|
|
|
|
2014-11-19 12:35:14 +03:00
|
|
|
@propertycache
|
|
|
|
def _cachestorehashvfs(self):
|
|
|
|
return scmutil.vfs(self._repo.join('cache/storehash'))
|
|
|
|
|
2013-02-16 04:18:53 +04:00
|
|
|
def _readstorehashcache(self, remotepath):
|
|
|
|
'''read the store hash cache for a given remote repository'''
|
2014-11-19 12:35:14 +03:00
|
|
|
cachefile = _getstorehashcachename(remotepath)
|
|
|
|
return self._cachestorehashvfs.tryreadlines(cachefile, 'r')
|
2013-02-16 04:18:53 +04:00
|
|
|
|
|
|
|
def _cachestorehash(self, remotepath):
|
|
|
|
'''cache the current store hash
|
|
|
|
|
|
|
|
Each remote repo requires its own store hash cache, because a subrepo
|
|
|
|
store may be "clean" versus a given remote repo, but not versus another
|
|
|
|
'''
|
2014-11-19 12:35:14 +03:00
|
|
|
cachefile = _getstorehashcachename(remotepath)
|
2013-02-16 04:18:53 +04:00
|
|
|
lock = self._repo.lock()
|
2014-06-19 19:21:19 +04:00
|
|
|
try:
|
|
|
|
storehash = list(self._calcstorehash(remotepath))
|
2014-11-19 12:35:14 +03:00
|
|
|
vfs = self._cachestorehashvfs
|
|
|
|
vfs.writelines(cachefile, storehash, mode='w', notindexed=True)
|
2014-06-19 19:21:19 +04:00
|
|
|
finally:
|
|
|
|
lock.release()
|
2013-02-16 04:18:53 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-05-09 19:15:44 +04:00
|
|
|
def _initrepo(self, parentrepo, source, create):
|
|
|
|
self._repo._subparent = parentrepo
|
|
|
|
self._repo._subsource = source
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2010-03-12 03:23:35 +03:00
|
|
|
if create:
|
2014-06-19 19:42:35 +04:00
|
|
|
lines = ['[paths]\n']
|
2010-03-12 03:23:35 +03:00
|
|
|
|
|
|
|
def addpathconfig(key, value):
|
2010-10-19 05:56:20 +04:00
|
|
|
if value:
|
2014-06-19 19:42:35 +04:00
|
|
|
lines.append('%s = %s\n' % (key, value))
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.setconfig('paths', key, value, 'subrepo')
|
2010-03-12 03:23:35 +03:00
|
|
|
|
2010-10-19 05:56:20 +04:00
|
|
|
defpath = _abssource(self._repo, abort=False)
|
|
|
|
defpushpath = _abssource(self._repo, True, abort=False)
|
2010-03-12 03:23:35 +03:00
|
|
|
addpathconfig('default', defpath)
|
2010-03-14 02:28:10 +03:00
|
|
|
if defpath != defpushpath:
|
|
|
|
addpathconfig('default-push', defpushpath)
|
2014-06-19 19:42:35 +04:00
|
|
|
|
2015-01-16 01:17:12 +03:00
|
|
|
fp = self._repo.vfs("hgrc", "w", text=True)
|
2014-06-19 19:42:35 +04:00
|
|
|
try:
|
|
|
|
fp.write(''.join(lines))
|
|
|
|
finally:
|
|
|
|
fp.close()
|
2010-03-12 03:23:35 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2015-01-13 04:59:17 +03:00
|
|
|
def add(self, ui, match, prefix, explicitonly, **opts):
|
|
|
|
return cmdutil.add(ui, self._repo, match,
|
2015-04-09 18:36:42 +03:00
|
|
|
self.wvfs.reljoin(prefix, self._path),
|
|
|
|
explicitonly, **opts)
|
2010-09-13 15:09:20 +04:00
|
|
|
|
2015-02-07 04:39:20 +03:00
|
|
|
@annotatesubrepoerror
|
2014-11-25 06:27:49 +03:00
|
|
|
def addremove(self, m, prefix, opts, dry_run, similarity):
|
2014-12-01 06:47:53 +03:00
|
|
|
# In the same way as sub directories are processed, once in a subrepo,
|
|
|
|
# always entry any of its subrepos. Don't corrupt the options that will
|
|
|
|
# be used to process sibling subrepos however.
|
|
|
|
opts = copy.copy(opts)
|
|
|
|
opts['subrepos'] = True
|
2014-11-25 06:27:49 +03:00
|
|
|
return scmutil.addremove(self._repo, m,
|
2015-04-09 18:36:42 +03:00
|
|
|
self.wvfs.reljoin(prefix, self._path), opts,
|
2014-11-25 06:27:49 +03:00
|
|
|
dry_run, similarity)
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2014-12-13 22:26:38 +03:00
|
|
|
def cat(self, match, prefix, **opts):
|
2014-03-15 05:32:05 +04:00
|
|
|
rev = self._state[1]
|
|
|
|
ctx = self._repo[rev]
|
2014-12-13 22:26:38 +03:00
|
|
|
return cmdutil.cat(self.ui, self._repo, ctx, match, prefix, **opts)
|
2014-03-15 05:32:05 +04:00
|
|
|
|
|
|
|
@annotatesubrepoerror
|
2010-09-03 14:58:51 +04:00
|
|
|
def status(self, rev2, **opts):
|
|
|
|
try:
|
|
|
|
rev1 = self._state[1]
|
|
|
|
ctx1 = self._repo[rev1]
|
|
|
|
ctx2 = self._repo[rev2]
|
|
|
|
return self._repo.status(ctx1, ctx2, **opts)
|
|
|
|
except error.RepoLookupError, inst:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
|
|
|
|
% (inst, subrelpath(self)))
|
2014-10-14 09:52:27 +04:00
|
|
|
return scmutil.status([], [], [], [], [], [], [])
|
2010-09-03 14:58:51 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2012-11-29 19:43:55 +04:00
|
|
|
def diff(self, ui, diffopts, node2, match, prefix, **opts):
|
2010-09-03 14:58:51 +04:00
|
|
|
try:
|
|
|
|
node1 = node.bin(self._state[1])
|
2010-09-11 00:52:00 +04:00
|
|
|
# We currently expect node2 to come from substate and be
|
|
|
|
# in hex format
|
2010-09-11 01:53:49 +04:00
|
|
|
if node2 is not None:
|
|
|
|
node2 = node.bin(node2)
|
2012-11-29 19:43:55 +04:00
|
|
|
cmdutil.diffordiffstat(ui, self._repo, diffopts,
|
2010-09-03 14:58:51 +04:00
|
|
|
node1, node2, match,
|
2012-11-28 02:58:00 +04:00
|
|
|
prefix=posixpath.join(prefix, self._path),
|
2010-09-03 14:58:51 +04:00
|
|
|
listsubrepos=True, **opts)
|
|
|
|
except error.RepoLookupError, inst:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
|
|
|
|
% (inst, subrelpath(self)))
|
2010-09-03 14:58:51 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
def archive(self, archiver, prefix, match=None):
|
2011-10-17 18:45:19 +04:00
|
|
|
self._get(self._state + ('hg',))
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
total = abstractsubrepo.archive(self, archiver, prefix, match)
|
2010-09-20 17:46:17 +04:00
|
|
|
rev = self._state[1]
|
|
|
|
ctx = self._repo[rev]
|
|
|
|
for subpath in ctx.substate:
|
|
|
|
s = subrepo(ctx, subpath)
|
2012-06-17 06:34:06 +04:00
|
|
|
submatch = matchmod.narrowmatcher(subpath, match)
|
2013-03-22 01:09:15 +04:00
|
|
|
total += s.archive(
|
2015-04-09 18:36:42 +03:00
|
|
|
archiver, self.wvfs.reljoin(prefix, self._path), submatch)
|
2013-03-22 01:09:15 +04:00
|
|
|
return total
|
2010-09-20 17:46:17 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-12-08 07:14:43 +03:00
|
|
|
def dirty(self, ignoreupdate=False):
|
2009-06-15 11:45:38 +04:00
|
|
|
r = self._state[1]
|
2010-12-08 07:14:43 +03:00
|
|
|
if r == '' and not ignoreupdate: # no state recorded
|
2009-06-15 11:45:38 +04:00
|
|
|
return True
|
|
|
|
w = self._repo[None]
|
2011-05-13 20:04:51 +04:00
|
|
|
if r != w.p1().hex() and not ignoreupdate:
|
2011-01-04 19:42:00 +03:00
|
|
|
# different version checked out
|
2009-06-15 11:45:38 +04:00
|
|
|
return True
|
|
|
|
return w.dirty() # working directory changed
|
|
|
|
|
2012-02-07 01:00:08 +04:00
|
|
|
def basestate(self):
|
|
|
|
return self._repo['.'].hex()
|
|
|
|
|
2010-09-03 14:58:51 +04:00
|
|
|
def checknested(self, path):
|
|
|
|
return self._repo._checknested(self._repo.wjoin(path))
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2009-06-15 11:45:38 +04:00
|
|
|
def commit(self, text, user, date):
|
2011-07-19 22:43:53 +04:00
|
|
|
# don't bother committing in the subrepo if it's only been
|
|
|
|
# updated
|
|
|
|
if not self.dirty(True):
|
|
|
|
return self._repo['.'].hex()
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.debug("committing subrepo %s\n" % subrelpath(self))
|
2009-06-15 11:45:38 +04:00
|
|
|
n = self._repo.commit(text, user, date)
|
|
|
|
if not n:
|
|
|
|
return self._repo['.'].hex() # different version checked out
|
|
|
|
return node.hex(n)
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2013-11-13 10:55:30 +04:00
|
|
|
def phase(self, state):
|
|
|
|
return self._repo[state].phase()
|
|
|
|
|
|
|
|
@annotatesubrepoerror
|
2009-06-15 11:45:38 +04:00
|
|
|
def remove(self):
|
|
|
|
# we can't fully delete the repository as it may contain
|
|
|
|
# local-only history
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.note(_('removing subrepo %s\n') % subrelpath(self))
|
2009-06-15 11:45:38 +04:00
|
|
|
hg.clean(self._repo, node.nullid, False)
|
|
|
|
|
2009-10-01 03:47:33 +04:00
|
|
|
def _get(self, state):
|
2010-01-01 02:10:03 +03:00
|
|
|
source, revision, kind = state
|
2013-11-24 05:10:14 +04:00
|
|
|
if revision in self._repo.unfiltered():
|
2013-11-24 05:17:17 +04:00
|
|
|
return True
|
2013-11-24 05:13:00 +04:00
|
|
|
self._repo._subsource = source
|
|
|
|
srcurl = _abssource(self._repo)
|
|
|
|
other = hg.peer(self._repo, {}, srcurl)
|
|
|
|
if len(self._repo) == 0:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.status(_('cloning subrepo %s from %s\n')
|
|
|
|
% (subrelpath(self), srcurl))
|
2013-11-24 05:13:00 +04:00
|
|
|
parentrepo = self._repo._subparent
|
2015-04-10 18:47:09 +03:00
|
|
|
# use self._repo.vfs instead of self.wvfs to remove .hg only
|
|
|
|
self._repo.vfs.rmtree()
|
2013-11-24 05:13:00 +04:00
|
|
|
other, cloned = hg.clone(self._repo._subparent.baseui, {},
|
|
|
|
other, self._repo.root,
|
|
|
|
update=False)
|
|
|
|
self._repo = cloned.local()
|
|
|
|
self._initrepo(parentrepo, source, create=True)
|
|
|
|
self._cachestorehash(srcurl)
|
2013-11-24 05:10:14 +04:00
|
|
|
else:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.status(_('pulling subrepo %s from %s\n')
|
|
|
|
% (subrelpath(self), srcurl))
|
2013-11-24 05:13:00 +04:00
|
|
|
cleansub = self.storeclean(srcurl)
|
2014-10-03 20:12:55 +04:00
|
|
|
exchange.pull(self._repo, other)
|
2013-11-24 05:13:00 +04:00
|
|
|
if cleansub:
|
|
|
|
# keep the repo clean after pull
|
2013-02-16 04:18:53 +04:00
|
|
|
self._cachestorehash(srcurl)
|
2013-11-24 05:17:17 +04:00
|
|
|
return False
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-01-31 15:33:41 +03:00
|
|
|
def get(self, state, overwrite=False):
|
2013-11-24 05:17:17 +04:00
|
|
|
inrepo = self._get(state)
|
2010-01-01 02:10:03 +03:00
|
|
|
source, revision, kind = state
|
2013-11-24 05:17:17 +04:00
|
|
|
repo = self._repo
|
|
|
|
repo.ui.debug("getting subrepo %s\n" % self._path)
|
|
|
|
if inrepo:
|
|
|
|
urepo = repo.unfiltered()
|
|
|
|
ctx = urepo[revision]
|
|
|
|
if ctx.hidden():
|
|
|
|
urepo.ui.warn(
|
|
|
|
_('revision %s in subrepo %s is hidden\n') \
|
|
|
|
% (revision[0:12], self._path))
|
|
|
|
repo = urepo
|
|
|
|
hg.updaterepo(repo, revision, overwrite)
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2009-06-15 11:45:38 +04:00
|
|
|
def merge(self, state):
|
2009-10-01 03:47:33 +04:00
|
|
|
self._get(state)
|
2009-11-08 01:31:43 +03:00
|
|
|
cur = self._repo['.']
|
|
|
|
dst = self._repo[state[1]]
|
2010-01-15 23:08:04 +03:00
|
|
|
anc = dst.ancestor(cur)
|
2011-02-09 12:53:09 +03:00
|
|
|
|
|
|
|
def mergefunc():
|
2012-02-29 17:24:57 +04:00
|
|
|
if anc == cur and dst.branch() == cur.branch():
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.debug("updating subrepo %s\n" % subrelpath(self))
|
2011-02-09 12:53:09 +03:00
|
|
|
hg.update(self._repo, state[1])
|
|
|
|
elif anc == dst:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.debug("skipping subrepo %s\n" % subrelpath(self))
|
2011-02-09 12:53:09 +03:00
|
|
|
else:
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.debug("merging subrepo %s\n" % subrelpath(self))
|
2011-02-09 12:53:09 +03:00
|
|
|
hg.merge(self._repo, state[1], remind=False)
|
|
|
|
|
|
|
|
wctx = self._repo[None]
|
|
|
|
if self.dirty():
|
|
|
|
if anc != dst:
|
2014-12-14 06:44:22 +03:00
|
|
|
if _updateprompt(self.ui, self, wctx.dirty(), cur, dst):
|
2011-02-09 12:53:09 +03:00
|
|
|
mergefunc()
|
|
|
|
else:
|
|
|
|
mergefunc()
|
2009-11-08 01:31:43 +03:00
|
|
|
else:
|
2011-02-09 12:53:09 +03:00
|
|
|
mergefunc()
|
2009-06-15 11:46:20 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-09-29 19:20:04 +04:00
|
|
|
def push(self, opts):
|
|
|
|
force = opts.get('force')
|
|
|
|
newbranch = opts.get('new_branch')
|
|
|
|
ssh = opts.get('ssh')
|
|
|
|
|
2009-06-15 11:46:20 +04:00
|
|
|
# push subrepos depth-first for coherent ordering
|
|
|
|
c = self._repo['']
|
|
|
|
subs = c.substate # only repos that are committed
|
|
|
|
for s in sorted(subs):
|
2012-01-30 21:26:20 +04:00
|
|
|
if c.sub(s).push(opts) == 0:
|
2010-05-01 03:32:18 +04:00
|
|
|
return False
|
2009-06-15 11:46:20 +04:00
|
|
|
|
|
|
|
dsturl = _abssource(self._repo, True)
|
2013-02-16 04:21:40 +04:00
|
|
|
if not force:
|
|
|
|
if self.storeclean(dsturl):
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.status(
|
2013-02-16 04:21:40 +04:00
|
|
|
_('no changes made to subrepo %s since last push to %s\n')
|
|
|
|
% (subrelpath(self), dsturl))
|
|
|
|
return None
|
2014-12-14 06:44:22 +03:00
|
|
|
self.ui.status(_('pushing subrepo %s to %s\n') %
|
2010-10-19 05:55:28 +04:00
|
|
|
(subrelpath(self), dsturl))
|
2012-07-29 01:28:36 +04:00
|
|
|
other = hg.peer(self._repo, {'ssh': ssh}, dsturl)
|
2014-09-25 12:42:49 +04:00
|
|
|
res = exchange.push(self._repo, other, force, newbranch=newbranch)
|
2013-02-16 04:18:53 +04:00
|
|
|
|
|
|
|
# the repo is now clean
|
|
|
|
self._cachestorehash(dsturl)
|
2014-09-25 12:42:49 +04:00
|
|
|
return res.cgresult
|
2010-01-01 02:10:03 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-09-13 15:09:26 +04:00
|
|
|
def outgoing(self, ui, dest, opts):
|
|
|
|
return hg.outgoing(ui, self._repo, _abssource(self._repo, True), opts)
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-09-13 15:09:31 +04:00
|
|
|
def incoming(self, ui, source, opts):
|
|
|
|
return hg.incoming(ui, self._repo, _abssource(self._repo, False), opts)
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-09-20 17:44:30 +04:00
|
|
|
def files(self):
|
|
|
|
rev = self._state[1]
|
|
|
|
ctx = self._repo[rev]
|
2015-02-16 01:29:10 +03:00
|
|
|
return ctx.manifest().keys()
|
2010-09-20 17:44:30 +04:00
|
|
|
|
|
|
|
def filedata(self, name):
|
|
|
|
rev = self._state[1]
|
|
|
|
return self._repo[rev][name].data()
|
|
|
|
|
|
|
|
def fileflags(self, name):
|
|
|
|
rev = self._state[1]
|
|
|
|
ctx = self._repo[rev]
|
|
|
|
return ctx.flags(name)
|
|
|
|
|
2015-03-19 06:03:41 +03:00
|
|
|
@annotatesubrepoerror
|
|
|
|
def printfiles(self, ui, m, fm, fmt):
|
|
|
|
# If the parent context is a workingctx, use the workingctx here for
|
|
|
|
# consistency.
|
|
|
|
if self._ctx.rev() is None:
|
|
|
|
ctx = self._repo[None]
|
|
|
|
else:
|
|
|
|
rev = self._state[1]
|
|
|
|
ctx = self._repo[rev]
|
|
|
|
return cmdutil.files(ui, ctx, m, fm, fmt, True)
|
|
|
|
|
2011-11-02 09:17:11 +04:00
|
|
|
def walk(self, match):
|
|
|
|
ctx = self._repo[None]
|
|
|
|
return ctx.walk(match)
|
2010-09-20 17:44:30 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2014-12-14 03:23:30 +03:00
|
|
|
def forget(self, match, prefix):
|
|
|
|
return cmdutil.forget(self.ui, self._repo, match,
|
2015-04-09 18:36:42 +03:00
|
|
|
self.wvfs.reljoin(prefix, self._path), True)
|
2011-11-10 04:46:51 +04:00
|
|
|
|
2014-11-16 05:36:19 +03:00
|
|
|
@annotatesubrepoerror
|
2014-12-14 03:36:50 +03:00
|
|
|
def removefiles(self, matcher, prefix, after, force, subrepos):
|
|
|
|
return cmdutil.remove(self.ui, self._repo, matcher,
|
2015-04-09 18:36:42 +03:00
|
|
|
self.wvfs.reljoin(prefix, self._path),
|
|
|
|
after, force, subrepos)
|
2014-11-16 05:36:19 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2014-12-14 03:44:55 +03:00
|
|
|
def revert(self, substate, *pats, **opts):
|
2012-03-28 13:42:17 +04:00
|
|
|
# reverting a subrepo is a 2 step process:
|
|
|
|
# 1. if the no_backup is not set, revert all modified
|
|
|
|
# files inside the subrepo
|
|
|
|
# 2. update the subrepo to the revision specified in
|
|
|
|
# the corresponding substate dictionary
|
2014-12-14 03:44:55 +03:00
|
|
|
self.ui.status(_('reverting subrepo %s\n') % substate[0])
|
2012-03-28 13:42:17 +04:00
|
|
|
if not opts.get('no_backup'):
|
|
|
|
# Revert all files on the subrepo, creating backups
|
|
|
|
# Note that this will not recursively revert subrepos
|
|
|
|
# We could do it if there was a set:subrepos() predicate
|
|
|
|
opts = opts.copy()
|
|
|
|
opts['date'] = None
|
|
|
|
opts['rev'] = substate[1]
|
|
|
|
|
2014-12-14 03:44:55 +03:00
|
|
|
self.filerevert(*pats, **opts)
|
2012-03-28 13:42:17 +04:00
|
|
|
|
|
|
|
# Update the repo to the revision specified in the given substate
|
2015-02-08 05:47:28 +03:00
|
|
|
if not opts.get('dry_run'):
|
|
|
|
self.get(substate, overwrite=True)
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-12-14 03:44:55 +03:00
|
|
|
def filerevert(self, *pats, **opts):
|
2012-03-28 13:42:17 +04:00
|
|
|
ctx = self._repo[opts['rev']]
|
|
|
|
parents = self._repo.dirstate.parents()
|
2013-04-15 18:52:57 +04:00
|
|
|
if opts.get('all'):
|
2012-03-28 13:42:17 +04:00
|
|
|
pats = ['set:modified()']
|
|
|
|
else:
|
|
|
|
pats = []
|
2014-12-14 03:44:55 +03:00
|
|
|
cmdutil.revert(self.ui, self._repo, ctx, parents, *pats, **opts)
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-05-07 02:08:20 +04:00
|
|
|
def shortid(self, revid):
|
|
|
|
return revid[:12]
|
|
|
|
|
2015-04-09 18:36:42 +03:00
|
|
|
@propertycache
|
|
|
|
def wvfs(self):
|
|
|
|
"""return own wvfs for efficiency and consitency
|
|
|
|
"""
|
|
|
|
return self._repo.wvfs
|
|
|
|
|
2010-07-14 22:25:31 +04:00
|
|
|
class svnsubrepo(abstractsubrepo):
|
2009-12-31 22:16:03 +03:00
|
|
|
def __init__(self, ctx, path, state):
|
2015-04-09 18:36:42 +03:00
|
|
|
super(svnsubrepo, self).__init__(ctx, path)
|
2009-12-31 22:16:03 +03:00
|
|
|
self._state = state
|
2011-10-02 22:02:15 +04:00
|
|
|
self._exe = util.findexe('svn')
|
|
|
|
if not self._exe:
|
|
|
|
raise util.Abort(_("'svn' executable not found for subrepo '%s'")
|
|
|
|
% self._path)
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2011-06-18 00:22:50 +04:00
|
|
|
def _svncommand(self, commands, filename='', failok=False):
|
2011-10-02 22:02:15 +04:00
|
|
|
cmd = [self._exe]
|
2011-06-01 04:49:17 +04:00
|
|
|
extrakw = {}
|
2014-12-13 23:19:38 +03:00
|
|
|
if not self.ui.interactive():
|
2011-06-01 04:49:17 +04:00
|
|
|
# Making stdin be a pipe should prevent svn from behaving
|
|
|
|
# interactively even if we can't pass --non-interactive.
|
|
|
|
extrakw['stdin'] = subprocess.PIPE
|
|
|
|
# Starting in svn 1.5 --non-interactive is a global flag
|
|
|
|
# instead of being per-command, but we need to support 1.4 so
|
|
|
|
# we have to be intelligent about what commands take
|
|
|
|
# --non-interactive.
|
|
|
|
if commands[0] in ('update', 'checkout', 'commit'):
|
|
|
|
cmd.append('--non-interactive')
|
2011-04-29 12:05:48 +04:00
|
|
|
cmd.extend(commands)
|
2011-03-04 16:00:49 +03:00
|
|
|
if filename is not None:
|
2015-04-09 18:36:42 +03:00
|
|
|
path = self.wvfs.reljoin(self._ctx.repo().origroot,
|
|
|
|
self._path, filename)
|
2011-03-04 16:00:49 +03:00
|
|
|
cmd.append(path)
|
2010-01-02 18:42:00 +03:00
|
|
|
env = dict(os.environ)
|
2010-01-21 17:13:03 +03:00
|
|
|
# Avoid localized output, preserve current locale for everything else.
|
2012-10-04 18:30:40 +04:00
|
|
|
lc_all = env.get('LC_ALL')
|
|
|
|
if lc_all:
|
|
|
|
env['LANG'] = lc_all
|
|
|
|
del env['LC_ALL']
|
2010-01-21 17:13:03 +03:00
|
|
|
env['LC_MESSAGES'] = 'C'
|
2010-12-10 00:52:14 +03:00
|
|
|
p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds,
|
2010-11-17 23:24:36 +03:00
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
2011-06-01 04:49:17 +04:00
|
|
|
universal_newlines=True, env=env, **extrakw)
|
2010-11-17 23:24:36 +03:00
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
stderr = stderr.strip()
|
2011-06-18 00:22:50 +04:00
|
|
|
if not failok:
|
|
|
|
if p.returncode:
|
|
|
|
raise util.Abort(stderr or 'exited with code %d' % p.returncode)
|
|
|
|
if stderr:
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(stderr + '\n')
|
2011-06-18 00:22:50 +04:00
|
|
|
return stdout, stderr
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2011-03-04 16:00:49 +03:00
|
|
|
@propertycache
|
|
|
|
def _svnversion(self):
|
2012-10-04 18:52:20 +04:00
|
|
|
output, err = self._svncommand(['--version', '--quiet'], filename=None)
|
|
|
|
m = re.search(r'^(\d+)\.(\d+)', output)
|
2011-03-04 16:00:49 +03:00
|
|
|
if not m:
|
|
|
|
raise util.Abort(_('cannot retrieve svn tool version'))
|
|
|
|
return (int(m.group(1)), int(m.group(2)))
|
|
|
|
|
2011-01-22 18:15:40 +03:00
|
|
|
def _wcrevs(self):
|
|
|
|
# Get the working directory revision as well as the last
|
|
|
|
# commit revision so we can compare the subrepo state with
|
|
|
|
# both. We used to store the working directory one.
|
2011-06-18 00:22:50 +04:00
|
|
|
output, err = self._svncommand(['info', '--xml'])
|
2010-01-21 17:13:40 +03:00
|
|
|
doc = xml.dom.minidom.parseString(output)
|
|
|
|
entries = doc.getElementsByTagName('entry')
|
2011-01-22 18:15:40 +03:00
|
|
|
lastrev, rev = '0', '0'
|
|
|
|
if entries:
|
|
|
|
rev = str(entries[0].getAttribute('revision')) or '0'
|
|
|
|
commits = entries[0].getElementsByTagName('commit')
|
|
|
|
if commits:
|
|
|
|
lastrev = str(commits[0].getAttribute('revision')) or '0'
|
|
|
|
return (lastrev, rev)
|
|
|
|
|
|
|
|
def _wcrev(self):
|
|
|
|
return self._wcrevs()[0]
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2010-01-21 15:26:26 +03:00
|
|
|
def _wcchanged(self):
|
2012-04-26 14:13:20 +04:00
|
|
|
"""Return (changes, extchanges, missing) where changes is True
|
|
|
|
if the working directory was changed, extchanges is
|
|
|
|
True if any of these changes concern an external entry and missing
|
|
|
|
is True if any change is a missing entry.
|
2010-01-21 15:26:26 +03:00
|
|
|
"""
|
2011-06-18 00:22:50 +04:00
|
|
|
output, err = self._svncommand(['status', '--xml'])
|
2012-04-26 14:13:20 +04:00
|
|
|
externals, changes, missing = [], [], []
|
2010-01-21 17:13:40 +03:00
|
|
|
doc = xml.dom.minidom.parseString(output)
|
2010-01-21 15:26:26 +03:00
|
|
|
for e in doc.getElementsByTagName('entry'):
|
|
|
|
s = e.getElementsByTagName('wc-status')
|
|
|
|
if not s:
|
|
|
|
continue
|
|
|
|
item = s[0].getAttribute('item')
|
|
|
|
props = s[0].getAttribute('props')
|
|
|
|
path = e.getAttribute('path')
|
|
|
|
if item == 'external':
|
|
|
|
externals.append(path)
|
2012-04-26 14:13:20 +04:00
|
|
|
elif item == 'missing':
|
|
|
|
missing.append(path)
|
2010-01-21 15:26:26 +03:00
|
|
|
if (item not in ('', 'normal', 'unversioned', 'external')
|
2011-07-28 21:28:32 +04:00
|
|
|
or props not in ('', 'none', 'normal')):
|
2010-01-21 15:26:26 +03:00
|
|
|
changes.append(path)
|
|
|
|
for path in changes:
|
|
|
|
for ext in externals:
|
|
|
|
if path == ext or path.startswith(ext + os.sep):
|
2012-04-26 14:13:20 +04:00
|
|
|
return True, True, bool(missing)
|
|
|
|
return bool(changes), False, bool(missing)
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2010-12-08 07:14:43 +03:00
|
|
|
def dirty(self, ignoreupdate=False):
|
|
|
|
if not self._wcchanged()[0]:
|
2011-01-22 18:29:10 +03:00
|
|
|
if self._state[1] in self._wcrevs() or ignoreupdate:
|
2010-12-08 07:14:43 +03:00
|
|
|
return False
|
2009-12-31 22:16:03 +03:00
|
|
|
return True
|
|
|
|
|
2012-02-07 01:00:08 +04:00
|
|
|
def basestate(self):
|
2012-04-30 19:03:15 +04:00
|
|
|
lastrev, rev = self._wcrevs()
|
|
|
|
if lastrev != rev:
|
|
|
|
# Last committed rev is not the same than rev. We would
|
|
|
|
# like to take lastrev but we do not know if the subrepo
|
|
|
|
# URL exists at lastrev. Test it and fallback to rev it
|
|
|
|
# is not there.
|
|
|
|
try:
|
2012-06-26 16:27:33 +04:00
|
|
|
self._svncommand(['list', '%s@%s' % (self._state[0], lastrev)])
|
2012-04-30 19:03:15 +04:00
|
|
|
return lastrev
|
|
|
|
except error.Abort:
|
|
|
|
pass
|
|
|
|
return rev
|
2012-02-07 01:00:08 +04:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2009-12-31 22:16:03 +03:00
|
|
|
def commit(self, text, user, date):
|
|
|
|
# user and date are out of our hands since svn is centralized
|
2012-04-26 14:13:20 +04:00
|
|
|
changed, extchanged, missing = self._wcchanged()
|
2010-01-21 15:26:26 +03:00
|
|
|
if not changed:
|
2012-04-30 19:03:15 +04:00
|
|
|
return self.basestate()
|
2010-01-21 15:26:26 +03:00
|
|
|
if extchanged:
|
|
|
|
# Do not try to commit externals
|
|
|
|
raise util.Abort(_('cannot commit svn externals'))
|
2012-04-26 14:13:20 +04:00
|
|
|
if missing:
|
|
|
|
# svn can commit with missing entries but aborting like hg
|
|
|
|
# seems a better approach.
|
|
|
|
raise util.Abort(_('cannot commit missing svn entries'))
|
2011-06-18 00:22:50 +04:00
|
|
|
commitinfo, err = self._svncommand(['commit', '-m', text])
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(commitinfo)
|
2010-08-27 15:03:57 +04:00
|
|
|
newrev = re.search('Committed revision ([0-9]+).', commitinfo)
|
2009-12-31 22:16:03 +03:00
|
|
|
if not newrev:
|
2012-04-26 13:55:07 +04:00
|
|
|
if not commitinfo.strip():
|
|
|
|
# Sometimes, our definition of "changed" differs from
|
|
|
|
# svn one. For instance, svn ignores missing files
|
|
|
|
# when committing. If there are only missing files, no
|
|
|
|
# commit is made, no output and no error code.
|
|
|
|
raise util.Abort(_('failed to commit svn changes'))
|
2009-12-31 22:16:03 +03:00
|
|
|
raise util.Abort(commitinfo.splitlines()[-1])
|
|
|
|
newrev = newrev.groups()[0]
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(self._svncommand(['update', '-r', newrev])[0])
|
2009-12-31 22:16:03 +03:00
|
|
|
return newrev
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2009-12-31 22:16:03 +03:00
|
|
|
def remove(self):
|
|
|
|
if self.dirty():
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('not removing repo %s because '
|
|
|
|
'it has changes.\n') % self._path)
|
2009-12-31 22:16:03 +03:00
|
|
|
return
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.note(_('removing subrepo %s\n') % self._path)
|
2010-11-17 23:00:47 +03:00
|
|
|
|
2015-04-10 18:47:09 +03:00
|
|
|
self.wvfs.rmtree(forcibly=True)
|
2010-11-17 23:25:23 +03:00
|
|
|
try:
|
2015-04-10 18:47:09 +03:00
|
|
|
self._ctx.repo().wvfs.removedirs(os.path.dirname(self._path))
|
2010-11-17 23:25:23 +03:00
|
|
|
except OSError:
|
|
|
|
pass
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-01-31 15:33:41 +03:00
|
|
|
def get(self, state, overwrite=False):
|
|
|
|
if overwrite:
|
2011-02-01 23:39:28 +03:00
|
|
|
self._svncommand(['revert', '--recursive'])
|
2011-03-04 16:00:49 +03:00
|
|
|
args = ['checkout']
|
|
|
|
if self._svnversion >= (1, 5):
|
|
|
|
args.append('--force')
|
2011-06-30 22:22:12 +04:00
|
|
|
# The revision must be specified at the end of the URL to properly
|
|
|
|
# update to a directory which has since been deleted and recreated.
|
|
|
|
args.append('%s@%s' % (state[0], state[1]))
|
2011-06-18 00:22:50 +04:00
|
|
|
status, err = self._svncommand(args, failok=True)
|
2015-04-11 17:00:04 +03:00
|
|
|
_sanitize(self.ui, self.wvfs, '.svn')
|
2010-08-27 15:03:57 +04:00
|
|
|
if not re.search('Checked out revision [0-9]+.', status):
|
2011-06-18 00:22:50 +04:00
|
|
|
if ('is already a working copy for a different URL' in err
|
2012-04-26 14:13:20 +04:00
|
|
|
and (self._wcchanged()[:2] == (False, False))):
|
2011-06-18 00:22:50 +04:00
|
|
|
# obstructed but clean working copy, so just blow it away.
|
|
|
|
self.remove()
|
|
|
|
self.get(state, overwrite=False)
|
|
|
|
return
|
|
|
|
raise util.Abort((status or err).splitlines()[-1])
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(status)
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2009-12-31 22:16:03 +03:00
|
|
|
def merge(self, state):
|
2011-02-09 12:53:09 +03:00
|
|
|
old = self._state[1]
|
|
|
|
new = state[1]
|
2012-04-30 19:05:19 +04:00
|
|
|
wcrev = self._wcrev()
|
|
|
|
if new != wcrev:
|
|
|
|
dirty = old == wcrev or self._wcchanged()[0]
|
2014-12-13 23:19:38 +03:00
|
|
|
if _updateprompt(self.ui, self, dirty, wcrev, new):
|
2011-02-09 12:53:09 +03:00
|
|
|
self.get(state, False)
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2011-09-29 19:20:04 +04:00
|
|
|
def push(self, opts):
|
2010-06-28 03:20:49 +04:00
|
|
|
# push is a no-op for SVN
|
|
|
|
return True
|
2009-12-31 22:16:03 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-09-20 17:44:30 +04:00
|
|
|
def files(self):
|
2012-04-16 13:48:15 +04:00
|
|
|
output = self._svncommand(['list', '--recursive', '--xml'])[0]
|
|
|
|
doc = xml.dom.minidom.parseString(output)
|
|
|
|
paths = []
|
|
|
|
for e in doc.getElementsByTagName('entry'):
|
|
|
|
kind = str(e.getAttribute('kind'))
|
|
|
|
if kind != 'file':
|
|
|
|
continue
|
|
|
|
name = ''.join(c.data for c
|
|
|
|
in e.getElementsByTagName('name')[0].childNodes
|
|
|
|
if c.nodeType == c.TEXT_NODE)
|
2012-09-05 02:46:04 +04:00
|
|
|
paths.append(name.encode('utf-8'))
|
2012-04-16 13:48:15 +04:00
|
|
|
return paths
|
2010-09-20 17:44:30 +04:00
|
|
|
|
|
|
|
def filedata(self, name):
|
2012-04-16 13:48:15 +04:00
|
|
|
return self._svncommand(['cat'], name)[0]
|
2010-09-20 17:44:30 +04:00
|
|
|
|
|
|
|
|
2010-12-10 00:52:14 +03:00
|
|
|
class gitsubrepo(abstractsubrepo):
|
2010-11-15 02:15:26 +03:00
|
|
|
def __init__(self, ctx, path, state):
|
2015-04-09 18:36:42 +03:00
|
|
|
super(gitsubrepo, self).__init__(ctx, path)
|
2010-11-15 02:15:26 +03:00
|
|
|
self._state = state
|
2015-03-13 05:59:52 +03:00
|
|
|
self._abspath = ctx.repo().wjoin(path)
|
|
|
|
self._subparent = ctx.repo()
|
2012-06-12 17:28:55 +04:00
|
|
|
self._ensuregit()
|
|
|
|
|
|
|
|
def _ensuregit(self):
|
2012-06-12 17:31:04 +04:00
|
|
|
try:
|
|
|
|
self._gitexecutable = 'git'
|
|
|
|
out, err = self._gitnodir(['--version'])
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno != 2 or os.name != 'nt':
|
|
|
|
raise
|
|
|
|
self._gitexecutable = 'git.cmd'
|
|
|
|
out, err = self._gitnodir(['--version'])
|
2014-03-22 03:09:17 +04:00
|
|
|
versionstatus = self._checkversion(out)
|
|
|
|
if versionstatus == 'unknown':
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('cannot retrieve git version\n'))
|
2014-03-22 03:09:17 +04:00
|
|
|
elif versionstatus == 'abort':
|
|
|
|
raise util.Abort(_('git subrepo requires at least 1.6.0 or later'))
|
|
|
|
elif versionstatus == 'warning':
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('git subrepo requires at least 1.6.0 or later\n'))
|
2014-03-22 03:09:17 +04:00
|
|
|
|
2014-12-10 10:33:03 +03:00
|
|
|
@staticmethod
|
|
|
|
def _gitversion(out):
|
2014-12-10 10:41:21 +03:00
|
|
|
m = re.search(r'^git version (\d+)\.(\d+)\.(\d+)', out)
|
|
|
|
if m:
|
|
|
|
return (int(m.group(1)), int(m.group(2)), int(m.group(3)))
|
|
|
|
|
2014-12-10 10:33:03 +03:00
|
|
|
m = re.search(r'^git version (\d+)\.(\d+)', out)
|
|
|
|
if m:
|
2014-12-10 10:41:21 +03:00
|
|
|
return (int(m.group(1)), int(m.group(2)), 0)
|
2014-12-10 10:33:03 +03:00
|
|
|
|
|
|
|
return -1
|
|
|
|
|
2014-03-22 03:09:17 +04:00
|
|
|
@staticmethod
|
|
|
|
def _checkversion(out):
|
|
|
|
'''ensure git version is new enough
|
|
|
|
|
|
|
|
>>> _checkversion = gitsubrepo._checkversion
|
|
|
|
>>> _checkversion('git version 1.6.0')
|
|
|
|
'ok'
|
|
|
|
>>> _checkversion('git version 1.8.5')
|
|
|
|
'ok'
|
|
|
|
>>> _checkversion('git version 1.4.0')
|
|
|
|
'abort'
|
|
|
|
>>> _checkversion('git version 1.5.0')
|
|
|
|
'warning'
|
|
|
|
>>> _checkversion('git version 1.9-rc0')
|
|
|
|
'ok'
|
|
|
|
>>> _checkversion('git version 1.9.0.265.g81cdec2')
|
|
|
|
'ok'
|
|
|
|
>>> _checkversion('git version 1.9.0.GIT')
|
|
|
|
'ok'
|
|
|
|
>>> _checkversion('git version 12345')
|
|
|
|
'unknown'
|
|
|
|
>>> _checkversion('no')
|
|
|
|
'unknown'
|
|
|
|
'''
|
2014-12-10 10:33:03 +03:00
|
|
|
version = gitsubrepo._gitversion(out)
|
2012-06-12 17:28:55 +04:00
|
|
|
# git 1.4.0 can't work at all, but 1.5.X can in at least some cases,
|
|
|
|
# despite the docstring comment. For now, error on 1.4.0, warn on
|
|
|
|
# 1.5.0 but attempt to continue.
|
2014-12-10 10:33:03 +03:00
|
|
|
if version == -1:
|
|
|
|
return 'unknown'
|
2014-12-10 10:41:21 +03:00
|
|
|
if version < (1, 5, 0):
|
2014-03-22 03:09:17 +04:00
|
|
|
return 'abort'
|
2014-12-10 10:41:21 +03:00
|
|
|
elif version < (1, 6, 0):
|
2014-03-22 03:09:17 +04:00
|
|
|
return 'warning'
|
|
|
|
return 'ok'
|
2010-11-15 02:15:26 +03:00
|
|
|
|
2010-12-07 05:17:27 +03:00
|
|
|
def _gitcommand(self, commands, env=None, stream=False):
|
|
|
|
return self._gitdir(commands, env=env, stream=stream)[0]
|
2010-11-15 02:15:26 +03:00
|
|
|
|
2010-12-07 05:17:27 +03:00
|
|
|
def _gitdir(self, commands, env=None, stream=False):
|
2010-12-20 21:59:33 +03:00
|
|
|
return self._gitnodir(commands, env=env, stream=stream,
|
|
|
|
cwd=self._abspath)
|
2010-11-15 02:15:26 +03:00
|
|
|
|
2010-12-07 05:17:27 +03:00
|
|
|
def _gitnodir(self, commands, env=None, stream=False, cwd=None):
|
2010-11-15 02:15:26 +03:00
|
|
|
"""Calls the git command
|
|
|
|
|
2012-08-16 00:38:42 +04:00
|
|
|
The methods tries to call the git command. versions prior to 1.6.0
|
2010-11-15 02:15:26 +03:00
|
|
|
are not supported and very probably fail.
|
|
|
|
"""
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.debug('%s: git %s\n' % (self._relpath, ' '.join(commands)))
|
2010-12-10 00:52:14 +03:00
|
|
|
# unless ui.quiet is set, print git's stderr,
|
|
|
|
# which is mostly progress and useful info
|
|
|
|
errpipe = None
|
2014-12-13 23:19:38 +03:00
|
|
|
if self.ui.quiet:
|
2010-12-10 00:52:14 +03:00
|
|
|
errpipe = open(os.devnull, 'w')
|
2012-06-12 17:31:04 +04:00
|
|
|
p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1,
|
|
|
|
cwd=cwd, env=env, close_fds=util.closefds,
|
2010-12-10 00:52:14 +03:00
|
|
|
stdout=subprocess.PIPE, stderr=errpipe)
|
2010-11-19 03:20:21 +03:00
|
|
|
if stream:
|
|
|
|
return p.stdout, None
|
|
|
|
|
2010-11-28 23:03:48 +03:00
|
|
|
retdata = p.stdout.read().strip()
|
2010-11-15 02:15:26 +03:00
|
|
|
# wait for the child to exit to avoid race condition.
|
|
|
|
p.wait()
|
|
|
|
|
2010-12-10 00:52:14 +03:00
|
|
|
if p.returncode != 0 and p.returncode != 1:
|
2010-11-15 02:15:26 +03:00
|
|
|
# there are certain error codes that are ok
|
2010-12-10 00:52:14 +03:00
|
|
|
command = commands[0]
|
2010-12-15 05:53:40 +03:00
|
|
|
if command in ('cat-file', 'symbolic-ref'):
|
2010-11-15 02:15:26 +03:00
|
|
|
return retdata, p.returncode
|
|
|
|
# for all others, abort
|
2010-12-10 00:52:14 +03:00
|
|
|
raise util.Abort('git %s error %d in %s' %
|
|
|
|
(command, p.returncode, self._relpath))
|
2010-11-15 02:15:26 +03:00
|
|
|
|
|
|
|
return retdata, p.returncode
|
|
|
|
|
2011-03-07 20:03:54 +03:00
|
|
|
def _gitmissing(self):
|
2015-02-07 20:57:40 +03:00
|
|
|
return not self.wvfs.exists('.git')
|
2011-03-07 20:03:54 +03:00
|
|
|
|
2010-11-15 02:15:26 +03:00
|
|
|
def _gitstate(self):
|
2010-11-28 23:03:48 +03:00
|
|
|
return self._gitcommand(['rev-parse', 'HEAD'])
|
2010-11-15 02:15:26 +03:00
|
|
|
|
2010-12-15 05:56:43 +03:00
|
|
|
def _gitcurrentbranch(self):
|
|
|
|
current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet'])
|
|
|
|
if err:
|
|
|
|
current = None
|
|
|
|
return current
|
|
|
|
|
2011-03-08 23:36:56 +03:00
|
|
|
def _gitremote(self, remote):
|
|
|
|
out = self._gitcommand(['remote', 'show', '-n', remote])
|
|
|
|
line = out.split('\n')[1]
|
|
|
|
i = line.index('URL: ') + len('URL: ')
|
|
|
|
return line[i:]
|
|
|
|
|
2010-11-15 02:15:26 +03:00
|
|
|
def _githavelocally(self, revision):
|
|
|
|
out, code = self._gitdir(['cat-file', '-e', revision])
|
|
|
|
return code == 0
|
|
|
|
|
2010-11-22 06:00:51 +03:00
|
|
|
def _gitisancestor(self, r1, r2):
|
2010-11-28 23:03:48 +03:00
|
|
|
base = self._gitcommand(['merge-base', r1, r2])
|
2010-11-22 06:00:51 +03:00
|
|
|
return base == r1
|
|
|
|
|
2011-05-25 19:38:58 +04:00
|
|
|
def _gitisbare(self):
|
|
|
|
return self._gitcommand(['config', '--bool', 'core.bare']) == 'true'
|
|
|
|
|
2011-11-11 04:00:11 +04:00
|
|
|
def _gitupdatestat(self):
|
|
|
|
"""This must be run before git diff-index.
|
|
|
|
diff-index only looks at changes to file stat;
|
|
|
|
this command looks at file contents and updates the stat."""
|
|
|
|
self._gitcommand(['update-index', '-q', '--refresh'])
|
|
|
|
|
2010-11-15 02:31:29 +03:00
|
|
|
def _gitbranchmap(self):
|
2010-12-20 21:59:19 +03:00
|
|
|
'''returns 2 things:
|
2010-11-28 23:21:23 +03:00
|
|
|
a map from git branch to revision
|
2010-12-20 21:59:19 +03:00
|
|
|
a map from revision to branches'''
|
2010-11-28 23:21:23 +03:00
|
|
|
branch2rev = {}
|
|
|
|
rev2branch = {}
|
2010-12-20 21:59:19 +03:00
|
|
|
|
2010-12-15 05:53:40 +03:00
|
|
|
out = self._gitcommand(['for-each-ref', '--format',
|
2010-12-20 21:59:19 +03:00
|
|
|
'%(objectname) %(refname)'])
|
2010-11-15 02:31:29 +03:00
|
|
|
for line in out.split('\n'):
|
2010-12-20 21:59:19 +03:00
|
|
|
revision, ref = line.split(' ')
|
2011-02-23 18:17:44 +03:00
|
|
|
if (not ref.startswith('refs/heads/') and
|
|
|
|
not ref.startswith('refs/remotes/')):
|
2010-11-15 02:31:29 +03:00
|
|
|
continue
|
2010-12-15 05:53:40 +03:00
|
|
|
if ref.startswith('refs/remotes/') and ref.endswith('/HEAD'):
|
2010-11-15 02:31:29 +03:00
|
|
|
continue # ignore remote/HEAD redirects
|
2010-12-15 05:53:40 +03:00
|
|
|
branch2rev[ref] = revision
|
|
|
|
rev2branch.setdefault(revision, []).append(ref)
|
2010-12-20 21:59:19 +03:00
|
|
|
return branch2rev, rev2branch
|
|
|
|
|
|
|
|
def _gittracking(self, branches):
|
|
|
|
'return map of remote branch to local tracking branch'
|
|
|
|
# assumes no more than one local tracking branch for each remote
|
|
|
|
tracking = {}
|
|
|
|
for b in branches:
|
|
|
|
if b.startswith('refs/remotes/'):
|
|
|
|
continue
|
2011-10-12 08:34:55 +04:00
|
|
|
bname = b.split('/', 2)[2]
|
|
|
|
remote = self._gitcommand(['config', 'branch.%s.remote' % bname])
|
2010-12-20 21:59:19 +03:00
|
|
|
if remote:
|
2011-10-12 08:34:55 +04:00
|
|
|
ref = self._gitcommand(['config', 'branch.%s.merge' % bname])
|
2010-12-20 21:59:19 +03:00
|
|
|
tracking['refs/remotes/%s/%s' %
|
|
|
|
(remote, ref.split('/', 2)[2])] = b
|
|
|
|
return tracking
|
2010-11-29 01:19:23 +03:00
|
|
|
|
2011-02-22 23:11:10 +03:00
|
|
|
def _abssource(self, source):
|
2011-03-17 23:29:09 +03:00
|
|
|
if '://' not in source:
|
|
|
|
# recognize the scp syntax as an absolute source
|
|
|
|
colon = source.find(':')
|
|
|
|
if colon != -1 and '/' not in source[:colon]:
|
|
|
|
return source
|
2011-02-22 23:11:10 +03:00
|
|
|
self._subsource = source
|
|
|
|
return _abssource(self)
|
|
|
|
|
2010-11-15 02:20:13 +03:00
|
|
|
def _fetch(self, source, revision):
|
2011-03-07 20:03:54 +03:00
|
|
|
if self._gitmissing():
|
2011-03-02 20:19:18 +03:00
|
|
|
source = self._abssource(source)
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(_('cloning subrepo %s from %s\n') %
|
2011-03-02 20:19:18 +03:00
|
|
|
(self._relpath, source))
|
|
|
|
self._gitnodir(['clone', source, self._abspath])
|
2010-11-15 02:20:13 +03:00
|
|
|
if self._githavelocally(revision):
|
|
|
|
return
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(_('pulling subrepo %s from %s\n') %
|
2011-03-08 23:36:56 +03:00
|
|
|
(self._relpath, self._gitremote('origin')))
|
2011-02-23 18:59:36 +03:00
|
|
|
# try only origin: the originally cloned repo
|
2010-12-07 05:17:27 +03:00
|
|
|
self._gitcommand(['fetch'])
|
2010-11-15 02:20:13 +03:00
|
|
|
if not self._githavelocally(revision):
|
|
|
|
raise util.Abort(_("revision %s does not exist in subrepo %s\n") %
|
2010-12-20 21:59:33 +03:00
|
|
|
(revision, self._relpath))
|
2010-11-15 02:20:13 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-12-20 21:59:33 +03:00
|
|
|
def dirty(self, ignoreupdate=False):
|
2011-03-07 20:03:54 +03:00
|
|
|
if self._gitmissing():
|
2011-05-28 19:03:48 +04:00
|
|
|
return self._state[1] != ''
|
2011-05-25 19:38:58 +04:00
|
|
|
if self._gitisbare():
|
|
|
|
return True
|
2010-12-20 21:59:33 +03:00
|
|
|
if not ignoreupdate and self._state[1] != self._gitstate():
|
2011-01-04 19:42:00 +03:00
|
|
|
# different version checked out
|
2010-11-15 02:15:26 +03:00
|
|
|
return True
|
|
|
|
# check for staged changes or modified files; ignore untracked files
|
2011-11-11 04:00:11 +04:00
|
|
|
self._gitupdatestat()
|
2010-12-15 05:58:13 +03:00
|
|
|
out, code = self._gitdir(['diff-index', '--quiet', 'HEAD'])
|
|
|
|
return code == 1
|
2010-11-15 02:15:26 +03:00
|
|
|
|
2012-02-07 01:00:08 +04:00
|
|
|
def basestate(self):
|
|
|
|
return self._gitstate()
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-01-31 15:38:00 +03:00
|
|
|
def get(self, state, overwrite=False):
|
2010-11-15 02:20:13 +03:00
|
|
|
source, revision, kind = state
|
2011-05-28 19:03:48 +04:00
|
|
|
if not revision:
|
|
|
|
self.remove()
|
|
|
|
return
|
2010-11-15 02:20:13 +03:00
|
|
|
self._fetch(source, revision)
|
2010-11-15 02:31:40 +03:00
|
|
|
# if the repo was set to be bare, unbare it
|
2011-05-25 19:38:58 +04:00
|
|
|
if self._gitisbare():
|
2010-11-15 02:31:40 +03:00
|
|
|
self._gitcommand(['config', 'core.bare', 'false'])
|
|
|
|
if self._gitstate() == revision:
|
|
|
|
self._gitcommand(['reset', '--hard', 'HEAD'])
|
|
|
|
return
|
|
|
|
elif self._gitstate() == revision:
|
2011-01-31 15:40:05 +03:00
|
|
|
if overwrite:
|
2011-04-11 16:34:40 +04:00
|
|
|
# first reset the index to unmark new files for commit, because
|
2011-01-31 15:40:05 +03:00
|
|
|
# reset --hard will otherwise throw away files added for commit,
|
|
|
|
# not just unmark them.
|
|
|
|
self._gitcommand(['reset', 'HEAD'])
|
|
|
|
self._gitcommand(['reset', '--hard', 'HEAD'])
|
2010-11-15 02:31:29 +03:00
|
|
|
return
|
2010-12-20 21:59:19 +03:00
|
|
|
branch2rev, rev2branch = self._gitbranchmap()
|
2010-11-29 01:19:23 +03:00
|
|
|
|
2011-01-31 15:40:05 +03:00
|
|
|
def checkout(args):
|
|
|
|
cmd = ['checkout']
|
|
|
|
if overwrite:
|
|
|
|
# first reset the index to unmark new files for commit, because
|
|
|
|
# the -f option will otherwise throw away files added for
|
|
|
|
# commit, not just unmark them.
|
|
|
|
self._gitcommand(['reset', 'HEAD'])
|
|
|
|
cmd.append('-f')
|
|
|
|
self._gitcommand(cmd + args)
|
2015-04-11 17:00:04 +03:00
|
|
|
_sanitize(self.ui, self.wvfs, '.git')
|
2011-01-31 15:40:05 +03:00
|
|
|
|
2010-11-29 01:19:23 +03:00
|
|
|
def rawcheckout():
|
2010-11-15 02:31:29 +03:00
|
|
|
# no branch to checkout, check it out with no branch
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('checking out detached HEAD in subrepo %s\n') %
|
2010-11-15 02:20:13 +03:00
|
|
|
self._relpath)
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('check out a git branch if you intend '
|
2010-11-15 02:20:13 +03:00
|
|
|
'to make changes\n'))
|
2011-01-31 15:40:05 +03:00
|
|
|
checkout(['-q', revision])
|
2010-11-29 01:19:23 +03:00
|
|
|
|
|
|
|
if revision not in rev2branch:
|
|
|
|
rawcheckout()
|
2010-11-15 02:31:29 +03:00
|
|
|
return
|
2010-11-28 23:21:23 +03:00
|
|
|
branches = rev2branch[revision]
|
2010-11-15 02:31:29 +03:00
|
|
|
firstlocalbranch = None
|
|
|
|
for b in branches:
|
2010-12-15 05:53:40 +03:00
|
|
|
if b == 'refs/heads/master':
|
2010-11-15 02:31:29 +03:00
|
|
|
# master trumps all other branches
|
2011-01-31 15:40:05 +03:00
|
|
|
checkout(['refs/heads/master'])
|
2010-11-15 02:31:29 +03:00
|
|
|
return
|
2010-12-15 05:53:40 +03:00
|
|
|
if not firstlocalbranch and not b.startswith('refs/remotes/'):
|
2010-11-15 02:31:29 +03:00
|
|
|
firstlocalbranch = b
|
|
|
|
if firstlocalbranch:
|
2011-01-31 15:40:05 +03:00
|
|
|
checkout([firstlocalbranch])
|
2010-11-29 01:19:23 +03:00
|
|
|
return
|
|
|
|
|
2010-12-20 21:59:19 +03:00
|
|
|
tracking = self._gittracking(branch2rev.keys())
|
2010-11-29 01:19:23 +03:00
|
|
|
# choose a remote branch already tracked if possible
|
|
|
|
remote = branches[0]
|
|
|
|
if remote not in tracking:
|
|
|
|
for b in branches:
|
|
|
|
if b in tracking:
|
|
|
|
remote = b
|
|
|
|
break
|
|
|
|
|
|
|
|
if remote not in tracking:
|
|
|
|
# create a new local tracking branch
|
2013-04-17 07:00:05 +04:00
|
|
|
local = remote.split('/', 3)[3]
|
2011-01-31 15:40:05 +03:00
|
|
|
checkout(['-b', local, remote])
|
2010-11-29 01:19:23 +03:00
|
|
|
elif self._gitisancestor(branch2rev[tracking[remote]], remote):
|
|
|
|
# When updating to a tracked remote branch,
|
|
|
|
# if the local tracking branch is downstream of it,
|
|
|
|
# a normal `git pull` would have performed a "fast-forward merge"
|
|
|
|
# which is equivalent to updating the local branch to the remote.
|
|
|
|
# Since we are only looking at branching at update, we need to
|
|
|
|
# detect this situation and perform this action lazily.
|
2010-12-15 05:56:43 +03:00
|
|
|
if tracking[remote] != self._gitcurrentbranch():
|
2011-01-31 15:40:05 +03:00
|
|
|
checkout([tracking[remote]])
|
2010-11-29 01:19:23 +03:00
|
|
|
self._gitcommand(['merge', '--ff', remote])
|
2015-04-11 17:00:04 +03:00
|
|
|
_sanitize(self.ui, self.wvfs, '.git')
|
2010-11-29 01:19:23 +03:00
|
|
|
else:
|
|
|
|
# a real merge would be required, just checkout the revision
|
|
|
|
rawcheckout()
|
2010-11-15 02:20:13 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-11-15 02:15:26 +03:00
|
|
|
def commit(self, text, user, date):
|
2011-03-07 20:03:54 +03:00
|
|
|
if self._gitmissing():
|
|
|
|
raise util.Abort(_("subrepo %s is missing") % self._relpath)
|
2010-11-15 02:15:26 +03:00
|
|
|
cmd = ['commit', '-a', '-m', text]
|
2010-12-07 05:17:27 +03:00
|
|
|
env = os.environ.copy()
|
2010-11-15 02:15:26 +03:00
|
|
|
if user:
|
|
|
|
cmd += ['--author', user]
|
|
|
|
if date:
|
|
|
|
# git's date parser silently ignores when seconds < 1e9
|
|
|
|
# convert to ISO8601
|
2010-12-07 05:17:27 +03:00
|
|
|
env['GIT_AUTHOR_DATE'] = util.datestr(date,
|
|
|
|
'%Y-%m-%dT%H:%M:%S %1%2')
|
|
|
|
self._gitcommand(cmd, env=env)
|
2010-11-15 02:15:26 +03:00
|
|
|
# make sure commit works otherwise HEAD might not exist under certain
|
|
|
|
# circumstances
|
|
|
|
return self._gitstate()
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-11-15 02:22:33 +03:00
|
|
|
def merge(self, state):
|
|
|
|
source, revision, kind = state
|
|
|
|
self._fetch(source, revision)
|
2010-11-28 23:03:48 +03:00
|
|
|
base = self._gitcommand(['merge-base', revision, self._state[1]])
|
2011-11-11 04:00:11 +04:00
|
|
|
self._gitupdatestat()
|
2011-02-09 12:53:09 +03:00
|
|
|
out, code = self._gitdir(['diff-index', '--quiet', 'HEAD'])
|
|
|
|
|
|
|
|
def mergefunc():
|
|
|
|
if base == revision:
|
|
|
|
self.get(state) # fast forward merge
|
|
|
|
elif base != self._state[1]:
|
|
|
|
self._gitcommand(['merge', '--no-commit', revision])
|
2015-04-11 17:00:04 +03:00
|
|
|
_sanitize(self.ui, self.wvfs, '.git')
|
2011-02-09 12:53:09 +03:00
|
|
|
|
|
|
|
if self.dirty():
|
|
|
|
if self._gitstate() != revision:
|
|
|
|
dirty = self._gitstate() == self._state[1] or code != 0
|
2014-12-13 23:19:38 +03:00
|
|
|
if _updateprompt(self.ui, self, dirty,
|
2011-02-17 11:20:44 +03:00
|
|
|
self._state[1][:7], revision[:7]):
|
2011-02-09 12:53:09 +03:00
|
|
|
mergefunc()
|
|
|
|
else:
|
|
|
|
mergefunc()
|
2010-11-15 02:22:33 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2011-09-29 19:20:04 +04:00
|
|
|
def push(self, opts):
|
|
|
|
force = opts.get('force')
|
|
|
|
|
2011-05-28 19:03:48 +04:00
|
|
|
if not self._state[1]:
|
|
|
|
return True
|
2011-03-07 20:03:54 +03:00
|
|
|
if self._gitmissing():
|
|
|
|
raise util.Abort(_("subrepo %s is missing") % self._relpath)
|
2010-11-22 06:00:51 +03:00
|
|
|
# if a branch in origin contains the revision, nothing to do
|
2010-12-20 21:59:19 +03:00
|
|
|
branch2rev, rev2branch = self._gitbranchmap()
|
2010-12-10 00:52:14 +03:00
|
|
|
if self._state[1] in rev2branch:
|
|
|
|
for b in rev2branch[self._state[1]]:
|
2010-12-15 05:53:40 +03:00
|
|
|
if b.startswith('refs/remotes/origin/'):
|
2010-12-10 00:52:14 +03:00
|
|
|
return True
|
2010-11-28 23:21:23 +03:00
|
|
|
for b, revision in branch2rev.iteritems():
|
2010-12-15 05:53:40 +03:00
|
|
|
if b.startswith('refs/remotes/origin/'):
|
2010-11-28 23:21:23 +03:00
|
|
|
if self._gitisancestor(self._state[1], revision):
|
|
|
|
return True
|
2010-11-22 06:00:51 +03:00
|
|
|
# otherwise, try to push the currently checked out branch
|
2010-11-15 02:22:33 +03:00
|
|
|
cmd = ['push']
|
|
|
|
if force:
|
|
|
|
cmd.append('--force')
|
2010-12-15 05:56:43 +03:00
|
|
|
|
|
|
|
current = self._gitcurrentbranch()
|
2010-11-15 02:31:29 +03:00
|
|
|
if current:
|
2010-11-22 06:00:51 +03:00
|
|
|
# determine if the current branch is even useful
|
|
|
|
if not self._gitisancestor(self._state[1], current):
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('unrelated git branch checked out '
|
2010-11-22 06:00:51 +03:00
|
|
|
'in subrepo %s\n') % self._relpath)
|
|
|
|
return False
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.status(_('pushing branch %s of subrepo %s\n') %
|
|
|
|
(current.split('/', 2)[2], self._relpath))
|
2014-04-11 23:38:18 +04:00
|
|
|
ret = self._gitdir(cmd + ['origin', current])
|
|
|
|
return ret[1] == 0
|
2010-11-15 02:31:29 +03:00
|
|
|
else:
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('no branch checked out in subrepo %s\n'
|
|
|
|
'cannot push revision %s\n') %
|
2010-11-22 06:00:51 +03:00
|
|
|
(self._relpath, self._state[1]))
|
2010-11-15 02:31:29 +03:00
|
|
|
return False
|
2010-11-15 02:22:33 +03:00
|
|
|
|
2015-02-24 10:49:22 +03:00
|
|
|
@annotatesubrepoerror
|
|
|
|
def add(self, ui, match, prefix, explicitonly, **opts):
|
|
|
|
if self._gitmissing():
|
|
|
|
return []
|
|
|
|
|
2015-02-26 23:53:54 +03:00
|
|
|
(modified, added, removed,
|
2015-03-04 05:17:29 +03:00
|
|
|
deleted, unknown, ignored, clean) = self.status(None, unknown=True,
|
|
|
|
clean=True)
|
2015-02-26 23:53:54 +03:00
|
|
|
|
2015-02-28 07:30:42 +03:00
|
|
|
tracked = set()
|
|
|
|
# dirstates 'amn' warn, 'r' is added again
|
|
|
|
for l in (modified, added, deleted, clean):
|
|
|
|
tracked.update(l)
|
|
|
|
|
2015-02-26 23:53:54 +03:00
|
|
|
# Unknown files not of interest will be rejected by the matcher
|
|
|
|
files = unknown
|
|
|
|
files.extend(match.files())
|
|
|
|
|
2015-02-28 07:30:42 +03:00
|
|
|
rejected = []
|
|
|
|
|
2015-02-26 23:53:54 +03:00
|
|
|
files = [f for f in sorted(set(files)) if match(f)]
|
2015-02-24 10:49:22 +03:00
|
|
|
for f in files:
|
|
|
|
exact = match.exact(f)
|
|
|
|
command = ["add"]
|
|
|
|
if exact:
|
|
|
|
command.append("-f") #should be added, even if ignored
|
|
|
|
if ui.verbose or not exact:
|
|
|
|
ui.status(_('adding %s\n') % match.rel(f))
|
2015-02-28 07:30:42 +03:00
|
|
|
|
|
|
|
if f in tracked: # hg prints 'adding' even if already tracked
|
|
|
|
if exact:
|
|
|
|
rejected.append(f)
|
|
|
|
continue
|
2015-02-24 10:49:22 +03:00
|
|
|
if not opts.get('dry_run'):
|
|
|
|
self._gitcommand(command + [f])
|
2015-02-28 07:30:42 +03:00
|
|
|
|
|
|
|
for f in rejected:
|
|
|
|
ui.warn(_("%s already tracked!\n") % match.abs(f))
|
|
|
|
|
|
|
|
return rejected
|
2015-02-24 10:49:22 +03:00
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-11-15 02:31:40 +03:00
|
|
|
def remove(self):
|
2011-03-07 20:03:54 +03:00
|
|
|
if self._gitmissing():
|
|
|
|
return
|
2010-11-15 02:31:40 +03:00
|
|
|
if self.dirty():
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.warn(_('not removing repo %s because '
|
|
|
|
'it has changes.\n') % self._relpath)
|
2010-11-15 02:31:40 +03:00
|
|
|
return
|
|
|
|
# we can't fully delete the repository as it may contain
|
|
|
|
# local-only history
|
2014-12-13 23:19:38 +03:00
|
|
|
self.ui.note(_('removing subrepo %s\n') % self._relpath)
|
2010-11-15 02:31:40 +03:00
|
|
|
self._gitcommand(['config', 'core.bare', 'true'])
|
2015-04-10 18:47:09 +03:00
|
|
|
for f, kind in self.wvfs.readdir():
|
2010-11-15 02:31:40 +03:00
|
|
|
if f == '.git':
|
|
|
|
continue
|
2015-04-10 18:47:09 +03:00
|
|
|
if kind == stat.S_IFDIR:
|
2015-04-10 18:47:09 +03:00
|
|
|
self.wvfs.rmtree(f)
|
2010-11-15 02:31:40 +03:00
|
|
|
else:
|
2015-04-10 18:47:09 +03:00
|
|
|
self.wvfs.unlink(f)
|
2010-11-15 02:31:40 +03:00
|
|
|
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
def archive(self, archiver, prefix, match=None):
|
2013-03-22 01:09:15 +04:00
|
|
|
total = 0
|
2010-11-19 03:20:21 +03:00
|
|
|
source, revision = self._state
|
2011-05-28 19:03:48 +04:00
|
|
|
if not revision:
|
2013-03-22 01:09:15 +04:00
|
|
|
return total
|
2010-11-19 03:20:21 +03:00
|
|
|
self._fetch(source, revision)
|
|
|
|
|
|
|
|
# Parse git's native archive command.
|
|
|
|
# This should be much faster than manually traversing the trees
|
|
|
|
# and objects with many subprocess calls.
|
|
|
|
tarstream = self._gitcommand(['archive', revision], stream=True)
|
|
|
|
tar = tarfile.open(fileobj=tarstream, mode='r|')
|
2010-11-29 18:34:10 +03:00
|
|
|
relpath = subrelpath(self)
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files'))
|
2010-11-29 18:34:10 +03:00
|
|
|
for i, info in enumerate(tar):
|
2010-12-20 21:59:33 +03:00
|
|
|
if info.isdir():
|
|
|
|
continue
|
2012-06-17 06:34:06 +04:00
|
|
|
if match and not match(info.name):
|
|
|
|
continue
|
2010-12-20 21:59:33 +03:00
|
|
|
if info.issym():
|
|
|
|
data = info.linkname
|
|
|
|
else:
|
|
|
|
data = tar.extractfile(info).read()
|
2015-04-09 18:36:42 +03:00
|
|
|
archiver.addfile(self.wvfs.reljoin(prefix, self._path, info.name),
|
2010-12-20 21:59:33 +03:00
|
|
|
info.mode, info.issym(), data)
|
2013-03-22 01:09:15 +04:00
|
|
|
total += 1
|
subrepo: drop the 'ui' parameter to archive()
The current state of subrepo methods is to pass a 'ui' object to some methods,
which has the effect of overriding the subrepo configuration since it is the
root repo's 'ui' that is passed along as deep as there are subrepos. Other
subrepo method are *not* passed the root 'ui', and instead delegate to their
repo object's 'ui'. Even in the former case where the root 'ui' is available,
some methods are inconsistent in their use of both the root 'ui' and the local
repo's 'ui'. (Consider hg._incoming() uses the root 'ui' for path expansion
and some status messages, but also calls bundlerepo.getremotechanges(), which
eventually calls discovery.findcommonincoming(), which calls
setdiscovery.findcommonheads(), which calls status() on the local repo 'ui'.)
This inconsistency with respect to the configured output level is probably
always hidden, because --verbose, --debug and --quiet, along with their 'ui.xxx'
equivalents in the global and user level hgrc files are propagated from the
parent repo to the subrepo via 'baseui'. The 'ui.xxx' settings in the parent
repo hgrc file are not propagated, but that seems like an unusual thing to set
on a per repo config file. Any 'ui.xxx' options changed by --config are also
not propagated, because they are set on repo.ui by dispatch.py, not repo.baseui.
The goal here is to cleanup the subrepo methods by dropping the 'ui' parameter,
which in turn prevents mixing subtly different 'ui' instances on a given subrepo
level. Some methods use more than just the output level settings in 'ui' (add
for example ends up calling scmutil.checkportabilityalert() with both the root
and local repo's 'ui' at different points). This series just goes for the low
hanging fruit and switches methods that only use the output level.
If we really care about not letting a subrepo config override the root repo's
output level, we can propagate the verbose, debug and quiet settings to the
subrepo in the same way 'ui.commitsubrepos' is in hgsubrepo.__init__.
Archive only uses the 'ui' object to call its progress() method, and gitsubrepo
calls status().
2014-12-13 22:53:46 +03:00
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, i + 1,
|
|
|
|
unit=_('files'))
|
|
|
|
self.ui.progress(_('archiving (%s)') % relpath, None)
|
2013-03-22 01:09:15 +04:00
|
|
|
return total
|
2010-11-29 18:34:10 +03:00
|
|
|
|
2010-11-19 03:20:21 +03:00
|
|
|
|
2015-02-01 16:09:31 +03:00
|
|
|
@annotatesubrepoerror
|
|
|
|
def cat(self, match, prefix, **opts):
|
|
|
|
rev = self._state[1]
|
|
|
|
if match.anypats():
|
|
|
|
return 1 #No support for include/exclude yet
|
|
|
|
|
|
|
|
if not match.files():
|
|
|
|
return 1
|
|
|
|
|
|
|
|
for f in match.files():
|
|
|
|
output = self._gitcommand(["show", "%s:%s" % (rev, f)])
|
|
|
|
fp = cmdutil.makefileobj(self._subparent, opts.get('output'),
|
|
|
|
self._ctx.node(),
|
2015-04-09 18:36:42 +03:00
|
|
|
pathname=self.wvfs.reljoin(prefix, f))
|
2015-02-01 16:09:31 +03:00
|
|
|
fp.write(output)
|
|
|
|
fp.close()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2012-12-14 02:37:53 +04:00
|
|
|
@annotatesubrepoerror
|
2010-12-20 21:59:33 +03:00
|
|
|
def status(self, rev2, **opts):
|
2011-05-28 19:03:48 +04:00
|
|
|
rev1 = self._state[1]
|
|
|
|
if self._gitmissing() or not rev1:
|
2011-03-07 20:03:54 +03:00
|
|
|
# if the repo is missing, return no results
|
2015-03-04 05:24:16 +03:00
|
|
|
return scmutil.status([], [], [], [], [], [], [])
|
2010-12-20 21:59:33 +03:00
|
|
|
modified, added, removed = [], [], []
|
2011-11-11 04:00:11 +04:00
|
|
|
self._gitupdatestat()
|
2010-12-20 21:59:33 +03:00
|
|
|
if rev2:
|
|
|
|
command = ['diff-tree', rev1, rev2]
|
|
|
|
else:
|
|
|
|
command = ['diff-index', rev1]
|
|
|
|
out = self._gitcommand(command)
|
|
|
|
for line in out.split('\n'):
|
|
|
|
tab = line.find('\t')
|
|
|
|
if tab == -1:
|
|
|
|
continue
|
|
|
|
status, f = line[tab - 1], line[tab + 1:]
|
|
|
|
if status == 'M':
|
|
|
|
modified.append(f)
|
|
|
|
elif status == 'A':
|
|
|
|
added.append(f)
|
|
|
|
elif status == 'D':
|
|
|
|
removed.append(f)
|
|
|
|
|
2014-10-12 09:43:14 +04:00
|
|
|
deleted, unknown, ignored, clean = [], [], [], []
|
2014-11-28 22:16:15 +03:00
|
|
|
|
2015-03-10 00:14:09 +03:00
|
|
|
command = ['status', '--porcelain', '-z']
|
2015-03-04 05:31:16 +03:00
|
|
|
if opts.get('unknown'):
|
2015-03-10 00:14:09 +03:00
|
|
|
command += ['--untracked-files=all']
|
|
|
|
if opts.get('ignored'):
|
|
|
|
command += ['--ignored']
|
|
|
|
out = self._gitcommand(command)
|
|
|
|
|
|
|
|
changedfiles = set()
|
|
|
|
changedfiles.update(modified)
|
|
|
|
changedfiles.update(added)
|
|
|
|
changedfiles.update(removed)
|
|
|
|
for line in out.split('\0'):
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
st = line[0:2]
|
|
|
|
#moves and copies show 2 files on one line
|
|
|
|
if line.find('\0') >= 0:
|
|
|
|
filename1, filename2 = line[3:].split('\0')
|
|
|
|
else:
|
|
|
|
filename1 = line[3:]
|
|
|
|
filename2 = None
|
|
|
|
|
|
|
|
changedfiles.add(filename1)
|
|
|
|
if filename2:
|
|
|
|
changedfiles.add(filename2)
|
|
|
|
|
|
|
|
if st == '??':
|
|
|
|
unknown.append(filename1)
|
|
|
|
elif st == '!!':
|
|
|
|
ignored.append(filename1)
|
|
|
|
|
|
|
|
if opts.get('clean'):
|
|
|
|
out = self._gitcommand(['ls-files'])
|
|
|
|
for f in out.split('\n'):
|
|
|
|
if not f in changedfiles:
|
|
|
|
clean.append(f)
|
2014-11-28 22:16:15 +03:00
|
|
|
|
2014-10-14 09:52:27 +04:00
|
|
|
return scmutil.status(modified, added, removed, deleted,
|
|
|
|
unknown, ignored, clean)
|
2010-12-20 21:59:33 +03:00
|
|
|
|
2014-12-10 12:32:51 +03:00
|
|
|
@annotatesubrepoerror
|
|
|
|
def diff(self, ui, diffopts, node2, match, prefix, **opts):
|
|
|
|
node1 = self._state[1]
|
|
|
|
cmd = ['diff']
|
|
|
|
if opts['stat']:
|
|
|
|
cmd.append('--stat')
|
|
|
|
else:
|
|
|
|
# for Git, this also implies '-p'
|
|
|
|
cmd.append('-U%d' % diffopts.context)
|
|
|
|
|
2015-04-09 18:36:42 +03:00
|
|
|
gitprefix = self.wvfs.reljoin(prefix, self._path)
|
2014-12-10 12:32:51 +03:00
|
|
|
|
|
|
|
if diffopts.noprefix:
|
|
|
|
cmd.extend(['--src-prefix=%s/' % gitprefix,
|
|
|
|
'--dst-prefix=%s/' % gitprefix])
|
|
|
|
else:
|
|
|
|
cmd.extend(['--src-prefix=a/%s/' % gitprefix,
|
|
|
|
'--dst-prefix=b/%s/' % gitprefix])
|
|
|
|
|
|
|
|
if diffopts.ignorews:
|
|
|
|
cmd.append('--ignore-all-space')
|
|
|
|
if diffopts.ignorewsamount:
|
|
|
|
cmd.append('--ignore-space-change')
|
|
|
|
if self._gitversion(self._gitcommand(['--version'])) >= (1, 8, 4) \
|
|
|
|
and diffopts.ignoreblanklines:
|
|
|
|
cmd.append('--ignore-blank-lines')
|
|
|
|
|
|
|
|
cmd.append(node1)
|
|
|
|
if node2:
|
|
|
|
cmd.append(node2)
|
|
|
|
|
|
|
|
if match.anypats():
|
|
|
|
return #No support for include/exclude yet
|
|
|
|
|
2015-01-21 23:47:27 +03:00
|
|
|
output = ""
|
2014-12-10 12:32:51 +03:00
|
|
|
if match.always():
|
2015-01-21 23:47:27 +03:00
|
|
|
output += self._gitcommand(cmd) + '\n'
|
2014-12-10 12:32:51 +03:00
|
|
|
elif match.files():
|
|
|
|
for f in match.files():
|
2015-01-21 23:47:27 +03:00
|
|
|
output += self._gitcommand(cmd + [f]) + '\n'
|
2014-12-10 12:32:51 +03:00
|
|
|
elif match(gitprefix): #Subrepo is matched
|
2015-01-21 23:47:27 +03:00
|
|
|
output += self._gitcommand(cmd) + '\n'
|
|
|
|
|
|
|
|
if output.strip():
|
|
|
|
ui.write(output)
|
2014-12-10 12:32:51 +03:00
|
|
|
|
2014-12-29 01:59:57 +03:00
|
|
|
@annotatesubrepoerror
|
2014-12-18 21:07:03 +03:00
|
|
|
def revert(self, substate, *pats, **opts):
|
|
|
|
self.ui.status(_('reverting subrepo %s\n') % substate[0])
|
2014-12-14 13:34:51 +03:00
|
|
|
if not opts.get('no_backup'):
|
2014-12-28 12:42:25 +03:00
|
|
|
status = self.status(None)
|
|
|
|
names = status.modified
|
|
|
|
for name in names:
|
|
|
|
bakname = "%s.orig" % name
|
|
|
|
self.ui.note(_('saving current version of %s as %s\n') %
|
|
|
|
(name, bakname))
|
2015-02-07 20:57:40 +03:00
|
|
|
self.wvfs.rename(name, bakname)
|
2014-12-14 13:34:51 +03:00
|
|
|
|
2015-02-08 05:47:28 +03:00
|
|
|
if not opts.get('dry_run'):
|
|
|
|
self.get(substate, overwrite=True)
|
2014-12-14 13:34:51 +03:00
|
|
|
return []
|
|
|
|
|
2014-05-07 02:08:20 +04:00
|
|
|
def shortid(self, revid):
|
|
|
|
return revid[:7]
|
|
|
|
|
2010-01-01 02:10:03 +03:00
|
|
|
types = {
|
|
|
|
'hg': hgsubrepo,
|
2009-12-31 22:16:03 +03:00
|
|
|
'svn': svnsubrepo,
|
2010-11-15 02:15:26 +03:00
|
|
|
'git': gitsubrepo,
|
2010-01-01 02:10:03 +03:00
|
|
|
}
|