Example #1
0
def main(args):
  current = current_branch()
  if current == 'HEAD':
    current = None
  old_name_help = 'The old branch to rename.'
  if current:
    old_name_help += ' (default %(default)r)'

  parser = argparse.ArgumentParser()
  parser.add_argument('old_name', nargs=('?' if current else 1),
                      help=old_name_help, default=current)
  parser.add_argument('new_name', help='The new branch name.')

  opts = parser.parse_args(args)

  # when nargs=1, we get a list :(
  if isinstance(opts.old_name, list):
    opts.old_name = opts.old_name[0]

  try:
    run('branch', '-m', opts.old_name, opts.new_name)

    # update the downstreams
    for branch, merge in branch_config_map('merge').items():
      if merge == 'refs/heads/' + opts.old_name:
        # Only care about local branches
        if branch_config(branch, 'remote') == '.':
          set_branch_config(branch, 'merge', 'refs/heads/' + opts.new_name)
  except subprocess2.CalledProcessError as cpe:
    sys.stderr.write(cpe.stderr)
    return 1
  return 0
def main(args):
  current = current_branch()
  if current == 'HEAD':
    current = None
  old_name_help = 'The old branch to rename.'
  if current:
    old_name_help += ' (default %(default)r)'

  parser = argparse.ArgumentParser()
  parser.add_argument('old_name', nargs=('?' if current else 1),
                      help=old_name_help, default=current)
  parser.add_argument('new_name', help='The new branch name.')

  opts = parser.parse_args(args)

  # when nargs=1, we get a list :(
  if isinstance(opts.old_name, list):
    opts.old_name = opts.old_name[0]

  try:
    run('branch', '-m', opts.old_name, opts.new_name)

    # update the downstreams
    for branch, merge in branch_config_map('merge').iteritems():
      if merge == 'refs/heads/' + opts.old_name:
        # Only care about local branches
        if branch_config(branch, 'remote') == '.':
          set_branch_config(branch, 'merge', 'refs/heads/' + opts.new_name)
  except subprocess2.CalledProcessError as cpe:
    sys.stderr.write(cpe.stderr)
    return 1
Example #3
0
def main():
    map_extra = config_list('depot_tools.map_extra')
    fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s'
    log_proc = subprocess2.Popen([
        GIT_EXE, 'log', '--graph', '--branches', '--tags',
        root(), '--color=always', '--date=short', ('--pretty=format:' + fmt)
    ] + map_extra + sys.argv[1:],
                                 stdout=subprocess2.PIPE,
                                 shell=False)

    merge_base_map = branch_config_map('base')
    current = current_branch()
    all_branches = set(branches())
    if current in all_branches:
        all_branches.remove(current)
    all_tags = set(tags())
    try:
        for line in log_proc.stdout.xreadlines():
            if merge_base_map:
                commit = line[line.find(BRIGHT_RED) +
                              len(BRIGHT_RED):line.find('\t')]
                base_for_branches = set()
                for branch, sha in merge_base_map.iteritems():
                    if sha.startswith(commit):
                        base_for_branches.add(branch)
                if base_for_branches:
                    newline = '\r\n' if line.endswith('\r\n') else '\n'
                    line = line.rstrip(newline)
                    line += ''.join(
                        (BRIGHT, WHITE,
                         '    <(%s)' % (', '.join(base_for_branches)), RESET,
                         newline))
                    for b in base_for_branches:
                        del merge_base_map[b]

            start = line.find(GREEN + ' (')
            end = line.find(')', start)
            if start != -1 and end != -1:
                start += len(GREEN) + 2
                branch_list = line[start:end].split(', ')
                branches_str = ''
                if branch_list:
                    colored_branches = []
                    head_marker = ''
                    for b in branch_list:
                        if b == "HEAD":
                            head_marker = BLUEBAK + BRIGHT + '*'
                            continue
                        if b == current:
                            colored_branches.append(CYAN + BRIGHT + b + RESET)
                            current = None
                        elif b in all_branches:
                            colored_branches.append(GREEN + BRIGHT + b + RESET)
                            all_branches.remove(b)
                        elif b in all_tags:
                            colored_branches.append(MAGENTA + BRIGHT + b +
                                                    RESET)
                        elif b.startswith('tag: '):
                            colored_branches.append(MAGENTA + BRIGHT + b[5:] +
                                                    RESET)
                        else:
                            colored_branches.append(RED + b)
                        branches_str = '(%s) ' % (
                            (GREEN + ", ").join(colored_branches) + GREEN)
                    line = "%s%s%s" % (line[:start - 1], branches_str,
                                       line[end + 5:])
                    if head_marker:
                        line = line.replace('*', head_marker, 1)
            sys.stdout.write(line)
    except (IOError, KeyboardInterrupt):
        pass
    finally:
        sys.stderr.close()
        sys.stdout.close()
    return 0
Example #4
0
def main():
  map_extra = config_list('depot_tools.map_extra')
  fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s'
  log_proc = subprocess2.Popen(
    [GIT_EXE, 'log', '--graph', '--branches', '--tags', root(),
     '--color=always', '--date=short', ('--pretty=format:' + fmt)
    ] + map_extra + sys.argv[1:],
    stdout=subprocess2.PIPE,
    shell=False)

  merge_base_map = branch_config_map('base')
  current = current_branch()
  all_branches = set(branches())
  if current in all_branches:
    all_branches.remove(current)
  all_tags = set(tags())
  try:
    for line in log_proc.stdout.xreadlines():
      if merge_base_map:
        commit = line[line.find(BRIGHT_RED)+len(BRIGHT_RED):line.find('\t')]
        base_for_branches = set()
        for branch, sha in merge_base_map.iteritems():
          if sha.startswith(commit):
            base_for_branches.add(branch)
        if base_for_branches:
          newline = '\r\n' if line.endswith('\r\n') else '\n'
          line = line.rstrip(newline)
          line += ''.join(
              (BRIGHT, WHITE, '    <(%s)' % (', '.join(base_for_branches)),
               RESET, newline))
          for b in base_for_branches:
            del merge_base_map[b]

      start = line.find(GREEN+' (')
      end   = line.find(')', start)
      if start != -1 and end != -1:
        start += len(GREEN) + 2
        branch_list = line[start:end].split(', ')
        branches_str = ''
        if branch_list:
          colored_branches = []
          head_marker = ''
          for b in branch_list:
            if b == "HEAD":
              head_marker = BLUEBAK+BRIGHT+'*'
              continue
            if b == current:
              colored_branches.append(CYAN+BRIGHT+b+RESET)
              current = None
            elif b in all_branches:
              colored_branches.append(GREEN+BRIGHT+b+RESET)
              all_branches.remove(b)
            elif b in all_tags:
              colored_branches.append(MAGENTA+BRIGHT+b+RESET)
            elif b.startswith('tag: '):
              colored_branches.append(MAGENTA+BRIGHT+b[5:]+RESET)
            else:
              colored_branches.append(RED+b)
            branches_str = '(%s) ' % ((GREEN+", ").join(colored_branches)+GREEN)
          line = "%s%s%s" % (line[:start-1], branches_str, line[end+5:])
          if head_marker:
            line = line.replace('*', head_marker, 1)
      sys.stdout.write(line)
  except (IOError, KeyboardInterrupt):
    pass
  finally:
    sys.stderr.close()
    sys.stdout.close()
  return 0