comparison push_cmd.py @ 9:9eb6bf2be1e7

Fix adding files that require new directories.
author Augie Fackler <durin42@gmail.com>
date Mon, 06 Oct 2008 11:01:46 -0500
parents 1a5bb173170b
children dfdc078661db
comparison
equal deleted inserted replaced
8:c89f53103502 9:9eb6bf2be1e7
12 @util.register_subcommand('push') 12 @util.register_subcommand('push')
13 @util.register_subcommand('dcommit') # for git expats 13 @util.register_subcommand('dcommit') # for git expats
14 def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url, **opts): 14 def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url, **opts):
15 """Push revisions starting at a specified head back to Subversion. 15 """Push revisions starting at a specified head back to Subversion.
16 """ 16 """
17 #assert False # safety while the command is partially implemented.
18 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, 17 hge = hg_delta_editor.HgChangeReceiver(hg_repo_path,
19 ui_=ui) 18 ui_=ui)
20 svn_commit_hashes = dict(zip(hge.revmap.itervalues(), 19 svn_commit_hashes = dict(zip(hge.revmap.itervalues(),
21 hge.revmap.iterkeys())) 20 hge.revmap.iterkeys()))
22 # Strategy: 21 # Strategy:
64 hge.revmap.iterkeys())) 63 hge.revmap.iterkeys()))
65 outgoing = utility_commands.outgoing_revisions(ui, repo, hge, 64 outgoing = utility_commands.outgoing_revisions(ui, repo, hge,
66 svn_commit_hashes) 65 svn_commit_hashes)
67 return 0 66 return 0
68 67
68 class PrefixMatch(object):
69 def __init__(self, prefix):
70 self.p = prefix
71
72 def files(self):
73 return []
74
75 def __call__(self, fn):
76 return fn.startswith(self.p)
69 77
70 def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision): 78 def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision):
71 """Build and send a commit from Mercurial to Subversion. 79 """Build and send a commit from Mercurial to Subversion.
72 """ 80 """
73 target_files = [] 81 target_files = []
74 file_data = {} 82 file_data = {}
83 svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser())
84 parent = rev_ctx.parents()[0]
85 parent_branch = rev_ctx.parents()[0].branch()
86 branch_path = 'trunk'
87
88 if parent_branch and parent_branch != 'default':
89 branch_path = 'branches/%s' % parent_branch
90
91 added_dirs = []
75 for file in rev_ctx.files(): 92 for file in rev_ctx.files():
76 parent = rev_ctx.parents()[0]
77 new_data = base_data = '' 93 new_data = base_data = ''
78 action = '' 94 action = ''
79 if file in rev_ctx: 95 if file in rev_ctx:
80 new_data = rev_ctx.filectx(file).data() 96 new_data = rev_ctx.filectx(file).data()
81 if file not in parent: 97 if file not in parent:
82 target_files.append(file) 98 target_files.append(file)
83 action = 'add' 99 action = 'add'
100 dirname = '/'.join(file.split('/')[:-1] + [''])
101 # check for new directories
102 if not list(parent.walk(PrefixMatch(dirname))):
103 # check and see if the dir exists svn-side.
104 try:
105 assert svn.list_dir('%s/%s' % (branch_path, dirname))
106 except core.SubversionException, e:
107 # dir must not exist
108 added_dirs.append(dirname[:-1])
84 # TODO check for mime-type autoprops here 109 # TODO check for mime-type autoprops here
85 # TODO check for directory adds here 110 # TODO check for directory adds here
86 else: 111 else:
87 target_files.append(file) 112 target_files.append(file)
88 base_data = parent.filectx(file).data() 113 base_data = parent.filectx(file).data()
92 base_data = parent.filectx(file).data() 117 base_data = parent.filectx(file).data()
93 action = 'delete' 118 action = 'delete'
94 file_data[file] = base_data, new_data, action 119 file_data[file] = base_data, new_data, action
95 120
96 # TODO check for directory deletes here 121 # TODO check for directory deletes here
97 svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser())
98 parent_branch = rev_ctx.parents()[0].branch()
99 branch_path = 'trunk'
100 if parent_branch and parent_branch != 'default':
101 branch_path = 'branches/%s' % parent_branch
102 new_target_files = ['%s/%s' % (branch_path, f) for f in target_files] 122 new_target_files = ['%s/%s' % (branch_path, f) for f in target_files]
103 for tf, ntf in zip(target_files, new_target_files): 123 for tf, ntf in zip(target_files, new_target_files):
104 if tf in file_data: 124 if tf in file_data:
105 file_data[ntf] = file_data[tf] 125 file_data[ntf] = file_data[tf]
106 del file_data[tf] 126 del file_data[tf]
127 added_dirs = ['%s/%s' % (branch_path, f) for f in added_dirs]
128 new_target_files += added_dirs
107 try: 129 try:
108 svn.commit(new_target_files, rev_ctx.description(), file_data, 130 svn.commit(new_target_files, rev_ctx.description(), file_data,
109 base_revision, set([])) 131 base_revision, set(added_dirs))
110 except core.SubversionException, e: 132 except core.SubversionException, e:
111 if hasattr(e, 'apr_err') and e.apr_err == 160028: 133 if hasattr(e, 'apr_err') and e.apr_err == 160028:
112 raise merc_util.Abort('Base text was out of date, maybe rebase?') 134 raise merc_util.Abort('Base text was out of date, maybe rebase?')
113 else: 135 else:
114 raise 136 raise