Beispiel #1
0
def cache_diff_hunks(oldrev, newrev):
    def parse_start_length(s):
        # Chop the '-' or '+'.
        s = s[1:]
        # Length is optional (defaults to 1).
        try:
            start, length = s.split(',')
        except ValueError:
            start = s
            length = 1
        return int(start), int(length)

    try:
        return diff_hunks_cache[(oldrev, newrev)]
    except KeyError:
        pass

    # Use -U0 to get the smallest possible hunks.
    diff = git_common.diff(oldrev, newrev, '-U0')

    # Get all the hunks.
    hunks = []
    for line in diff.split('\n'):
        if not line.startswith('@@'):
            continue
        ranges = line.split(' ', 3)[1:3]
        ranges = tuple(parse_start_length(r) for r in ranges)
        hunks.append(ranges)

    diff_hunks_cache[(oldrev, newrev)] = hunks
    return hunks
def cache_diff_hunks(oldrev, newrev):
  def parse_start_length(s):
    # Chop the '-' or '+'.
    s = s[1:]
    # Length is optional (defaults to 1).
    try:
      start, length = s.split(',')
    except ValueError:
      start = s
      length = 1
    return int(start), int(length)

  try:
    return diff_hunks_cache[(oldrev, newrev)]
  except KeyError:
    pass

  # Use -U0 to get the smallest possible hunks.
  diff = git_common.diff(oldrev, newrev, '-U0')

  # Get all the hunks.
  hunks = []
  for line in diff.split('\n'):
    if not line.startswith('@@'):
      continue
    ranges = line.split(' ', 3)[1:3]
    ranges = tuple(parse_start_length(r) for r in ranges)
    hunks.append(ranges)

  diff_hunks_cache[(oldrev, newrev)] = hunks
  return hunks