Rev 1749: Create branches directory automatically when pushing merged revisions. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Mon Sep 1 02:30:25 BST 2008


At file:///data/jelmer/bzr-svn/trunk/

------------------------------------------------------------
revno: 1749
revision-id: jelmer at samba.org-20080901013013-0r9r7syh1693zb7k
parent: jelmer at samba.org-20080901002056-7m001pqzvfiyd0t0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2008-09-01 03:30:13 +0200
message:
  Create branches directory automatically when pushing merged revisions.
modified:
  NEWS                           news-20061231030336-h9fhq245ie0de8bs-1
  TODO                           todo-20060729211917-2kpobww0zyvvo0j2-1
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  commit.py                      commit.py-20060607190346-qvq128wgfubhhgm2-1
  errors.py                      errors.py-20061226172623-w1sbj8ynpo0eojqp-1
  tags.py                        tags.py-20080822211316-scblu3akdvu0b64c-1
=== modified file 'NEWS'
--- a/NEWS	2008-08-31 23:20:29 +0000
+++ b/NEWS	2008-09-01 01:30:13 +0000
@@ -20,6 +20,9 @@
 
    * "bzr revert" in a Subversion working tree now works.
 
+   * Create branches/ directory automatically if it didn't exist
+     when pushing merged revisions.
+
   BUG FIXES
 
    * Set bzr signature revision property during commit if possible.

=== modified file 'TODO'
--- a/TODO	2008-09-01 00:20:56 +0000
+++ b/TODO	2008-09-01 01:30:13 +0000
@@ -2,12 +2,10 @@
  - implement layout functions, including command
  - add options in commit for create_root, create_prefix
   - if create_root=False: skip _check_dirs_exist
-  - create branches/ dir automatically
  - allow skipping a revision completely - to allow creating branches using "svn cp"
 
 - generate deltas rather than fulltexts when creating file id maps
 - transform file ids in workingtree in svn-upgrade
-- only look for fileprops until the first custom revprop that appears in revhistory and mapping.supports_custom_revprops()
 
 tests:
 - more blackbox tests

=== modified file 'branch.py'
--- a/branch.py	2008-08-31 19:59:08 +0000
+++ b/branch.py	2008-09-01 01:30:13 +0000
@@ -430,7 +430,9 @@
                           len(todo))
                 if push_merged:
                     parent_revids = other_graph.get_parent_map([revid])[revid]
-                    push_ancestors(self.repository, other.repository, self.layout, self.project, parent_revids, other_graph)
+                    push_ancestors(self.repository, other.repository, self.layout, 
+                                   self.project, parent_revids, other_graph,
+                                   create_prefix=True)
                 push(my_graph, self, other.repository, revid)
                 self._clear_cached_state()
         finally:

=== modified file 'commit.py'
--- a/commit.py	2008-08-31 23:40:20 +0000
+++ b/commit.py	2008-09-01 01:30:13 +0000
@@ -402,7 +402,7 @@
 
         if (len(existing_elements) != len(elements) and
             len(existing_elements)+1 != len(elements)):
-            raise MissingPrefix("/".join(elements))
+            raise MissingPrefix("/".join(elements), "/".join(existing_elements))
 
         # Branch already exists and stayed at the same location, open:
         # TODO: What if the branch didn't change but the new revision 
@@ -871,7 +871,8 @@
                     target_branch.set_branch_path(bp)
 
                 if layout.push_merged_revisions(target_branch.project) and len(rev.parent_ids) > 1:
-                    push_ancestors(self.target, self.source, layout, "", rev.parent_ids, graph)
+                    push_ancestors(self.target, self.source, layout, "", rev.parent_ids, graph,
+                                   create_prefix=True)
 
                 target_config = target_branch.get_config()
                 push_revision_tree(graph, target_branch, target_config, 
@@ -890,7 +891,7 @@
         return isinstance(target, SvnRepository)
 
 
-def push_ancestors(target_repo, source_repo, layout, project, parent_revids, graph):
+def push_ancestors(target_repo, source_repo, layout, project, parent_revids, graph, create_prefix=False):
     for parent_revid in parent_revids[1:]:
         if target_repo.has_revision(parent_revid):
             continue
@@ -902,4 +903,43 @@
             rev = source_repo.get_revision(x)
             nick = (rev.properties.get('branch-nick') or "merged").encode("utf-8").replace("/","_")
             rhs_branch_path = layout.get_branch_path(nick, project)
-            push_new(target_repo, rhs_branch_path, source_repo, x)
+            try:
+                push_new(target_repo, rhs_branch_path, source_repo, x)
+            except MissingPrefix, e:
+                if not create_prefix:
+                    raise
+                revprops = {properties.PROP_REVISION_LOG: "Add branches directory."}
+                if target_repo.transport.has_capability("commit-revprops"):
+                    revprops[mapping.SVN_REVPROP_BZR_SKIP] = ""
+                create_branch_prefix(target_repo, revprops, e.path.split("/")[:-1], filter(lambda x: x != "", e.existing_path.split("/")))
+                push_new(target_repo, rhs_branch_path, source_repo, x)
+
+
+def create_branch_prefix(repository, revprops, bp_parts, existing_bp_parts):
+    conn = repository.transport.get_connection()
+    try:
+        ci = conn.get_commit_editor(revprops)
+        try:
+            root = ci.open_root()
+            name = None
+            batons = [root]
+            for p in existing_bp_parts:
+                if name is None:
+                    name = p
+                else:
+                    name += "/" + p
+                batons.append(batons[-1].open_directory(name))
+            for p in bp_parts[len(existing_bp_parts):]:
+                if name is None:
+                    name = p
+                else:
+                    name += "/" + p
+                batons.append(batons[-1].add_directory(name))
+            for baton in reversed(batons):
+                baton.close()
+        except:
+            ci.abort()
+            raise
+        ci.close()
+    finally:
+        repository.transport.add_connection(conn)

=== modified file 'errors.py'
--- a/errors.py	2008-08-31 13:44:01 +0000
+++ b/errors.py	2008-09-01 01:30:13 +0000
@@ -89,9 +89,10 @@
 class MissingPrefix(BzrError):
     _fmt = """Prefix missing for %(path)s; please create it before pushing. """
 
-    def __init__(self, path):
+    def __init__(self, path, existing_path):
         BzrError.__init__(self)
         self.path = path
+        self.existing_path = existing_path
 
 
 class RaRequestFailed(BzrError):

=== modified file 'tags.py'
--- a/tags.py	2008-08-30 21:11:14 +0000
+++ b/tags.py	2008-09-01 01:30:13 +0000
@@ -37,33 +37,8 @@
         if existing_bp_parts == bp_parts:
             self._parent_exists = True
             return
-        conn = self.repository.transport.get_connection()
-        try:
-            ci = conn.get_commit_editor(self._revprops("Add tags base directory."))
-            try:
-                root = ci.open_root()
-                name = None
-                batons = [root]
-                for p in existing_bp_parts:
-                    if name is None:
-                        name = p
-                    else:
-                        name += "/" + p
-                    batons.append(batons[-1].open_directory(name))
-                for p in bp_parts[len(existing_bp_parts):]:
-                    if name is None:
-                        name = p
-                    else:
-                        name += "/" + p
-                    batons.append(batons[-1].add_directory(name))
-                for baton in reversed(batons):
-                    baton.close()
-            except:
-                ci.abort()
-                raise
-            ci.close()
-        finally:
-            self.repository.transport.add_connection(conn)
+        commit.create_branch_prefix(self.repository, self._revprops("Add tags base directory."),
+                             bp_parts, existing_bp_parts)
         self._parent_exists = True
 
     def set_tag(self, tag_name, tag_target):




More information about the bazaar-commits mailing list