Exemplo n.º 1
0
    def _MultipleBranches(self, opt, pending):
        projects = {}
        branches = {}

        script = []
        script.append('# Uncomment the branches to upload:')
        for project, avail in pending:
            script.append('#')
            script.append('# project %s/:' % project.relpath)

            b = {}
            for branch in avail:
                name = branch.name
                date = branch.date
                list = branch.commits

                if b:
                    script.append('#')
                script.append(
                    '#  branch %s (%2d commit%s, %s):' %
                    (name, len(list), len(list) != 1 and 's' or '', date))
                for commit in list:
                    script.append('#         %s' % commit)
                b[name] = branch

            projects[project.relpath] = project
            branches[project.name] = b
        script.append('')

        script = Editor.EditString("\n".join(script)).split("\n")

        project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$')
        branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*')

        project = None
        todo = []

        for line in script:
            m = project_re.match(line)
            if m:
                name = m.group(1)
                project = projects.get(name)
                if not project:
                    _die('project %s not available for upload', name)
                continue

            m = branch_re.match(line)
            if m:
                name = m.group(1)
                if not project:
                    _die('project for branch %s not in script', name)
                branch = branches[project.name].get(name)
                if not branch:
                    _die('branch %s not in %s', name, project.relpath)
                todo.append(branch)
        if not todo:
            _die("nothing uncommented for upload")

        self._UploadAndReport(opt, todo)
Exemplo n.º 2
0
    def _ReplaceBranch(self, project, people):
        branch = project.CurrentBranch
        if not branch:
            print >> sys.stdout, "no branches ready for upload"
            return
        branch = project.GetUploadableBranch(branch)
        if not branch:
            print >> sys.stdout, "no branches ready for upload"
            return

        script = []
        script.append('# Replacing from branch %s' % branch.name)

        if len(branch.commits) == 1:
            change = self._FindGerritChange(branch)
            script.append('[%-6s] %s' % (change, branch.commits[0]))
        else:
            for commit in branch.commits:
                script.append('[      ] %s' % commit)

        script.append('')
        script.append(
            '# Insert change numbers in the brackets to add a new patch set.')
        script.append(
            '# To create a new change record, leave the brackets empty.')

        script = Editor.EditString("\n".join(script)).split("\n")

        change_re = re.compile(r'^\[\s*(\d{1,})\s*\]\s*([0-9a-f]{1,}) .*$')
        to_replace = dict()
        full_hashes = branch.unabbrev_commits

        for line in script:
            m = change_re.match(line)
            if m:
                c = m.group(1)
                f = m.group(2)
                try:
                    f = full_hashes[f]
                except KeyError:
                    print 'fh = %s' % full_hashes
                    print >> sys.stderr, "error: commit %s not found" % f
                    sys.exit(1)
                if c in to_replace:
                    print >>sys.stderr,\
                      "error: change %s cannot accept multiple commits" % c
                    sys.exit(1)
                to_replace[c] = f

        if not to_replace:
            print >> sys.stderr, "error: no replacements specified"
            print >> sys.stderr, "       use 'repo upload' without --replace"
            sys.exit(1)

        branch.replace_changes = to_replace
        self._UploadAndReport([branch], people)
Exemplo n.º 3
0
    def _MultipleBranches(self, opt, pending, people):
        projects = {}
        branches = {}

        script = []
        script.append('# Uncomment the branches to upload:')
        for project, avail in pending:
            script.append('#')
            script.append('# project %s/:' % project.relpath)

            b = {}
            for branch in avail:
                if branch is None:
                    continue
                name = branch.name
                date = branch.date
                commit_list = branch.commits

                if b:
                    script.append('#')
                destination = opt.dest_branch or project.dest_branch or project.revisionExpr
                script.append(
                    '#  branch %s (%2d commit%s, %s) to remote branch %s:' %
                    (name, len(commit_list), len(commit_list) != 1 and 's'
                     or '', date, destination))
                for commit in commit_list:
                    script.append('#         %s' % commit)
                b[name] = branch

            projects[project.relpath] = project
            branches[project.name] = b
        script.append('')

        script = Editor.EditString("\n".join(script)).split("\n")

        project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$')
        branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*')

        project = None
        todo = []

        for line in script:
            m = project_re.match(line)
            if m:
                name = m.group(1)
                project = projects.get(name)
                if not project:
                    _die('project %s not available for upload', name)
                continue

            m = branch_re.match(line)
            if m:
                name = m.group(1)
                if not project:
                    _die('project for branch %s not in script', name)
                branch = branches[project.name].get(name)
                if not branch:
                    _die('branch %s not in %s', name, project.relpath)
                todo.append(branch)
        if not todo:
            _die("nothing uncommented for upload")

        many_commits = False
        for branch in todo:
            if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
                many_commits = True
                break
        if many_commits:
            if not _ConfirmManyUploads(multiple_branches=True):
                _die("upload aborted by user")

        self._UploadAndReport(opt, todo, people)
Exemplo n.º 4
0
 def test_cat_editor(self):
   """Check behavior when editor is `cat`."""
   self.setEditor('cat')
   self.assertEqual('foo', Editor.EditString('foo'))
Exemplo n.º 5
0
 def test_no_editor(self):
   """Check behavior when no editor is available."""
   self.setEditor(':')
   self.assertEqual('foo', Editor.EditString('foo'))
Exemplo n.º 6
0
 def test_cat_editor(self):
     """Check behavior when editor is `cat`."""
     self.setEditor("cat")
     self.assertEqual("foo", Editor.EditString("foo"))
Exemplo n.º 7
0
 def test_no_editor(self):
     """Check behavior when no editor is available."""
     self.setEditor(":")
     self.assertEqual("foo", Editor.EditString("foo"))
Exemplo n.º 8
0
  def _MultipleBranches(self, opt, pending, people):
    projects = {}
    branches = {}

    script = []
    script.append('# Uncomment the branches to upload:')
    for project, avail in pending:
      script.append('#')
      script.append('# project %s/:' % project.relpath)

      b = {}
      for branch in avail:
        if branch is None:
          continue
        name = branch.name
        date = branch.date
        commit_list = branch.commits

        if b:
          script.append('#')
        # TODO: The destination branch name is calculated twice in this file
        #       and again in project.py.  This is not DRY.  Further, the
        #       calculations are different.  The value calculated here is merely
        #       used in a message.  The project.py value is actually used in a
        #       git command and is therefore probably more reliable.
        push_branch = None if self.gerrit else name
        destination = opt.dest_branch or push_branch or project.dest_branch or project.revisionExpr
        script.append('#  branch %s (%2d commit%s, %s) to remote branch %s:' % (
                      name,
                      len(commit_list),
                      len(commit_list) != 1 and 's' or '',
                      date,
                      destination))
        for commit in commit_list:
          script.append('#         %s' % commit)
        b[name] = branch

      projects[project.relpath] = project
      branches[project.name] = b
    script.append('')

    script = [ x.encode('utf-8')
             if issubclass(type(x), unicode)
             else x
             for x in script ]

    script = Editor.EditString("\n".join(script)).split("\n")

    project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$')
    branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*')

    project = None
    todo = []

    for line in script:
      m = project_re.match(line)
      if m:
        name = m.group(1)
        project = projects.get(name)
        if not project:
          _die('project %s not available for upload', name)
        continue

      m = branch_re.match(line)
      if m:
        name = m.group(1)
        if not project:
          _die('project for branch %s not in script', name)
        branch = branches[project.name].get(name)
        if not branch:
          _die('branch %s not in %s', name, project.relpath)
        todo.append(branch)
    if not todo:
      _die("nothing uncommented for upload")

    many_commits = False
    for branch in todo:
      if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
        many_commits = True
        break
    if many_commits:
      if not _ConfirmManyUploads(multiple_branches=True):
        _die("upload aborted by user")

    self._UploadAndReport(opt, todo, people)