From 75b87c8a5171b26947d0a13d970f09defac736e3 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <sop@google.com>
Date: Fri, 3 Jul 2009 16:24:57 -0700
Subject: [PATCH] Abstract manifest branch creation from init to the manifest
 object

This permits the XML style manifest to use 'default', while other
types can use their own creation strategy for the current branch.

Signed-off-by: Shawn O. Pearce <sop@google.com>
---
 manifest.py     | 3 +++
 manifest_xml.py | 6 ++++++
 subcmds/init.py | 7 +++----
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/manifest.py b/manifest.py
index 0762098b..a2fc9601 100644
--- a/manifest.py
+++ b/manifest.py
@@ -40,5 +40,8 @@ class Manifest(object):
   def projects(self):
     return {}
 
+  def InitBranch(self):
+    pass
+
   def SetMRefs(self, project):
     pass
diff --git a/manifest_xml.py b/manifest_xml.py
index 66cdf3e3..45896be9 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -169,6 +169,12 @@ class XmlManifest(Manifest):
     self._Load()
     return self._default
 
+  def InitBranch(self):
+    m = self.manifestProject
+    if m.CurrentBranch is None:
+      return m.StartBranch('default')
+    return True
+
   def SetMRefs(self, project):
     if self.branch:
       project._InitAnyMRef(R_M + self.branch)
diff --git a/subcmds/init.py b/subcmds/init.py
index ec87d036..0075b0b4 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -130,10 +130,9 @@ to update the working directory files.
     m.Sync_LocalHalf(syncbuf)
     syncbuf.Finish()
 
-    if is_new or m.CurrentBranch is None:
-      if not m.StartBranch('default'):
-        print >>sys.stderr, 'fatal: cannot create default in manifest'
-        sys.exit(1)
+    if not self.manifest.InitBranch():
+      print >>sys.stderr, 'fatal: cannot create branch in manifest'
+      sys.exit(1)
 
   def _LinkManifest(self, name):
     if not name: