def _SyncManifest(self, opt):
    m = self.manifest.manifestProject
    is_new = not m.Exists

    if is_new:
      if not opt.manifest_url:
        print >>sys.stderr, 'fatal: manifest url (-u) is required.'
        sys.exit(1)

      if not opt.quiet:
        print >>sys.stderr, 'Getting manifest ...'
        print >>sys.stderr, '   from %s' % opt.manifest_url
      m._InitGitDir()

    self._ApplyOptions(opt, is_new)
    if opt.manifest_url:
      r = m.GetRemote(m.remote.name)
      r.url = opt.manifest_url
      r.ResetFetch()
      r.Save()

    if opt.reference:
      m.config.SetString('repo.reference', opt.reference)

    if opt.mirror:
      if is_new:
        m.config.SetString('repo.mirror', 'true')
        m.config.ClearCache()
      else:
        print >>sys.stderr, 'fatal: --mirror not supported on existing client'
        sys.exit(1)

    if not m.Sync_NetworkHalf():
      r = m.GetRemote(m.remote.name)
      print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url
      sys.exit(1)

    if is_new and SubmoduleManifest.IsBare(m):
      new = self.GetManifest(reparse=True, type=SubmoduleManifest)
      if m.gitdir != new.manifestProject.gitdir:
        os.rename(m.gitdir, new.manifestProject.gitdir)
        new = self.GetManifest(reparse=True, type=SubmoduleManifest)
      m = new.manifestProject
      self._ApplyOptions(opt, is_new)

    if not is_new:
      # Force the manifest to load if it exists, the old graph
      # may be needed inside of _ReloadManifest().
      #
      self.manifest.projects

    syncbuf = SyncBuffer(m.config)
    m.Sync_LocalHalf(syncbuf)
    syncbuf.Finish()

    if isinstance(self.manifest, XmlManifest):
      self._LinkManifest(opt.manifest_name)
    _ReloadManifest(self)

    self._ApplyOptions(opt, is_new)

    if not self.manifest.InitBranch():
      print >>sys.stderr, 'fatal: cannot create branch in manifest'
      sys.exit(1)
dataset/ETHPy150Open android/tools_repo/subcmds/init.py/Init._SyncManifest/original