annotate svncommands.py @ 256:7932d098cb5f

Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
author Augie Fackler <durin42@gmail.com>
date Fri, 10 Apr 2009 18:47:18 -0500
parents 246aaefb1cc0
children ffccf0080e54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
1 import os
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
2 import cPickle as pickle
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
3
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
4 from mercurial import cmdutil as hgcmdutil
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
5 from mercurial import commands
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
6 from mercurial import hg
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
7 from mercurial import node
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
8 from mercurial import patch
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
9 from mercurial import util as hgutil
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
10
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
11 from svn import core
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
12 from svn import delta
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
13
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
14 import hg_delta_editor
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
15 import svnwrap
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
16 import stupid as stupidmod
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
17 import cmdutil
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
18 import util
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
19 import utility_commands
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
20
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
21
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
22 def clone(orig, ui, source, dest=None, **opts):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
23 '''clone Subversion repository to a local Mercurial repository.
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
24
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
25 If no destination directory name is specified, it defaults to the
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
26 basename of the source plus "-hg".
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
27
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
28 You can specify multiple paths for the location of tags using comma
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
29 separated values.
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
30 '''
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
31 svnurl = ui.expandpath(source)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
32 if not cmdutil.issvnurl(svnurl):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
33 orig(ui, repo, source=source, dest=dest, *args, **opts)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
34
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
35 if not dest:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
36 dest = hg.defaultdest(source) + '-hg'
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
37 ui.status("Assuming destination %s\n" % dest)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
38
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
39 if os.path.exists(dest):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
40 raise hgutil.Abort("destination '%s' already exists" % dest)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
41 url = util.normalize_url(svnurl)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
42 res = -1
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
43 try:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
44 try:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
45 res = pull(None, ui, None, True, opts.pop('svn_stupid', False),
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
46 source=url, create_new_dest=dest, **opts)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
47 except core.SubversionException, e:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
48 if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
49 raise hgutil.Abort('It appears svn does not trust the ssl cert for this site.\n'
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
50 'Please try running svn ls on that url first.')
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
51 raise
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
52 finally:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
53 if os.path.exists(dest):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
54 repo = hg.repository(ui, dest)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
55 fp = repo.opener("hgrc", "w", text=True)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
56 fp.write("[paths]\n")
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
57 # percent needs to be escaped for ConfigParser
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
58 fp.write("default = %(url)s\nsvn = %(url)s\n" % {'url': svnurl.replace('%', '%%')})
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
59 fp.close()
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
60 if res is None or res == 0:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
61 commands.update(ui, repo, repo['tip'].node())
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
62
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
63 return res
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
64
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
65
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
66 def pull(orig, ui, repo, svn=None, svn_stupid=False, source="default", create_new_dest=False,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
67 *args, **opts):
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
68 """pull new revisions from Subversion
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
69 """
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
70 url = ui.expandpath(source)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
71 if not (cmdutil.issvnurl(url) or svn or create_new_dest):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
72 orig(ui, repo, source=source, *args, **opts)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
73 svn_url = url
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
74 svn_url = util.normalize_url(svn_url)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
75 old_encoding = util.swap_out_encoding()
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
76 # TODO implement skipto support
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
77 skipto_rev = 0
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
78 have_replay = not svn_stupid
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
79 if have_replay and not callable(
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
80 delta.svn_txdelta_apply(None, None, None)[0]): #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
81 ui.status('You are using old Subversion SWIG bindings. Replay will not'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
82 ' work until you upgrade to 1.5.0 or newer. Falling back to'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
83 ' a slower method that may be buggier. Please upgrade, or'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
84 ' contribute a patch to use the ctypes bindings instead'
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
85 ' of SWIG.\n')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
86 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
87 initializing_repo = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
88 user = opts.get('username', hgutil.getuser())
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
89 passwd = opts.get('password', '')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
90 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
91 author_host = "@%s" % svn.uuid
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
92 # TODO these should be configurable again, but I'm torn on how.
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
93 # Maybe this should be configured in .hg/hgrc for each repo? Seems vaguely reasonable.
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
94 tag_locations = ['tags', ]
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
95 authors = None
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
96 filemap = None
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
97 if repo:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
98 hg_editor = hg_delta_editor.HgChangeReceiver(repo=repo)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
99 else:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
100 hg_editor = hg_delta_editor.HgChangeReceiver(ui_=ui,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
101 path=create_new_dest,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
102 subdir=svn.subdir,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
103 author_host=author_host,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
104 tag_locations=tag_locations,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
105 authors=authors,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
106 filemap=filemap)
241
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
107 if os.path.exists(hg_editor.uuid_file):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
108 uuid = open(hg_editor.uuid_file).read()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
109 assert uuid == svn.uuid
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
110 start = hg_editor.last_known_revision()
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
111 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
112 open(hg_editor.uuid_file, 'w').write(svn.uuid)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
113 open(hg_editor.svn_url_file, 'w').write(svn_url)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
114 initializing_repo = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
115 start = skipto_rev
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
116
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
117 if initializing_repo and start > 0:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
118 raise hgutil.Abort('Revision skipping at repository initialization '
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
119 'remains unimplemented.')
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
120
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
121 # start converting revisions
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
122 for r in svn.revisions(start=start):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
123 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
124 hg_editor.update_branch_tag_map_for_rev(r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
125 for p in r.paths:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
126 if hg_editor._is_path_valid(p):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
127 valid = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
128 break
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
129 if valid:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
130 # got a 502? Try more than once!
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
131 tries = 0
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
132 converted = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
133 while not converted:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
134 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
135 util.describe_revision(ui, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
136 if have_replay:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
137 try:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
138 cmdutil.replay_convert_rev(hg_editor, svn, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
139 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
140 ui.status('%s\n' % e.message)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
141 stupidmod.print_your_svn_is_old_message(ui)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
142 have_replay = False
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
143 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
144 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
145 stupidmod.svn_server_pull_rev(ui, svn, hg_editor, r)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
146 converted = True
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
147 except core.SubversionException, e: #pragma: no cover
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
148 if (e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
149 and '502' in str(e)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
150 and tries < 3):
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
151 tries += 1
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
152 ui.status('Got a 502, retrying (%s)\n' % tries)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
153 else:
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
154 raise hgutil.Abort(*e.args)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
155 util.swap_out_encoding(old_encoding)
4950b18cf949 Move fetch_command.fetch_revisions() to svncommands.pull().
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
156
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
157
255
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
158 def incoming(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
159 tag_locations='tags', authors=None, filemap=None, **opts):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
160 """show incoming revisions from Subversion
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
161 """
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
162 svn_url = util.normalize_url(svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
163
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
164 initializing_repo = False
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
165 user = opts.get('username', hgutil.getuser())
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
166 passwd = opts.get('password', '')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
167 svn = svnwrap.SubversionRepo(svn_url, user, passwd)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
168 author_host = "@%s" % svn.uuid
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
169 tag_locations = tag_locations.split(',')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
170 hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
171 ui_=ui,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
172 subdir=svn.subdir,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
173 author_host=author_host,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
174 tag_locations=tag_locations,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
175 authors=authors,
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
176 filemap=filemap)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
177 if os.path.exists(hg_editor.uuid_file):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
178 uuid = open(hg_editor.uuid_file).read()
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
179 assert uuid == svn.uuid
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
180 start = hg_editor.last_known_revision()
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
181 else:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
182 open(hg_editor.uuid_file, 'w').write(svn.uuid)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
183 open(hg_editor.svn_url_file, 'w').write(svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
184 initializing_repo = True
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
185 start = skipto_rev
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
186
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
187 if initializing_repo and start > 0:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
188 raise hgutil.Abort('Revision skipping at repository initialization '
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
189 'remains unimplemented.')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
190
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
191 rev_stuff = (('revision', 'revnum'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
192 ('user', 'author'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
193 ('date', 'date'),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
194 ('message', 'message')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
195 )
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
196
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
197 ui.status('incoming changes from %s\n' % svn_url)
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
198
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
199 for r in svn.revisions(start=start):
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
200 ui.status('\n')
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
201 for label, attr in rev_stuff:
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
202 l1 = label+':'
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
203 ui.status('%s%s\n' % (l1.ljust(13),
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
204 str(r.__getattribute__(attr)).strip(), ))
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
205
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
206
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
207 def push(orig, ui, repo, dest=None, **opts):
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
208 """push revisions starting at a specified head back to Subversion.
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
209 """
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
210 svnurl = ui.expandpath(dest or 'default-push', dest or 'default')
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
211 if not cmdutil.issvnurl(svnurl):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
212 orig(ui, repo, dest=dest, *args, **opts)
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
213 old_encoding = util.swap_out_encoding()
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
214 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
215 assert svnurl == hge.url
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
216 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
217 hge.revmap.iterkeys()))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
218 user = opts.get('username', hgutil.getuser())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
219 passwd = opts.get('password', '')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
220
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
221 # Strategy:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
222 # 1. Find all outgoing commits from this head
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
223 if len(repo.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
224 ui.status('Cowardly refusing to push branch merge')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
225 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
226 workingrev = repo.parents()[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
227 outgoing = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, workingrev.node())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
228 if not (outgoing and len(outgoing)):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
229 ui.status('No revisions to push.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
230 return 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
231 while outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
232 oldest = outgoing.pop(-1)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
233 old_ctx = repo[oldest]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
234 if len(old_ctx.parents()) != 1:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
235 ui.status('Found a branch merge, this needs discussion and '
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
236 'implementation.')
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
237 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
238 base_n = old_ctx.parents()[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
239 old_children = repo[base_n].children()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
240 svnbranch = repo[base_n].branch()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
241 oldtip = base_n
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
242 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
243 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
244 while samebranchchildren:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
245 oldtip = samebranchchildren[0].node()
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
246 samebranchchildren = [c for c in repo[oldtip].children() if c.branch() == svnbranch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
247 and c.node() in svn_commit_hashes]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
248 # 2. Commit oldest revision that needs to be pushed
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
249 base_revision = svn_commit_hashes[base_n][0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
250 try:
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
251 cmdutil.commit_from_rev(ui, repo, old_ctx, hge, svnurl,
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
252 base_revision, user, passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
253 except cmdutil.NoFilesException:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
254 ui.warn("Could not push revision %s because it had no changes in svn.\n" %
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
255 old_ctx)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
256 return 1
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
257 # 3. Fetch revisions from svn
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
258 r = pull(None, ui, repo, True, stupid=opts.get('svn_stupid', False),
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
259 username=user, password=passwd)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
260 assert not r or r == 0
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
261 # 4. Find the new head of the target branch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
262 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
263 oldtipctx = repo[oldtip]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
264 replacement = [c for c in oldtipctx.children() if c not in old_children
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
265 and c.branch() == oldtipctx.branch()]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
266 assert len(replacement) == 1, 'Replacement node came back as: %r' % replacement
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
267 replacement = replacement[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
268 # 5. Rebase all children of the currently-pushing rev to the new branch
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
269 heads = repo.heads(old_ctx.node())
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
270 for needs_transplant in heads:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
271 def extrafn(ctx, extra):
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
272 if ctx.node() == oldest:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
273 return
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
274 extra['branch'] = ctx.branch()
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
275 utility_commands.rebase(ui, repo, extrafn=extrafn,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
276 sourcerev=needs_transplant, **opts)
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
277 repo = hg.repository(ui, hge.path)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
278 for child in repo[replacement.node()].children():
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
279 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
280 if rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
281 while rebasesrc in outgoing:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
282 rebsrcindex = outgoing.index(rebasesrc)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
283 outgoing = (outgoing[0:rebsrcindex] +
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
284 [child.node(), ] + outgoing[rebsrcindex+1:])
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
285 children = [c for c in child.children() if c.branch() == child.branch()]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
286 if children:
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
287 child = children[0]
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
288 rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid)))
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
289 hge = hg_delta_editor.HgChangeReceiver(hge.path, ui_=ui)
242
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
290 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys()))
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
291 util.swap_out_encoding(old_encoding)
06130689a2c8 Move push into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 241
diff changeset
292 return 0
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
293
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
294
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
295 def diff(orig, ui, repo, *args, **opts):
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
296 """show a diff of the most recent revision against its parent from svn
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
297 """
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
298 if not opts.get('svn', False) or opts.get('change', None):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
299 return orig(ui, repo, *args, **opts)
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
300 svn_commit_hashes = {}
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
301 hge = hg_delta_editor.HgChangeReceiver(repo=repo)
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
302 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
303 hge.revmap.iterkeys()))
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
304 if not opts.get('rev', None):
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
305 parent = repo.parents()[0]
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
306 o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes,
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
307 parent.node())
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
308 if o_r:
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
309 parent = repo[o_r[-1]].parents()[0]
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
310 opts['rev'] = ['%s:.' % node.hex(parent.node()), ]
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
311 node1, node2 = hgcmdutil.revpair(repo, opts['rev'])
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
312 baserev, _junk = svn_commit_hashes.get(node1, (-1, 'junk', ))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
313 newrev, _junk = svn_commit_hashes.get(node2, (-1, 'junk', ))
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
314 it = patch.diff(repo, node1, node2,
244
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
315 opts=patch.diffopts(ui, opts={'git': True,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
316 'show_function': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
317 'ignore_all_space': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
318 'ignore_space_change': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
319 'ignore_blank_lines': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
320 'unified': True,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
321 'text': False,
28d0ee605308 Move diff to svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 242
diff changeset
322 }))
256
7932d098cb5f Refactor commands to wrap their hg equivalent adding a --svn flag where sane.
Augie Fackler <durin42@gmail.com>
parents: 255
diff changeset
323 ui.write(cmdutil.filterdiff(''.join(it), baserev, newrev))
246
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
324
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
325
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
326 def rebuildmeta(ui, repo, hg_repo_path, args, **opts):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
327 """rebuild hgsubversion metadata using values stored in revisions
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
328 """
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
329 if len(args) != 1:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
330 raise hgutil.Abort('You must pass the svn URI used to create this repo.')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
331 uuid = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
332 url = args[0].rstrip('/')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
333 user = opts.get('username', hgutil.getuser())
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
334 passwd = opts.get('password', '')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
335 svn = svnwrap.SubversionRepo(url, user, passwd)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
336 subdir = svn.subdir
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
337 svnmetadir = os.path.join(repo.path, 'svn')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
338 if not os.path.exists(svnmetadir):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
339 os.makedirs(svnmetadir)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
340
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
341 revmap = open(os.path.join(svnmetadir, 'rev_map'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
342 revmap.write('1\n')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
343 last_rev = -1
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
344 branchinfo = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
345 noderevnums = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
346 for rev in repo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
347 ctx = repo[rev]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
348 convinfo = ctx.extra().get('convert_revision', None)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
349 if convinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
350 assert convinfo.startswith('svn:')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
351 revpath, revision = convinfo[40:].split('@')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
352 if subdir and subdir[0] != '/':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
353 subdir = '/' + subdir
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
354 if subdir and subdir[-1] == '/':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
355 subdir = subdir[:-1]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
356 assert revpath.startswith(subdir), ('That does not look like the '
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
357 'right location in the repo.')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
358 if uuid is None:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
359 uuid = convinfo[4:40]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
360 assert uuid == svn.uuid, 'UUIDs did not match!'
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
361 urlfile = open(os.path.join(svnmetadir, 'url'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
362 urlfile.write(url)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
363 urlfile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
364 uuidfile = open(os.path.join(svnmetadir, 'uuid'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
365 uuidfile.write(uuid)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
366 uuidfile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
367 commitpath = revpath[len(subdir)+1:]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
368 if commitpath.startswith('branches'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
369 commitpath = commitpath[len('branches/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
370 elif commitpath == 'trunk':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
371 commitpath = ''
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
372 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
373 assert False, 'Unhandled case in rebuildmeta'
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
374 revmap.write('%s %s %s\n' % (revision,
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
375 node.hex(ctx.node()),
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
376 commitpath))
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
377 revision = int(revision)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
378 noderevnums[ctx.node()] = revision
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
379 if revision > last_rev:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
380 last_rev = revision
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
381 branch = ctx.branch()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
382 if branch == 'default':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
383 branch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
384 if branch not in branchinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
385 parent = ctx.parents()[0]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
386 if (parent.node() in noderevnums
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
387 and parent.branch() != ctx.branch()):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
388 parentbranch = parent.branch()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
389 if parentbranch == 'default':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
390 parentbranch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
391 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
392 parentbranch = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
393 branchinfo[branch] = (parentbranch,
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
394 noderevnums.get(parent.node(), 0),
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
395 revision)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
396 for c in ctx.children():
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
397 if c.branch() == 'closed-branches':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
398 if branch in branchinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
399 del branchinfo[branch]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
400 branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
401 pickle.dump(branchinfo, branchinfofile)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
402 branchinfofile.close()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
403
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
404 # now handle tags
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
405 tagsinfo = {}
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
406 realtags = svn.tags
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
407 tagsleft = realtags.items()
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
408 while tagsleft:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
409 tag, tagparent = tagsleft.pop(0)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
410 source, rev = tagparent
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
411 if source.startswith('tags/'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
412 src = source[len('tags/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
413 if src in tagsinfo:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
414 tagsinfo[tag] = tagsinfo[src]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
415 elif src in realtags:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
416 if (realtags[src][1] <= last_rev
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
417 or realtags[src][0].startswith('tags/')):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
418 tagsleft.append(src)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
419 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
420 older_tags = svn.tags_at_rev(rev)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
421 newsrc, newrev = older_tags[src]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
422 tagsleft.append((tag, (newsrc, newrev)))
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
423 continue
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
424 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
425 # determine the branch
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
426 assert not source.startswith('tags/'), "Tags can't be tags of other tags."
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
427 if source.startswith('branches/'):
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
428 source = source[len('branches/'):]
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
429 elif source == 'trunk':
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
430 source = None
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
431 else:
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
432 source = '../' + source
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
433 if rev <= last_rev and (source or 'default') in repo.branchtags():
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
434 tagsinfo[tag] = source, rev
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
435
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
436 tagsinfofile = open(os.path.join(svnmetadir, 'tag_info'), 'w')
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
437 pickle.dump(tagsinfo, tagsinfofile)
074f27c68818 Move rebuildmeta into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 244
diff changeset
438 tagsinfofile.close()
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
439
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
440
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
441 def help(ui, args=None, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
442 """show help for a given subcommands or a help overview
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
443 """
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
444 if args:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
445 subcommand = args[0]
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
446 if subcommand not in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
447 candidates = []
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
448 for c in table:
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
449 if c.startswith(subcommand):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
450 candidates.append(c)
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
451 if len(candidates) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
452 subcommand = candidates[0]
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
453 elif len(candidates) > 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
454 ui.status('Ambiguous command. Could have been:\n%s\n' %
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
455 ' '.join(candidates))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
456 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
457 doc = table[subcommand].__doc__
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
458 if doc is None:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
459 doc = "No documentation available for %s." % subcommand
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
460 ui.status(doc.strip(), '\n')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
461 return
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
462 ui.status(_helpgen())
247
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
463
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
464
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
465 def update(ui, args, repo, clean=False, **opts):
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
466 """update to a specified Subversion revision number
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
467 """
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
468 assert len(args) == 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
469 rev = int(args[0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
470 path = os.path.join(repo.path, 'svn', 'rev_map')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
471 answers = []
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
472 for k,v in util.parse_revmap(path).iteritems():
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
473 if k[0] == rev:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
474 answers.append((v, k[1]))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
475 if len(answers) == 1:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
476 if clean:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
477 return hg.clean(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
478 return hg.update(repo, answers[0][0])
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
479 elif len(answers) == 0:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
480 ui.status('Revision %s did not produce an hg revision.\n' % rev)
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
481 return 1
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
482 else:
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
483 ui.status('Ambiguous revision!\n')
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
484 ui.status('\n'.join(['%s on %s' % (node.hex(a[0]), a[1]) for a in
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
485 answers]+['']))
1272e87546ed Move help, update into svncommands.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 246
diff changeset
486 return 1
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
487
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
488
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
489 nourl = ['rebuildmeta'] + utility_commands.nourl
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
490 table = {
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
491 'update': update,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
492 'help': help,
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
493 'rebuildmeta': rebuildmeta,
255
246aaefb1cc0 Add a basic incoming command.
Nat Williams <nat.williams@gmail.com>
parents: 253
diff changeset
494 'incoming': incoming,
253
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
495 }
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
496
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
497 table.update(utility_commands.table)
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
498
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
499
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
500 def _helpgen():
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
501 ret = ['hg svn ...', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
502 'subcommands for Subversion integration', '',
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
503 'list of subcommands:', '']
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
504 for name, func in sorted(table.items()):
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
505 short_description = (func.__doc__ or '').splitlines()[0]
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
506 ret.append(" %-10s %s" % (name, short_description))
c3d5c4ae9c7c Work with simple command table instead of decorators.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 247
diff changeset
507 return '\n'.join(ret) + '\n'