changeset 1007:e95f4de8709a

layouts: refactor buildmeta layout reading and writing
author David Schleimer <dschleimer@fb.com>
date Wed, 17 Apr 2013 16:50:44 -0700
parents 7a3b938825cd
children bdc9b21ea8d0
files hgsubversion/layouts/detect.py hgsubversion/svncommands.py
diffstat 2 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/layouts/detect.py
+++ b/hgsubversion/layouts/detect.py
@@ -70,3 +70,18 @@ def layout_from_file(meta_data_dir, ui=N
         if ui:
             ui.setconfig('hgsubversion', 'layout', layout)
     return layout
+
+def layout_from_commit(subdir, revpath):
+    """ Guess what the layout is based existing commit info
+
+    Specifically, this compares the subdir for the repository and the
+    revpath as extracted from the convinfo in the commit.
+
+    """
+
+    if (subdir or '/') == revpath:
+        layout = 'single'
+    else:
+        layout = 'standard'
+
+    return layout
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -12,6 +12,7 @@ from mercurial import node
 from mercurial import util as hgutil
 from mercurial import error
 
+import layouts
 import maps
 import svnwrap
 import svnrepo
@@ -198,11 +199,10 @@ def _buildmeta(ui, repo, args, partial=F
                                             'right location in the repo.')
 
         if layout is None:
-            if (subdir or '/') == revpath:
-                layout = 'single'
-            else:
-                layout = 'standard'
-            write_if_needed(os.path.join(svnmetadir, 'layout'), layout)
+            layout = layouts.detect.layout_from_commit(subdir, revpath)
+            existing_layout = layouts.detect.layout_from_file(svnmetadir)
+            if layout != existing_layout:
+                layouts.persist.layout_to_file(svnmetadir, layout)
         elif layout == 'single':
             assert (subdir or '/') == revpath, ('Possible layout detection'
                                                 ' defect in replay')