annotate fetch_command.py @ 120:f508c1fa19a5

hg_delta_editor: do not assume branches are copied from trunk by default Here is what happen in jquery repository: - kelvin-dev branch is created in r1617 with an empty directory for the datePicker plugin - commits are done - datePicker plugin is merged in trunk Before the fix, the converter assumed the initial empty commit had for parent some other commit of trunk, therefore adding all its files, which was wrong. And we ended with 'alignDemo.html' in converted trunk@5946 while it was not in the source revision.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 29 Nov 2008 11:25:01 -0600
parents ea65fe2b0856
children 7e45bcf52b64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 import cStringIO
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 import re
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 import os
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 import shutil
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 import tempfile
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 from mercurial import patch
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 from mercurial import node
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 from mercurial import context
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 from mercurial import revlog
6
1a5bb173170b Fixes for win32 compatibility. Changes suggested by Shun-ichi GOTO, with some alterations by me.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
11 from mercurial import util as merc_util
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 from svn import core
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 from svn import delta
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 import hg_delta_editor
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 import svnwrap
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 import util
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19
63
2e30b59a9c19 Added some coverage pragmas to stop it from trying to cover things we can't test.
Augie Fackler <durin42@gmail.com>
parents: 59
diff changeset
20 def print_your_svn_is_old_message(ui): #pragma: no cover
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 ui.status("In light of that, I'll fall back and do diffs, but it won't do "
11
83ed086ddf72 Add a missing newline.
Augie Fackler <durin42@gmail.com>
parents: 6
diff changeset
22 "as good a job. You should really upgrade your server.\n")
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 @util.register_subcommand('pull')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 def fetch_revisions(ui, svn_url, hg_repo_path, skipto_rev=0, stupid=None,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 tag_locations='tags',
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 **opts):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 """Pull new revisions from Subversion.
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 """
44
85fcac4e2291 Fix an encoding bug that would occur if the local encoding was not utf-8.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
31 old_encoding = merc_util._encoding
85fcac4e2291 Fix an encoding bug that would occur if the local encoding was not utf-8.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
32 merc_util._encoding = 'UTF-8'
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 skipto_rev=int(skipto_rev)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 have_replay = not stupid
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 if have_replay and not callable(delta.svn_txdelta_apply(None, None,
63
2e30b59a9c19 Added some coverage pragmas to stop it from trying to cover things we can't test.
Augie Fackler <durin42@gmail.com>
parents: 59
diff changeset
36 None)[0]): #pragma: no cover
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 ui.status('You are using old Subversion SWIG bindings. Replay will not'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 ' work until you upgrade to 1.5.0 or newer. Falling back to'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 ' a slower method that may be buggier. Please upgrade, or'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 ' contribute a patch to use the ctypes bindings instead'
29
575bd29bc1d8 Fix a missing newline.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
41 ' of SWIG.\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 have_replay = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 initializing_repo = False
6
1a5bb173170b Fixes for win32 compatibility. Changes suggested by Shun-ichi GOTO, with some alterations by me.
Augie Fackler <durin42@gmail.com>
parents: 0
diff changeset
44 svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser())
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 author_host = "@%s" % svn.uuid
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 tag_locations = tag_locations.split(',')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 hg_editor = hg_delta_editor.HgChangeReceiver(hg_repo_path,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 ui_=ui,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 subdir=svn.subdir,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 author_host=author_host,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 tag_locations=tag_locations)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 if os.path.exists(hg_editor.uuid_file):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 uuid = open(hg_editor.uuid_file).read()
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 assert uuid == svn.uuid
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 start = int(open(hg_editor.last_revision_handled_file, 'r').read())
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 else:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 open(hg_editor.uuid_file, 'w').write(svn.uuid)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 open(hg_editor.svn_url_file, 'w').write(svn_url)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 open(hg_editor.last_revision_handled_file, 'w').write(str(0))
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 initializing_repo = True
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 start = skipto_rev
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 # start converting revisions
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 for r in svn.revisions(start=start):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 valid = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 hg_editor.update_branch_tag_map_for_rev(r)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 for p in r.paths:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 if hg_editor._is_path_valid(p):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 valid = True
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 continue
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 if initializing_repo and start > 0:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 assert False, 'This feature not ready yet.'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 if valid:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 # got a 502? Try more than once!
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 tries = 0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 converted = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 while not converted and tries < 3:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 try:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 ui.status('converting %s\n' % r)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 if have_replay:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 try:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 replay_convert_rev(hg_editor, svn, r)
63
2e30b59a9c19 Added some coverage pragmas to stop it from trying to cover things we can't test.
Augie Fackler <durin42@gmail.com>
parents: 59
diff changeset
83 except svnwrap.SubversionRepoCanNotReplay, e: #pragma: no cover
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 ui.status('%s\n' % e.message)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 print_your_svn_is_old_message(ui)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 have_replay = False
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 stupid_svn_server_pull_rev(ui, svn, hg_editor, r)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 else:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 stupid_svn_server_pull_rev(ui, svn, hg_editor, r)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 converted = True
32
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
91 tmpfile = '%s_tmp' % hg_editor.last_revision_handled_file
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
92 fp = open(tmpfile, 'w')
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
93 fp.write(str(r.revnum))
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
94 fp.close()
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
95 merc_util.rename(tmpfile,
d01196ca1e39 Fix non-atomic write of the last_revision_handled_file which was causing
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
96 hg_editor.last_revision_handled_file)
63
2e30b59a9c19 Added some coverage pragmas to stop it from trying to cover things we can't test.
Augie Fackler <durin42@gmail.com>
parents: 59
diff changeset
97 except core.SubversionException, e: #pragma: no cover
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98 if hasattr(e, 'message') and (
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99 'Server sent unexpected return value (502 Bad Gateway)'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 ' in response to PROPFIND') in e.message:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 tries += 1
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 ui.status('Got a 502, retrying (%s)\n' % tries)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 else:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 raise
44
85fcac4e2291 Fix an encoding bug that would occur if the local encoding was not utf-8.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
105 merc_util._encoding = old_encoding
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
108 def cleanup_file_handles(svn, count):
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
109 if count % 50 == 0:
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
110 svn.init_ra_and_client()
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
111
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 def replay_convert_rev(hg_editor, svn, r):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 hg_editor.set_current_rev(r)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114 svn.get_replay(r.revnum, hg_editor)
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
115 i = 1
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 if hg_editor.missing_plaintexts:
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
117 hg_editor.ui.status('Fetching %s files that could not use replay.\n' %
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
118 len(hg_editor.missing_plaintexts))
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 files_to_grab = set()
98
c7ac013cf7fd fetch_command: simplify replay_convert_rev() with svn.list_files()
Patrick Mezard <pmezard@gmail.com>
parents: 97
diff changeset
120 rootpath = svn.subdir and svn.subdir[1:] or ''
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 for p in hg_editor.missing_plaintexts:
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
122 hg_editor.ui.status('.')
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
123 hg_editor.ui.flush()
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 if p[-1] == '/':
98
c7ac013cf7fd fetch_command: simplify replay_convert_rev() with svn.list_files()
Patrick Mezard <pmezard@gmail.com>
parents: 97
diff changeset
125 dirpath = p[len(rootpath):]
101
a3b717e4abf5 Cleanups based on pyflakes output.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
126 files_to_grab.update((dirpath + f for f,k in
112
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 111
diff changeset
127 svn.list_files(dirpath, r.revnum)
e58c2f1de059 Fix a regression in converting repositories with files copied in from outside
Augie Fackler <durin42@gmail.com>
parents: 111
diff changeset
128 if k == 'f'))
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 else:
98
c7ac013cf7fd fetch_command: simplify replay_convert_rev() with svn.list_files()
Patrick Mezard <pmezard@gmail.com>
parents: 97
diff changeset
130 files_to_grab.add(p[len(rootpath):])
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
131 hg_editor.ui.status('\nFetching files...\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 for p in files_to_grab:
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
133 hg_editor.ui.status('.')
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
134 hg_editor.ui.flush()
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
135 cleanup_file_handles(svn, i)
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
136 i += 1
98
c7ac013cf7fd fetch_command: simplify replay_convert_rev() with svn.list_files()
Patrick Mezard <pmezard@gmail.com>
parents: 97
diff changeset
137 data, mode = svn.get_file(p, r.revnum)
97
0d3a2a7cefa3 hg_delta_editor: fix symlink prefix confusion
Patrick Mezard <pmezard@gmail.com>
parents: 90
diff changeset
138 hg_editor.set_file(p, data, 'x' in mode, 'l' in mode)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 hg_editor.missing_plaintexts = set()
38
9ee7ce0505eb Fixes so that I can clone the melange repository successfully. Fixes a bug that
Augie Fackler <durin42@gmail.com>
parents: 33
diff changeset
140 hg_editor.ui.status('\n')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 hg_editor.commit_current_delta()
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 binary_file_re = re.compile(r'''Index: ([^\n]*)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 =*
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 Cannot display: file marked as a binary type.''')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 property_exec_set_re = re.compile(r'''Property changes on: ([^\n]*)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 _*
25
99f8e4b535e9 svn 1.4 and 1.5 have different ideas of diff output for prop changes.
Augie Fackler <durin42@gmail.com>
parents: 11
diff changeset
150 (?:Added|Name): svn:executable
111
5497d1264b4d fetch_command: Fix mis-converted executable when svn:executable was set to the
Augie Fackler <durin42@gmail.com>
parents: 110
diff changeset
151 \+''')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 property_exec_removed_re = re.compile(r'''Property changes on: ([^\n]*)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 _*
25
99f8e4b535e9 svn 1.4 and 1.5 have different ideas of diff output for prop changes.
Augie Fackler <durin42@gmail.com>
parents: 11
diff changeset
155 (?:Deleted|Name): svn:executable
111
5497d1264b4d fetch_command: Fix mis-converted executable when svn:executable was set to the
Augie Fackler <durin42@gmail.com>
parents: 110
diff changeset
156 -''')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 empty_file_patch_wont_make_re = re.compile(r'''Index: ([^\n]*)\n=*\n(?=Index:)''')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 any_file_re = re.compile(r'''^Index: ([^\n]*)\n=*\n''', re.MULTILINE)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 property_special_set_re = re.compile(r'''Property changes on: ([^\n]*)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 _*
25
99f8e4b535e9 svn 1.4 and 1.5 have different ideas of diff output for prop changes.
Augie Fackler <durin42@gmail.com>
parents: 11
diff changeset
164 (?:Added|Name): svn:special
111
5497d1264b4d fetch_command: Fix mis-converted executable when svn:executable was set to the
Augie Fackler <durin42@gmail.com>
parents: 110
diff changeset
165 \+''')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167 property_special_removed_re = re.compile(r'''Property changes on: ([^\n]*)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 _*
25
99f8e4b535e9 svn 1.4 and 1.5 have different ideas of diff output for prop changes.
Augie Fackler <durin42@gmail.com>
parents: 11
diff changeset
169 (?:Deleted|Name): svn:special
111
5497d1264b4d fetch_command: Fix mis-converted executable when svn:executable was set to the
Augie Fackler <durin42@gmail.com>
parents: 110
diff changeset
170 \-''')
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
172 def stupid_diff_branchrev(ui, svn, hg_editor, branch, r, parentctx, tempdir):
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
173 """Extract all 'branch' content at a given revision.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
174
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
175 Return a tuple (files, filectxfn) where 'files' is the list of all files
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
176 in the branch at the given revision, and 'filectxfn' is a memctx compatible
109
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
177 callable to retrieve individual file information. Raise BadPatchApply upon
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
178 error.
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
179 """
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
180 def make_diff_path(b):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
181 if b == None:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
182 return 'trunk'
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
183 return 'branches/' + b
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
184
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
185 parent_rev, br_p = hg_editor.get_parent_svn_branch_and_rev(r.revnum, branch)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
186 diff_path = make_diff_path(branch)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
187 files_touched = set()
109
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
188 try:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
189 if br_p == branch:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
190 # letting patch handle binaries sounded
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
191 # cool, but it breaks patch in sad ways
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
192 d = svn.get_unified_diff(diff_path, r.revnum, deleted=False,
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
193 ignore_type=False)
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
194 else:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
195 d = svn.get_unified_diff(diff_path, r.revnum,
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
196 other_path=make_diff_path(br_p),
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
197 other_rev=parent_rev,
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
198 deleted=True, ignore_type=True)
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
199 if d:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
200 raise BadPatchApply('branch creation with mods')
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
201 except svnwrap.SubversionRepoCanNotDiff:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
202 raise BadPatchApply('subversion diffing code is not supported')
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
203 except core.SubversionException, e:
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
204 if (hasattr(e, 'apr_err') and e.apr_err != 160013):
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
205 raise
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
206 raise BadPatchApply('previous revision does not exist')
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
207 opener = merc_util.opener(tempdir)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
208 for m in binary_file_re.findall(d):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
209 # we have to pull each binary file by hand as a fulltext,
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
210 # which sucks but we've got no choice
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
211 files_touched.add(m)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
212 try:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
213 f = opener(m, 'w')
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
214 f.write(svn.get_file(diff_path+'/'+m, r.revnum)[0])
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
215 f.close()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
216 except IOError:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
217 pass
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
218 d2 = empty_file_patch_wont_make_re.sub('', d)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
219 d2 = property_exec_set_re.sub('', d2)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
220 d2 = property_exec_removed_re.sub('', d2)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
221 for f in any_file_re.findall(d):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
222 if f in files_touched:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
223 # this check is here because modified binary files will get
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
224 # created before here.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
225 continue
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
226 files_touched.add(f)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
227 data = ''
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
228 if f in parentctx:
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
229 data = parentctx[f].data()
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
230 fp = opener(f, 'w')
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
231 fp.write(data)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
232 fp.close()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
233 if d2.strip() and len(re.findall('\n[-+]', d2.strip())) > 0:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
234 old_cwd = os.getcwd()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
235 os.chdir(tempdir)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
236 changed = {}
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
237 try:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
238 patch_st = patch.applydiff(ui, cStringIO.StringIO(d2),
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
239 changed, strip=0)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
240 except patch.PatchError:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
241 # TODO: this happens if the svn server has the wrong mime
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
242 # type stored and doesn't know a file is binary. It would
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
243 # be better to do one file at a time and only do a
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
244 # full fetch on files that had problems.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
245 os.chdir(old_cwd)
109
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
246 raise BadPatchApply('patching failed')
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
247 for x in changed.iterkeys():
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
248 ui.status('M %s\n' % x)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
249 files_touched.add(x)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
250 os.chdir(old_cwd)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
251 # if this patch didn't apply right, fall back to exporting the
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
252 # entire rev.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
253 if patch_st == -1:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
254 for fn in files_touched:
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
255 if 'l' in parentctx.flags(fn):
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
256 # I think this might be an underlying bug in svn -
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
257 # I get diffs of deleted symlinks even though I
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
258 # specifically said no deletes above.
109
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
259 raise BadPatchApply('deleted symlinked prevent patching')
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
260 assert False, ('This should only happen on case-insensitive'
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
261 ' volumes.')
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
262 elif patch_st == 1:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
263 # When converting Django, I saw fuzz on .po files that was
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
264 # causing revisions to end up failing verification. If that
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
265 # can be fixed, maybe this won't ever be reached.
109
460443a96497 fetch_command: only raise BadPatchApply() from stupid_diff_branchrev()
Patrick Mezard <pmezard@gmail.com>
parents: 108
diff changeset
266 raise BadPatchApply('patching succeeded with fuzz')
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
267 else:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
268 ui.status('Not using patch for %s, diff had no hunks.\n' %
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
269 r.revnum)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
270
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
271 # we create the files if they don't exist here because we know
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
272 # that we'll never have diff info for a deleted file, so if the
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
273 # property is set, we should force the file to exist no matter what.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
274 exec_files = {}
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
275 for m in property_exec_removed_re.findall(d):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
276 exec_files[m] = False
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
277 for m in property_exec_set_re.findall(d):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
278 exec_files[m] = True
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
279 for m in exec_files:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
280 files_touched.add(m)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
281 f = os.path.join(tempdir, m)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
282 if not os.path.exists(f):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
283 data = ''
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
284 if m in parentctx:
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
285 data = parentctx[m].data()
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
286 fp = opener(m, 'w')
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
287 fp.write(data)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
288 fp.close()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
289 link_files = {}
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
290 for m in property_special_set_re.findall(d):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
291 # TODO(augie) when a symlink is removed, patching will fail.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
292 # We're seeing that above - there's gotta be a better
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
293 # workaround than just bailing like that.
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
294 path = os.path.join(tempdir, m)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
295 assert os.path.exists(path)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
296 link_path = open(path).read()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
297 link_path = link_path[len('link '):]
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
298 os.remove(path)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
299 link_files[m] = link_path
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
300 files_touched.add(m)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
301
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
302 deleted_files = set()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
303 for p in r.paths:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
304 if p.startswith(diff_path) and r.paths[p].action == 'D':
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
305 p2 = p[len(diff_path)+1:].strip('/')
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
306 if p2 in parentctx:
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
307 deleted_files.add(p2)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
308 continue
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
309 # If this isn't in the parent ctx, it must've been a dir
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
310 deleted_files.update([f for f in parentctx if f.startswith(p2 + '/')])
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
311 files_touched.update(deleted_files)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
312
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
313 copies = getcopies(svn, hg_editor, branch, diff_path, r, files_touched,
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
314 parentctx)
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
315
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
316 def filectxfn(repo, memctx, path):
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
317 if path in deleted_files:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
318 raise IOError()
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
319 if path in link_files:
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
320 return context.memfilectx(path=path, data=link_files[path],
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
321 islink=True, isexec=False,
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
322 copied=False)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
323 data = opener(path).read()
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
324 exe = exec_files.get(path, 'x' in parentctx.flags(path))
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
325 copied = copies.get(path)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
326 return context.memfilectx(path=path, data=data, islink=False,
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
327 isexec=exe, copied=copied)
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
328
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
329 return list(files_touched), filectxfn
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
330
73
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
331 def makecopyfinder(r, branchpath, rootdir):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
332 """Return a function detecting copies.
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
333
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
334 Returned copyfinder(path) returns None if no copy information can
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
335 be found or ((source, sourcerev), sourcepath) where "sourcepath" is the
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
336 copy source path, "sourcerev" the source svn revision and "source" is the
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
337 copy record path causing the copy to occur. If a single file was copied
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
338 "sourcepath" and "source" are the same, while file copies dectected from
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
339 directory copies return the copied source directory in "source".
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
340 """
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
341 # filter copy information for current branch
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
342 branchpath = branchpath + '/'
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
343 fullbranchpath = rootdir + branchpath
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
344 copies = []
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
345 for path, e in r.paths.iteritems():
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
346 if not e.copyfrom_path:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
347 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
348 if not path.startswith(branchpath):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
349 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
350 if not e.copyfrom_path.startswith(fullbranchpath):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
351 # ignore cross branch copies
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
352 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
353 dest = path[len(branchpath):]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
354 source = e.copyfrom_path[len(fullbranchpath):]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
355 copies.append((dest, (source, e.copyfrom_rev)))
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
356
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
357 copies.sort()
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
358 copies.reverse()
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
359 exactcopies = dict(copies)
101
a3b717e4abf5 Cleanups based on pyflakes output.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
360
73
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
361 def finder(path):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
362 if path in exactcopies:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
363 return exactcopies[path], exactcopies[path][0]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
364 # look for parent directory copy, longest first
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
365 for dest, (source, sourcerev) in copies:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
366 dest = dest + '/'
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
367 if not path.startswith(dest):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
368 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
369 sourcepath = source + '/' + path[len(dest):]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
370 return (source, sourcerev), sourcepath
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
371 return None
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
372
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
373 return finder
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
374
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
375 def getcopies(svn, hg_editor, branch, branchpath, r, files, parentctx):
73
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
376 """Return a mapping {dest: source} for every file copied into r.
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
377 """
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
378 if parentctx.node() == revlog.nullid:
73
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
379 return {}
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
380
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
381 # Extract svn copy information, group them by copy source.
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
382 # The idea is to duplicate the replay behaviour where copies are
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
383 # evaluated per copy event (one event for all files in a directory copy,
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
384 # one event for single file copy). We assume that copy events match
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
385 # copy sources in revision info.
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
386 svncopies = {}
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
387 finder = makecopyfinder(r, branchpath, svn.subdir)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
388 for f in files:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
389 copy = finder(f)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
390 if copy:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
391 svncopies.setdefault(copy[0], []).append((f, copy[1]))
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
392 if not svncopies:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
393 return {}
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
394
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
395 # cache changeset contexts and map them to source svn revisions
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
396 ctxs = {}
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
397 def getctx(svnrev):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
398 if svnrev in ctxs:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
399 return ctxs[svnrev]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
400 changeid = hg_editor.get_parent_revision(svnrev + 1, branch)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
401 ctx = None
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
402 if changeid != revlog.nullid:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
403 ctx = hg_editor.repo.changectx(changeid)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
404 ctxs[svnrev] = ctx
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
405 return ctx
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
406
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
407 # check svn copies really make sense in mercurial
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
408 hgcopies = {}
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
409 for (sourcepath, rev), copies in svncopies.iteritems():
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
410 sourcectx = getctx(rev)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
411 if sourcectx is None:
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
412 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
413 sources = [s[1] for s in copies]
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
414 if not hg_editor.aresamefiles(sourcectx, parentctx, sources):
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
415 continue
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
416 hgcopies.update(copies)
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
417 return hgcopies
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
418
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
419 def stupid_fetch_branchrev(svn, hg_editor, branch, branchpath, r, parentctx):
77
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
420 """Extract all 'branch' content at a given revision.
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
421
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
422 Return a tuple (files, filectxfn) where 'files' is the list of all files
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
423 in the branch at the given revision, and 'filectxfn' is a memctx compatible
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
424 callable to retrieve individual file information.
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
425 """
87
b033d74be76b fetch_command: in stupid non-diffy mode, take changed paths in account
Patrick Mezard <pmezard@gmail.com>
parents: 79
diff changeset
426 files = []
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
427 if parentctx.node() == revlog.nullid:
88
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
428 # Initial revision, fetch all files
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
429 for path, kind in svn.list_files(branchpath, r.revnum):
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
430 if kind == 'f':
87
b033d74be76b fetch_command: in stupid non-diffy mode, take changed paths in account
Patrick Mezard <pmezard@gmail.com>
parents: 79
diff changeset
431 files.append(path)
88
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
432 else:
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
433 branchprefix = branchpath + '/'
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
434 for path, e in r.paths.iteritems():
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
435 if not path.startswith(branchprefix):
87
b033d74be76b fetch_command: in stupid non-diffy mode, take changed paths in account
Patrick Mezard <pmezard@gmail.com>
parents: 79
diff changeset
436 continue
88
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
437 kind = svn.checkpath(path, r.revnum)
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
438 path = path[len(branchprefix):]
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
439 if kind == 'f':
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
440 files.append(path)
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
441 elif kind == 'd':
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
442 if e.action == 'M':
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
443 # Ignore property changes for now
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
444 continue
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
445 dirpath = branchprefix + path
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
446 for child, k in svn.list_files(dirpath, r.revnum):
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
447 if k == 'f':
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
448 files.append(path + '/' + child)
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
449 else:
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
450 if path in parentctx:
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
451 files.append(path)
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
452 continue
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
453 # Assume it's a deleted directory
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
454 path = path + '/'
3b60f223893a fetch_command: handle nullid parent in stupid non-diffy mode
Patrick Mezard <pmezard@gmail.com>
parents: 87
diff changeset
455 deleted = [f for f in parentctx if f.startswith(path)]
101
a3b717e4abf5 Cleanups based on pyflakes output.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
456 files += deleted
87
b033d74be76b fetch_command: in stupid non-diffy mode, take changed paths in account
Patrick Mezard <pmezard@gmail.com>
parents: 79
diff changeset
457
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
458 copies = getcopies(svn, hg_editor, branch, branchpath, r, files, parentctx)
101
a3b717e4abf5 Cleanups based on pyflakes output.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
459
77
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
460 def filectxfn(repo, memctx, path):
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
461 data, mode = svn.get_file(branchpath + '/' + path, r.revnum)
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
462 isexec = 'x' in mode
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
463 islink = 'l' in mode
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
464 copied = copies.get(path)
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
465 return context.memfilectx(path=path, data=data, islink=islink,
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
466 isexec=isexec, copied=copied)
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
467
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
468 return files, filectxfn
ed3dd5bf45da fetch_command: bypass export3() and checkout manually
Patrick Mezard <pmezard@gmail.com>
parents: 76
diff changeset
469
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
470 def stupid_svn_server_pull_rev(ui, svn, hg_editor, r):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
471 # this server fails at replay
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
472 branches = hg_editor.branches_in_paths(r.paths)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
473 temp_location = os.path.join(hg_editor.path, '.hg', 'svn', 'temp')
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
474 if not os.path.exists(temp_location):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
475 os.makedirs(temp_location)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
476 for b in branches:
108
de19a13edfa8 fetch_command: extract diff code in a function
Patrick Mezard <pmezard@gmail.com>
parents: 107
diff changeset
477 our_tempdir = tempfile.mkdtemp('svn_fetch_temp', dir=temp_location)
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
478 parentctx = hg_editor.repo[hg_editor.get_parent_revision(r.revnum, b)]
119
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
479 kind = svn.checkpath(branches[b], r.revnum)
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
480 if kind != 'd':
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
481 # Branch does not exist at this revision. Get parent revision and
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
482 # remove everything.
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
483 files_touched = parentctx.manifest().keys()
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
484 def filectxfn(repo, memctx, path):
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
485 raise IOError()
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
486 else:
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
487 try:
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
488 files_touched, filectxfn = stupid_diff_branchrev(
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
489 ui, svn, hg_editor, b, r, parentctx, our_tempdir)
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
490 except BadPatchApply, e:
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
491 # Either this revision or the previous one does not exist.
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
492 ui.status("fetching entire rev: %s.\n" % e.message)
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
493 files_touched, filectxfn = stupid_fetch_branchrev(
ea65fe2b0856 hg_delta_editor: fix update of stray files in branches/
Patrick Mezard <pmezard@gmail.com>
parents: 118
diff changeset
494 svn, hg_editor, b, branches[b], r, parentctx)
73
9c1b53abefcb fetch_command: support svn copy detection in stupid mode
Patrick Mezard <pmezard@gmail.com>
parents: 63
diff changeset
495
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
496 date = r.date.replace('T', ' ').replace('Z', '').split('.')[0]
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
497 date += ' -0000'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
498 extra = {}
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
499 if b:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
500 extra['branch'] = b
59
430af23bef4a Performance fix for branches-from-tags in real replay, which is tied up with
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
501 if '' in files_touched:
430af23bef4a Performance fix for branches-from-tags in real replay, which is tied up with
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
502 files_touched.remove('')
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
503 if parentctx.node() != node.nullid or files_touched:
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
504 # TODO(augie) remove this debug code? Or maybe it's sane to have it.
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
505 for f in files_touched:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
506 if f:
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
507 assert f[0] != '/'
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
508 current_ctx = context.memctx(hg_editor.repo,
110
a4dcffaa6538 fetch_command: pass parent changectx instead of identifier
Patrick Mezard <pmezard@gmail.com>
parents: 109
diff changeset
509 [parentctx.node(), revlog.nullid],
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
510 r.message or '...',
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
511 files_touched,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
512 filectxfn,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
513 '%s%s' % (r.author,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
514 hg_editor.author_host),
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
515 date,
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
516 extra)
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
517 ha = hg_editor.repo.commitctx(current_ctx)
33
a9c15cae50e5 Faster append-only revmap implementation.
Andreas Hartmetz <ahartmetz@gmail.com>
parents: 32
diff changeset
518 hg_editor.add_to_revmap(r.revnum, b, ha)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
519 hg_editor._save_metadata()
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
520 ui.status('committed as %s on branch %s\n' %
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
521 (node.hex(ha), b or 'default'))
90
4c419603d41b fetch_command: create branch temporary directory when we need it
Patrick Mezard <pmezard@gmail.com>
parents: 89
diff changeset
522 if our_tempdir is not None:
4c419603d41b fetch_command: create branch temporary directory when we need it
Patrick Mezard <pmezard@gmail.com>
parents: 89
diff changeset
523 shutil.rmtree(our_tempdir)
0
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
524
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
525
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
526 class BadPatchApply(Exception):
f2636cfed115 Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
527 pass