# HG changeset patch # User Augie Fackler # Date 1223308906 18000 # Node ID 9eb6bf2be1e74a69a4f2e1ff80f9c02451f07579 # Parent c89f53103502411ca1db5ce0dbc6c2a90c81a225 Fix adding files that require new directories. diff --git a/push_cmd.py b/push_cmd.py --- a/push_cmd.py +++ b/push_cmd.py @@ -14,7 +14,6 @@ import utility_commands def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url, **opts): """Push revisions starting at a specified head back to Subversion. """ - #assert False # safety while the command is partially implemented. hge = hg_delta_editor.HgChangeReceiver(hg_repo_path, ui_=ui) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), @@ -66,14 +65,31 @@ def push_revisions_to_subversion(ui, rep svn_commit_hashes) return 0 +class PrefixMatch(object): + def __init__(self, prefix): + self.p = prefix + + def files(self): + return [] + + def __call__(self, fn): + return fn.startswith(self.p) def commit_from_rev(ui, repo, rev_ctx, hg_editor, svn_url, base_revision): """Build and send a commit from Mercurial to Subversion. """ target_files = [] file_data = {} + svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser()) + parent = rev_ctx.parents()[0] + parent_branch = rev_ctx.parents()[0].branch() + branch_path = 'trunk' + + if parent_branch and parent_branch != 'default': + branch_path = 'branches/%s' % parent_branch + + added_dirs = [] for file in rev_ctx.files(): - parent = rev_ctx.parents()[0] new_data = base_data = '' action = '' if file in rev_ctx: @@ -81,6 +97,15 @@ def commit_from_rev(ui, repo, rev_ctx, h if file not in parent: target_files.append(file) action = 'add' + dirname = '/'.join(file.split('/')[:-1] + ['']) + # check for new directories + if not list(parent.walk(PrefixMatch(dirname))): + # check and see if the dir exists svn-side. + try: + assert svn.list_dir('%s/%s' % (branch_path, dirname)) + except core.SubversionException, e: + # dir must not exist + added_dirs.append(dirname[:-1]) # TODO check for mime-type autoprops here # TODO check for directory adds here else: @@ -94,19 +119,16 @@ def commit_from_rev(ui, repo, rev_ctx, h file_data[file] = base_data, new_data, action # TODO check for directory deletes here - svn = svnwrap.SubversionRepo(svn_url, username=merc_util.getuser()) - parent_branch = rev_ctx.parents()[0].branch() - branch_path = 'trunk' - if parent_branch and parent_branch != 'default': - branch_path = 'branches/%s' % parent_branch new_target_files = ['%s/%s' % (branch_path, f) for f in target_files] for tf, ntf in zip(target_files, new_target_files): if tf in file_data: file_data[ntf] = file_data[tf] del file_data[tf] + added_dirs = ['%s/%s' % (branch_path, f) for f in added_dirs] + new_target_files += added_dirs try: svn.commit(new_target_files, rev_ctx.description(), file_data, - base_revision, set([])) + base_revision, set(added_dirs)) except core.SubversionException, e: if hasattr(e, 'apr_err') and e.apr_err == 160028: raise merc_util.Abort('Base text was out of date, maybe rebase?') diff --git a/svnwrap/svn_swig_wrapper.py b/svnwrap/svn_swig_wrapper.py --- a/svnwrap/svn_swig_wrapper.py +++ b/svnwrap/svn_swig_wrapper.py @@ -256,7 +256,7 @@ class SubversionRepo(object): checksum = [] def driver_cb(parent, path, pool): if path in dirs: - return baton + return editor.add_directory(path, parent, None, -1, pool) base_text, new_text, action = file_data[path] compute_delta = True if action == 'modify':