# HG changeset patch # User David Schleimer # Date 1366242644 25200 # Node ID e95f4de8709ad93639cd9eaae01e61e3b7ae0104 # Parent 7a3b938825cdf4cf9666e698e1775ad97ce3ef2d layouts: refactor buildmeta layout reading and writing diff --git a/hgsubversion/layouts/detect.py b/hgsubversion/layouts/detect.py --- 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 diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- 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')