Exemple #1
0
def check_patches_reversable(patches):
    """Check to see if the specified patches are reversible.

    Returns True if it is else throws an Error with why it is not reversible.
  """
    large_patches = 0
    for patch in patches:

        # If the patch status is 'None' it could be due to an incompletely uploaded
        # original patch.
        if not patch.status:
            raise exceptions.RevertError(
                'Found a None patch status. The original '
                'patchset may have been incompletely uploaded.')

        # Collect the number of large patches.
        if len(patch.text) > LARGE_PATCH_CHARS_THRESHOLD:
            large_patches += 1

        # Only git patches are supported.
        diff_header = invert_patches.split_header(patch.text)[0]
        if not invert_patches.is_git_diff_header(diff_header):
            raise exceptions.RevertError('Can only invert Git patches.')

    if large_patches > MAX_LARGE_PATCHES_REVERSIBLE:
        raise exceptions.RevertError('The Patchset is too large to invert.')
    return True
def check_patches_reversable(patches):
  """Check to see if the specified patches are reversible.

    Returns True if it is else throws an Error with why it is not reversible.
  """
  large_patches = 0
  for patch in patches:

    # If the patch status is 'None' it could be due to an incompletely uploaded
    # original patch.
    if not patch.status:
      raise exceptions.RevertError('Found a None patch status. The original '
          'patchset may have been incompletely uploaded.')

    # Collect the number of large patches.
    if len(patch.text) > LARGE_PATCH_CHARS_THRESHOLD:
      large_patches += 1

    # Only git patches are supported.
    diff_header = invert_patches.split_header(patch.text)[0]
    if not invert_patches.is_git_diff_header(diff_header):
      raise exceptions.RevertError('Can only invert Git patches.')

  if large_patches > MAX_LARGE_PATCHES_REVERSIBLE:
    raise exceptions.RevertError('The Patchset is too large to invert.')
  return True
Exemple #3
0
def check_patches_reversable(patches):
  """Check to see if the specified patches are reversible.

    Returns True if it is else throws an Error with why it is not reversible.
  """
  large_patches = 0
  for patch in patches:

    # If the patch status is 'None' it could be due to an incompletely uploaded
    # original patch.
    if not patch.status:
      raise exceptions.RevertError('Found a None patch status. The original '
          'patchset may have been incompletely uploaded.')

    # Collect the number of large patches.
    if len(patch.text) > LARGE_PATCH_CHARS_THRESHOLD:
      large_patches += 1

    # Only git patches are supported.
    diff_header = invert_patches.split_header(patch.text)[0]
    if not invert_patches.is_git_diff_header(diff_header):
      raise exceptions.RevertError('Can only invert Git patches.')

    if re.search(r"(?m)^similarity index 100%", diff_header):
      # We cannot invert A+ patches with 100% similarity index because they do
      # not contain the git SHA-1 indexes. Rietveld currently stores only MD5
      # checksums of data in Content, it would require a significant change to
      # support this.
      raise exceptions.RevertError(
          'Unable to inverse \'A +\' patches with 100% similarity indexes.')

  if large_patches > MAX_LARGE_PATCHES_REVERSIBLE:
    raise exceptions.RevertError('The Patchset is too large to invert.')
  return True