Пример #1
0
 def __init__(self, path, revision, *args, **kwargs):
     InvalidRevisionFormatError.__init__(
         self,
         path=path,
         revision=revision,
         detail='The SHA1 is too short. Make sure the diff is generated '
                'with `git diff --full-index`.',
         *args, **kwargs)
Пример #2
0
 def __init__(self, path, revision, *args, **kwargs):
     InvalidRevisionFormatError.__init__(
         self,
         path=path,
         revision=revision,
         detail=six.text_type(_('The SHA1 is too short. Make sure the diff '
                                'is generated with `git diff '
                                '--full-index`.')),
         *args, **kwargs)
Пример #3
0
 def __init__(self, path, revision, *args, **kwargs):
     InvalidRevisionFormatError.__init__(
         self,
         path=path,
         revision=revision,
         detail=six.text_type(_('The SHA1 is too short. Make sure the diff '
                                'is generated with `git diff '
                                '--full-index`.')),
         *args, **kwargs)
Пример #4
0
    def file_exists(self, path, revision, **kwargs):
        """Return whether a file exists with the given path and revision.

        Args:
            path (unicode):
                The path of the file within the repository. This must not be
                a full Bazaar repository path.

            revision (unicode):
                The revision to fetch. If a Bazaar revision specifier keyword
                is provided, then it will be used to perform the lookup.
                Otherwise, this is assumed to be a date in the form of
                ``YYYY-MM-DD HH:MM:SS ZZZZ``, the format used in Bazaar diffs.

            **kwargs (dict, unused):
                Unused additional keyword arguments.

        Returns:
            bool:
            ``True`` if the file exists. ``False`` if it does not.

        Raises:
            reviewboard.scmtools.errors.InvalidRevisionFormatError:
                The ``revision`` argument was in a format that's not supported.
        """
        if revision == BZRTool.PRE_CREATION_TIMESTAMP:
            return False

        revspec = self._revspec_from_revision(revision)

        if revspec is None:
            raise InvalidRevisionFormatError(path, revision)

        return self.client.get_file_exists(path=path, revspec=revspec)
Пример #5
0
    def parse_diff_revision(self, file_str, revision_str, *args, **kwargs):
        """Return a parsed filename and revision as represented in a diff.

        This will separate out the filename from the revision (separated by
        a ``#``) and return the results.

        If the revision is ``1``, this will have to query the repository for
        the file's history. This is to work around behavior in older versions
        of Perforce where a revision of ``1`` would be used for newly-created
        files.

        Args:
            file_str (unicode):
                The filename as represented in the diff.

            revision_str (unicode):
                The revision as represented in the diff.

            **args (tuple):
                Unused positional arguments.

            **kwargs (dict):
                Unused keyword arguments.

        Returns:
            tuple:
            A tuple containing two items: The normalized filename string, and
            a :py:class:`~reviewboard.scmtools.core.Revision`.

        Raises:
            reviewboard.scmtools.errors.InvalidRevisionFormatError:
                The ``revision`` was in an invalid format.
        """
        filename, revision = revision_str.rsplit('#', 1)

        try:
            int(revision)
        except ValueError:
            raise InvalidRevisionFormatError(filename, revision)

        # Older versions of Perforce had this lovely idiosyncracy that diffs
        # show revision #1 both for pre-creation and when there's an actual
        # revision. In this case, we need to check if the file already exists
        # in the repository.
        #
        # Newer versions use #0, so it's quicker to check.
        if (revision == '0' or
            (revision == '1' and
             not self.repository.get_file_exists(filename, revision))):
            revision = PRE_CREATION

        return filename, revision