Added tag v4.14.1 for changeset a47eeac5dfa4
Added tag v4.14.1 for changeset a47eeac5dfa4

File last commit:

r3124:ddd1ae7b default
r3205:fd4b2bf5 stable
Show More
base.py
1755 lines | 55.5 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2014-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Base module for all VCS systems
"""
import collections
import datetime
path-permissions: Path-based permissions for mercurial
r2619 import fnmatch
project: added all source files and assets
r1 import itertools
import logging
import os
path-permissions: Path-based permissions for mercurial
r2619 import re
project: added all source files and assets
r1 import time
import warnings
shadow-repos: use safer way to destroy shadow repositories....
r2777 import shutil
project: added all source files and assets
r1
from zope.cachedescriptors.property import Lazy as LazyProperty
from rhodecode.lib.utils2 import safe_str, safe_unicode
from rhodecode.lib.vcs import connection
from rhodecode.lib.vcs.utils import author_name, author_email
from rhodecode.lib.vcs.conf import settings
from rhodecode.lib.vcs.exceptions import (
CommitError, EmptyRepositoryError, NodeAlreadyAddedError,
NodeAlreadyChangedError, NodeAlreadyExistsError, NodeAlreadyRemovedError,
NodeDoesNotExistError, NodeNotChangedError, VCSError,
ImproperArchiveTypeError, BranchDoesNotExistError, CommitDoesNotExistError,
RepositoryError)
log = logging.getLogger(__name__)
FILEMODE_DEFAULT = 0100644
FILEMODE_EXECUTABLE = 0100755
Reference = collections.namedtuple('Reference', ('type', 'name', 'commit_id'))
MergeResponse = collections.namedtuple(
'MergeResponse',
Martin Bornhold
vcs: Return merge reference in merge response....
r1051 ('possible', 'executed', 'merge_ref', 'failure_reason'))
project: added all source files and assets
r1
class MergeFailureReason(object):
"""
Enumeration with all the reasons why the server side merge could fail.
DO NOT change the number of the reasons, as they may be stored in the
database.
Changing the name of a reason is acceptable and encouraged to deprecate old
reasons.
"""
# Everything went well.
NONE = 0
# An unexpected exception was raised. Check the logs for more details.
UNKNOWN = 1
# The merge was not successful, there are conflicts.
MERGE_FAILED = 2
# The merge succeeded but we could not push it to the target repository.
PUSH_FAILED = 3
# The specified target is not a head in the target repository.
TARGET_IS_NOT_HEAD = 4
# The source repository contains more branches than the target. Pushing
# the merge will create additional branches in the target.
HG_SOURCE_HAS_MORE_BRANCHES = 5
# The target reference has multiple heads. That does not allow to correctly
# identify the target location. This could only happen for mercurial
# branches.
HG_TARGET_HAS_MULTIPLE_HEADS = 6
# The target repository is locked
TARGET_IS_LOCKED = 7
Martin Bornhold
vcs: Deprecate generic missing commit merge error reason....
r1081 # Deprecated, use MISSING_TARGET_REF or MISSING_SOURCE_REF instead.
project: added all source files and assets
r1 # A involved commit could not be found.
Martin Bornhold
vcs: Deprecate generic missing commit merge error reason....
r1081 _DEPRECATED_MISSING_COMMIT = 8
project: added all source files and assets
r1
Martin Bornhold
vcs: Add merge failure reasons for missing target ref and missing source ref.
r1067 # The target repo reference is missing.
MISSING_TARGET_REF = 9
# The source repo reference is missing.
MISSING_SOURCE_REF = 10
Martin Bornhold
subrepo: Add merge failure reason code ad message for subrepo merge conflicts.
r1106 # The merge was not successful, there are conflicts related to sub
# repositories.
SUBREPO_MERGE_FAILED = 11
project: added all source files and assets
r1
Martin Bornhold
vcs: Add enumeration for pull request update failure reasons.
r1069 class UpdateFailureReason(object):
"""
Enumeration with all the reasons why the pull request update could fail.
DO NOT change the number of the reasons, as they may be stored in the
database.
Changing the name of a reason is acceptable and encouraged to deprecate old
reasons.
"""
# Everything went well.
NONE = 0
# An unexpected exception was raised. Check the logs for more details.
UNKNOWN = 1
# The pull request is up to date.
NO_CHANGE = 2
# The pull request has a reference type that is not supported for update.
pull-request: fixed typo in wrong ref type error, and added which...
r1687 WRONG_REF_TYPE = 3
Martin Bornhold
vcs: Add enumeration for pull request update failure reasons.
r1069
# Update failed because the target reference is missing.
MISSING_TARGET_REF = 4
# Update failed because the source reference is missing.
MISSING_SOURCE_REF = 5
project: added all source files and assets
r1 class BaseRepository(object):
"""
Base Repository for final backends
.. attribute:: DEFAULT_BRANCH_NAME
name of default branch (i.e. "trunk" for svn, "master" for git etc.
.. attribute:: commit_ids
list of all available commit ids, in ascending order
.. attribute:: path
absolute path to the repository
.. attribute:: bookmarks
Mapping from name to :term:`Commit ID` of the bookmark. Empty in case
there are no bookmarks or the backend implementation does not support
bookmarks.
.. attribute:: tags
Mapping from name to :term:`Commit ID` of the tag.
"""
DEFAULT_BRANCH_NAME = None
DEFAULT_CONTACT = u"Unknown"
DEFAULT_DESCRIPTION = u"unknown"
EMPTY_COMMIT_ID = '0' * 40
path = None
def __init__(self, repo_path, config=None, create=False, **kwargs):
"""
Initializes repository. Raises RepositoryError if repository could
not be find at the given ``repo_path`` or directory at ``repo_path``
exists and ``create`` is set to True.
:param repo_path: local path of the repository
:param config: repository configuration
:param create=False: if set to True, would try to create repository.
:param src_url=None: if set, should be proper url from which repository
would be cloned; requires ``create`` parameter to be set to True -
raises RepositoryError if src_url is set and create evaluates to
False
"""
raise NotImplementedError
def __repr__(self):
return '<%s at %s>' % (self.__class__.__name__, self.path)
def __len__(self):
return self.count()
def __eq__(self, other):
same_instance = isinstance(other, self.__class__)
return same_instance and other.path == self.path
def __ne__(self, other):
return not self.__eq__(other)
diff-caches: show count and size in caches view per repository.
r2687 def get_create_shadow_cache_pr_path(self, db_repo):
path = db_repo.cached_diffs_dir
Bartłomiej Wołyńczyk
caching: add option to cache diffs for commits and pull requests....
r2685 if not os.path.exists(path):
os.makedirs(path, 0755)
return path
mercurial: fix new 4.4.X code change that does strict requirement checks....
r2518 @classmethod
def get_default_config(cls, default=None):
config = Config()
if default and isinstance(default, list):
for section, key, val in default:
config.set(section, key, val)
return config
project: added all source files and assets
r1 @LazyProperty
caches: make gevent curl connection cache friendly....
r2946 def _remote(self):
raise NotImplementedError
@LazyProperty
project: added all source files and assets
r1 def EMPTY_COMMIT(self):
return EmptyCommit(self.EMPTY_COMMIT_ID)
@LazyProperty
def alias(self):
for k, v in settings.BACKENDS.items():
if v.split('.')[-1] == str(self.__class__.__name__):
return k
@LazyProperty
def name(self):
return safe_unicode(os.path.basename(self.path))
@LazyProperty
def description(self):
raise NotImplementedError
def refs(self):
"""
returns a `dict` with branches, bookmarks, tags, and closed_branches
for this repository
"""
api: implemente missing get_repo_refs api backend. Fixes #4677
r1243 return dict(
branches=self.branches,
branches_closed=self.branches_closed,
tags=self.tags,
bookmarks=self.bookmarks
)
project: added all source files and assets
r1
@LazyProperty
def branches(self):
"""
A `dict` which maps branch names to commit ids.
"""
raise NotImplementedError
@LazyProperty
vcs: use proper attributes/inits on base and child classes.
r2617 def branches_closed(self):
"""
A `dict` which maps tags names to commit ids.
"""
raise NotImplementedError
@LazyProperty
def bookmarks(self):
"""
A `dict` which maps tags names to commit ids.
"""
raise NotImplementedError
@LazyProperty
api: implemente missing get_repo_refs api backend. Fixes #4677
r1243 def tags(self):
"""
A `dict` which maps tags names to commit ids.
"""
raise NotImplementedError
@LazyProperty
project: added all source files and assets
r1 def size(self):
"""
Returns combined size in bytes for all repository files
"""
tip = self.get_commit()
return tip.size
def size_at_commit(self, commit_id):
commit = self.get_commit(commit_id)
return commit.size
def is_empty(self):
return not bool(self.commit_ids)
@staticmethod
def check_url(url, config):
"""
Function will check given url and try to verify if it's a valid
link.
"""
raise NotImplementedError
@staticmethod
def is_valid_repository(path):
"""
Check if given `path` contains a valid repository of this backend
"""
raise NotImplementedError
# ==========================================================================
# COMMITS
# ==========================================================================
def get_commit(self, commit_id=None, commit_idx=None, pre_load=None):
"""
Returns instance of `BaseCommit` class. If `commit_id` and `commit_idx`
are both None, most recent commit is returned.
:param pre_load: Optional. List of commit attributes to load.
:raises ``EmptyRepositoryError``: if there are no commits
"""
raise NotImplementedError
def __iter__(self):
for commit_id in self.commit_ids:
yield self.get_commit(commit_id=commit_id)
def get_commits(
self, start_id=None, end_id=None, start_date=None, end_date=None,
commits: hide evolve commits. Fixes #5392
r2144 branch_name=None, show_hidden=False, pre_load=None):
project: added all source files and assets
r1 """
Returns iterator of `BaseCommit` objects from start to end
not inclusive. This should behave just like a list, ie. end is not
inclusive.
:param start_id: None or str, must be a valid commit id
:param end_id: None or str, must be a valid commit id
:param start_date:
:param end_date:
:param branch_name:
commits: hide evolve commits. Fixes #5392
r2144 :param show_hidden:
project: added all source files and assets
r1 :param pre_load:
"""
raise NotImplementedError
def __getitem__(self, key):
"""
Allows index based access to the commit objects of this repository.
"""
pre_load = ["author", "branch", "date", "message", "parents"]
if isinstance(key, slice):
return self._get_range(key, pre_load)
return self.get_commit(commit_idx=key, pre_load=pre_load)
def _get_range(self, slice_obj, pre_load):
for commit_id in self.commit_ids.__getitem__(slice_obj):
yield self.get_commit(commit_id=commit_id, pre_load=pre_load)
def count(self):
return len(self.commit_ids)
def tag(self, name, user, commit_id=None, message=None, date=None, **opts):
"""
Creates and returns a tag for the given ``commit_id``.
:param name: name for new tag
:param user: full username, i.e.: "Joe Doe <joe.doe@example.com>"
:param commit_id: commit id for which new tag would be created
:param message: message of the tag's commit
:param date: date of tag's commit
:raises TagAlreadyExistError: if tag with same name already exists
"""
raise NotImplementedError
def remove_tag(self, name, user, message=None, date=None):
"""
Removes tag with the given ``name``.
:param name: name of the tag to be removed
:param user: full username, i.e.: "Joe Doe <joe.doe@example.com>"
:param message: message of the tag's removal commit
:param date: date of tag's removal commit
:raises TagDoesNotExistError: if tag with given name does not exists
"""
raise NotImplementedError
def get_diff(
self, commit1, commit2, path=None, ignore_whitespace=False,
context=3, path1=None):
"""
Returns (git like) *diff*, as plain text. Shows changes introduced by
`commit2` since `commit1`.
:param commit1: Entry point from which diff is shown. Can be
``self.EMPTY_COMMIT`` - in this case, patch showing all
the changes since empty state of the repository until `commit2`
:param commit2: Until which commit changes should be shown.
:param path: Can be set to a path of a file to create a diff of that
file. If `path1` is also set, this value is only associated to
`commit2`.
:param ignore_whitespace: If set to ``True``, would not show whitespace
changes. Defaults to ``False``.
:param context: How many lines before/after changed lines should be
shown. Defaults to ``3``.
:param path1: Can be set to a path to associate with `commit1`. This
parameter works only for backends which support diff generation for
different paths. Other backends will raise a `ValueError` if `path1`
is set and has a different value than `path`.
diffs: compare overhaul....
r1259 :param file_path: filter this diff by given path pattern
project: added all source files and assets
r1 """
raise NotImplementedError
def strip(self, commit_id, branch=None):
"""
Strip given commit_id from the repository
"""
raise NotImplementedError
def get_common_ancestor(self, commit_id1, commit_id2, repo2):
"""
Return a latest common ancestor commit if one exists for this repo
`commit_id1` vs `commit_id2` from `repo2`.
:param commit_id1: Commit it from this repository to use as a
target for the comparison.
:param commit_id2: Source commit id to use for comparison.
:param repo2: Source repository to use for comparison.
"""
raise NotImplementedError
def compare(self, commit_id1, commit_id2, repo2, merge, pre_load=None):
"""
Compare this repository's revision `commit_id1` with `commit_id2`.
Returns a tuple(commits, ancestor) that would be merged from
`commit_id2`. Doing a normal compare (``merge=False``), ``None``
will be returned as ancestor.
:param commit_id1: Commit it from this repository to use as a
target for the comparison.
:param commit_id2: Source commit id to use for comparison.
:param repo2: Source repository to use for comparison.
:param merge: If set to ``True`` will do a merge compare which also
returns the common ancestor.
:param pre_load: Optional. List of commit attributes to load.
"""
raise NotImplementedError
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 def merge(self, repo_id, workspace_id, target_ref, source_repo, source_ref,
Martin Bornhold
settings: Add argument to select rebase as merge strategy.
r360 user_name='', user_email='', message='', dry_run=False,
Mathieu Cantin
mercurial: Add option to close a branch before merging
r2055 use_rebase=False, close_branch=False):
project: added all source files and assets
r1 """
Merge the revisions specified in `source_ref` from `source_repo`
onto the `target_ref` of this repository.
`source_ref` and `target_ref` are named tupls with the following
fields `type`, `name` and `commit_id`.
Returns a MergeResponse named tuple with the following fields
'possible', 'executed', 'source_commit', 'target_commit',
'merge_commit'.
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 :param repo_id: `repo_id` target repo id.
:param workspace_id: `workspace_id` unique identifier.
project: added all source files and assets
r1 :param target_ref: `target_ref` points to the commit on top of which
the `source_ref` should be merged.
:param source_repo: The repository that contains the commits to be
merged.
:param source_ref: `source_ref` points to the topmost commit from
the `source_repo` which should be merged.
:param user_name: Merge commit `user_name`.
:param user_email: Merge commit `user_email`.
:param message: Merge commit `message`.
:param dry_run: If `True` the merge will not take place.
Martin Bornhold
settings: Add argument to select rebase as merge strategy.
r360 :param use_rebase: If `True` commits from the source will be rebased
on top of the target instead of being merged.
Mathieu Cantin
mercurial: Add option to close a branch before merging
r2055 :param close_branch: If `True` branch will be close before merging it
project: added all source files and assets
r1 """
if dry_run:
vcs: use a real two part name for merge operation....
r3040 message = message or settings.MERGE_DRY_RUN_MESSAGE
user_email = user_email or settings.MERGE_DRY_RUN_EMAIL
user_name = user_name or settings.MERGE_DRY_RUN_USER
project: added all source files and assets
r1 else:
if not user_name:
raise ValueError('user_name cannot be empty')
if not user_email:
raise ValueError('user_email cannot be empty')
if not message:
raise ValueError('message cannot be empty')
try:
return self._merge_repo(
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 repo_id, workspace_id, target_ref, source_repo,
Martin Bornhold
settings: Add argument to select rebase as merge strategy.
r360 source_ref, message, user_name, user_email, dry_run=dry_run,
Mathieu Cantin
mercurial: Add option to close a branch before merging
r2055 use_rebase=use_rebase, close_branch=close_branch)
project: added all source files and assets
r1 except RepositoryError:
hg: Include state of dry_run in merge failure logging.
r147 log.exception(
'Unexpected failure when running merge, dry-run=%s',
dry_run)
project: added all source files and assets
r1 return MergeResponse(
False, False, None, MergeFailureReason.UNKNOWN)
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 def _merge_repo(self, repo_id, workspace_id, target_ref,
project: added all source files and assets
r1 source_repo, source_ref, merge_message,
Mathieu Cantin
mercurial: Add option to close a branch before merging
r2055 merger_name, merger_email, dry_run=False,
use_rebase=False, close_branch=False):
project: added all source files and assets
r1 """Internal implementation of merge."""
raise NotImplementedError
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 def _maybe_prepare_merge_workspace(
self, repo_id, workspace_id, target_ref, source_ref):
project: added all source files and assets
r1 """
Create the merge workspace.
:param workspace_id: `workspace_id` unique identifier.
"""
raise NotImplementedError
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 def _get_legacy_shadow_repository_path(self, workspace_id):
"""
Legacy version that was used before. We still need it for
backward compat
"""
return os.path.join(
os.path.dirname(self.path),
'.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id))
shadow-repos: use safer way to destroy shadow repositories....
r2777
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 def _get_shadow_repository_path(self, repo_id, workspace_id):
# The name of the shadow repository must start with '.', so it is
# skipped by 'rhodecode.lib.utils.get_filesystem_repos'.
legacy_repository_path = self._get_legacy_shadow_repository_path(workspace_id)
if os.path.exists(legacy_repository_path):
return legacy_repository_path
else:
return os.path.join(
os.path.dirname(self.path),
'.__shadow_repo_%s_%s' % (repo_id, workspace_id))
def cleanup_merge_workspace(self, repo_id, workspace_id):
project: added all source files and assets
r1 """
Remove merge workspace.
This function MUST not fail in case there is no workspace associated to
the given `workspace_id`.
:param workspace_id: `workspace_id` unique identifier.
"""
shadow-repos: use numeric repo id for creation of shadow repos....
r2810 shadow_repository_path = self._get_shadow_repository_path(repo_id, workspace_id)
shadow-repos: use safer way to destroy shadow repositories....
r2777 shadow_repository_path_del = '{}.{}.delete'.format(
shadow_repository_path, time.time())
# move the shadow repo, so it never conflicts with the one used.
# we use this method because shutil.rmtree had some edge case problems
# removing symlinked repositories
if not os.path.isdir(shadow_repository_path):
return
shutil.move(shadow_repository_path, shadow_repository_path_del)
try:
shutil.rmtree(shadow_repository_path_del, ignore_errors=False)
except Exception:
log.exception('Failed to gracefully remove shadow repo under %s',
shadow_repository_path_del)
shutil.rmtree(shadow_repository_path_del, ignore_errors=True)
project: added all source files and assets
r1
# ========== #
# COMMIT API #
# ========== #
@LazyProperty
def in_memory_commit(self):
"""
Returns :class:`InMemoryCommit` object for this repository.
"""
raise NotImplementedError
# ======================== #
# UTILITIES FOR SUBCLASSES #
# ======================== #
def _validate_diff_commits(self, commit1, commit2):
"""
Validates that the given commits are related to this repository.
Intended as a utility for sub classes to have a consistent validation
of input parameters in methods like :meth:`get_diff`.
"""
self._validate_commit(commit1)
self._validate_commit(commit2)
if (isinstance(commit1, EmptyCommit) and
isinstance(commit2, EmptyCommit)):
raise ValueError("Cannot compare two empty commits")
def _validate_commit(self, commit):
if not isinstance(commit, BaseCommit):
raise TypeError(
"%s is not of type BaseCommit" % repr(commit))
if commit.repository != self and not isinstance(commit, EmptyCommit):
raise ValueError(
"Commit %s must be a valid commit from this repository %s, "
"related to this repository instead %s." %
(commit, self, commit.repository))
def _validate_commit_id(self, commit_id):
if not isinstance(commit_id, basestring):
raise TypeError("commit_id must be a string value")
def _validate_commit_idx(self, commit_idx):
if not isinstance(commit_idx, (int, long)):
raise TypeError("commit_idx must be a numeric value")
def _validate_branch_name(self, branch_name):
if branch_name and branch_name not in self.branches_all:
msg = ("Branch %s not found in %s" % (branch_name, self))
raise BranchDoesNotExistError(msg)
#
# Supporting deprecated API parts
# TODO: johbo: consider to move this into a mixin
#
@property
def EMPTY_CHANGESET(self):
warnings.warn(
"Use EMPTY_COMMIT or EMPTY_COMMIT_ID instead", DeprecationWarning)
return self.EMPTY_COMMIT_ID
@property
def revisions(self):
warnings.warn("Use commits attribute instead", DeprecationWarning)
return self.commit_ids
@revisions.setter
def revisions(self, value):
warnings.warn("Use commits attribute instead", DeprecationWarning)
self.commit_ids = value
def get_changeset(self, revision=None, pre_load=None):
warnings.warn("Use get_commit instead", DeprecationWarning)
commit_id = None
commit_idx = None
if isinstance(revision, basestring):
commit_id = revision
else:
commit_idx = revision
return self.get_commit(
commit_id=commit_id, commit_idx=commit_idx, pre_load=pre_load)
def get_changesets(
self, start=None, end=None, start_date=None, end_date=None,
branch_name=None, pre_load=None):
warnings.warn("Use get_commits instead", DeprecationWarning)
start_id = self._revision_to_commit(start)
end_id = self._revision_to_commit(end)
return self.get_commits(
start_id=start_id, end_id=end_id, start_date=start_date,
end_date=end_date, branch_name=branch_name, pre_load=pre_load)
def _revision_to_commit(self, revision):
"""
Translates a revision to a commit_id
Helps to support the old changeset based API which allows to use
commit ids and commit indices interchangeable.
"""
if revision is None:
return revision
if isinstance(revision, basestring):
commit_id = revision
else:
commit_id = self.commit_ids[revision]
return commit_id
@property
def in_memory_changeset(self):
warnings.warn("Use in_memory_commit instead", DeprecationWarning)
return self.in_memory_commit
path-permissions: Initial support for path-based permissions
r2618 def get_path_permissions(self, username):
"""
Returns a path permission checker or None if not supported
:param username: session user name
:return: an instance of BasePathPermissionChecker or None
"""
return None
svn: enable hooks and integration framework execution....
r2677 def install_hooks(self, force=False):
return self._remote.install_hooks(force)
project: added all source files and assets
r1
class BaseCommit(object):
"""
Each backend should implement it's commit representation.
**Attributes**
``repository``
repository object within which commit exists
``id``
The commit id, may be ``raw_id`` or i.e. for mercurial's tip
just ``tip``.
``raw_id``
raw commit representation (i.e. full 40 length sha for git
backend)
``short_id``
shortened (if apply) version of ``raw_id``; it would be simple
shortcut for ``raw_id[:12]`` for git/mercurial backends or same
as ``raw_id`` for subversion
``idx``
commit index
``files``
list of ``FileNode`` (``Node`` with NodeKind.FILE) objects
``dirs``
list of ``DirNode`` (``Node`` with NodeKind.DIR) objects
``nodes``
combined list of ``Node`` objects
``author``
author of the commit, as unicode
``message``
message of the commit, as unicode
``parents``
list of parent commits
"""
branch = None
"""
Depending on the backend this should be set to the branch name of the
commit. Backends not supporting branches on commits should leave this
value as ``None``.
"""
_ARCHIVE_PREFIX_TEMPLATE = b'{repo_name}-{short_id}'
"""
This template is used to generate a default prefix for repository archives
if no prefix has been specified.
"""
def __str__(self):
return '<%s at %s:%s>' % (
self.__class__.__name__, self.idx, self.short_id)
def __repr__(self):
return self.__str__()
def __unicode__(self):
return u'%s:%s' % (self.idx, self.short_id)
def __eq__(self, other):
dan
vcs: add equality testing for commits against non commits to allow...
r985 same_instance = isinstance(other, self.__class__)
return same_instance and self.raw_id == other.raw_id
project: added all source files and assets
r1
def __json__(self):
parents = []
try:
for parent in self.parents:
parents.append({'raw_id': parent.raw_id})
except NotImplementedError:
# empty commit doesn't have parents implemented
pass
return {
'short_id': self.short_id,
'raw_id': self.raw_id,
'revision': self.idx,
'message': self.message,
'date': self.date,
'author': self.author,
'parents': parents,
'branch': self.branch
}
Bartłomiej Wołyńczyk
caching: add option to cache diffs for commits and pull requests....
r2685 def __getstate__(self):
d = self.__dict__.copy()
d.pop('_remote', None)
d.pop('repository', None)
return d
vcs: commits, expose refs function to fetch commit refereces such as tags, bookmarks, etc.
r2337 def _get_refs(self):
return {
svn: enable hooks and integration framework execution....
r2677 'branches': [self.branch] if self.branch else [],
vcs: commits, expose refs function to fetch commit refereces such as tags, bookmarks, etc.
r2337 'bookmarks': getattr(self, 'bookmarks', []),
'tags': self.tags
}
project: added all source files and assets
r1 @LazyProperty
def last(self):
"""
``True`` if this is last commit in repository, ``False``
otherwise; trying to access this attribute while there is no
commits would raise `EmptyRepositoryError`
"""
if self.repository is None:
raise CommitError("Cannot check if it's most recent commit")
return self.raw_id == self.repository.commit_ids[-1]
@LazyProperty
def parents(self):
"""
Returns list of parent commits.
"""
raise NotImplementedError
pull-requests: allow to show range diff in pr view
r3124 @LazyProperty
def first_parent(self):
"""
Returns list of parent commits.
"""
return self.parents[0] if self.parents else EmptyCommit()
project: added all source files and assets
r1 @property
def merge(self):
"""
Returns boolean if commit is a merge.
"""
return len(self.parents) > 1
@LazyProperty
def children(self):
"""
Returns list of child commits.
"""
raise NotImplementedError
@LazyProperty
def id(self):
"""
Returns string identifying this commit.
"""
raise NotImplementedError
@LazyProperty
def raw_id(self):
"""
Returns raw string identifying this commit.
"""
raise NotImplementedError
@LazyProperty
def short_id(self):
"""
Returns shortened version of ``raw_id`` attribute, as string,
identifying this commit, useful for presentation to users.
"""
raise NotImplementedError
@LazyProperty
def idx(self):
"""
Returns integer identifying this commit.
"""
raise NotImplementedError
@LazyProperty
def committer(self):
"""
Returns committer for this commit
"""
raise NotImplementedError
@LazyProperty
def committer_name(self):
"""
Returns committer name for this commit
"""
return author_name(self.committer)
@LazyProperty
def committer_email(self):
"""
Returns committer email address for this commit
"""
return author_email(self.committer)
@LazyProperty
def author(self):
"""
Returns author for this commit
"""
raise NotImplementedError
@LazyProperty
def author_name(self):
"""
Returns author name for this commit
"""
return author_name(self.author)
@LazyProperty
def author_email(self):
"""
Returns author email address for this commit
"""
return author_email(self.author)
def get_file_mode(self, path):
"""
Returns stat mode of the file at `path`.
"""
raise NotImplementedError
def is_link(self, path):
"""
Returns ``True`` if given `path` is a symlink
"""
raise NotImplementedError
def get_file_content(self, path):
"""
Returns content of the file at the given `path`.
"""
raise NotImplementedError
def get_file_size(self, path):
"""
Returns size of the file at the given `path`.
"""
raise NotImplementedError
def get_file_commit(self, path, pre_load=None):
"""
Returns last commit of the file at the given `path`.
:param pre_load: Optional. List of commit attributes to load.
"""
vcs: raise better exception if file node history cannot be extracted....
r1179 commits = self.get_file_history(path, limit=1, pre_load=pre_load)
if not commits:
raise RepositoryError(
'Failed to fetch history for path {}. '
'Please check if such path exists in your repository'.format(
path))
return commits[0]
project: added all source files and assets
r1
def get_file_history(self, path, limit=None, pre_load=None):
"""
Returns history of file as reversed list of :class:`BaseCommit`
objects for which file at given `path` has been modified.
:param limit: Optional. Allows to limit the size of the returned
history. This is intended as a hint to the underlying backend, so
that it can apply optimizations depending on the limit.
:param pre_load: Optional. List of commit attributes to load.
"""
raise NotImplementedError
def get_file_annotate(self, path, pre_load=None):
"""
Returns a generator of four element tuples with
lineno, sha, commit lazy loader and line
:param pre_load: Optional. List of commit attributes to load.
"""
raise NotImplementedError
def get_nodes(self, path):
"""
Returns combined ``DirNode`` and ``FileNode`` objects list representing
state of commit at the given ``path``.
:raises ``CommitError``: if node at the given ``path`` is not
instance of ``DirNode``
"""
raise NotImplementedError
def get_node(self, path):
"""
Returns ``Node`` object from the given ``path``.
:raises ``NodeDoesNotExistError``: if there is no node at the given
``path``
"""
raise NotImplementedError
def get_largefile_node(self, path):
"""
largefiles: enabled download of largefiles for git and mercurial from web interface....
r1577 Returns the path to largefile from Mercurial/Git-lfs storage.
or None if it's not a largefile node
project: added all source files and assets
r1 """
largefiles: enabled download of largefiles for git and mercurial from web interface....
r1577 return None
project: added all source files and assets
r1
def archive_repo(self, file_path, kind='tgz', subrepos=None,
prefix=None, write_metadata=False, mtime=None):
"""
Creates an archive containing the contents of the repository.
:param file_path: path to the file which to create the archive.
:param kind: one of following: ``"tbz2"``, ``"tgz"``, ``"zip"``.
:param prefix: name of root directory in archive.
Default is repository name and commit's short_id joined with dash:
``"{repo_name}-{short_id}"``.
:param write_metadata: write a metadata file into archive.
:param mtime: custom modification time for archive creation, defaults
to time.time() if not given.
:raise VCSError: If prefix has a problem.
"""
allowed_kinds = settings.ARCHIVE_SPECS.keys()
if kind not in allowed_kinds:
raise ImproperArchiveTypeError(
'Archive kind (%s) not supported use one of %s' %
(kind, allowed_kinds))
prefix = self._validate_archive_prefix(prefix)
Martin Bornhold
vcs: Use commit date as modification time when creating archives. #4247
r869 mtime = mtime or time.mktime(self.date.timetuple())
project: added all source files and assets
r1
file_info = []
cur_rev = self.repository.get_commit(commit_id=self.raw_id)
for _r, _d, files in cur_rev.walk('/'):
for f in files:
f_path = os.path.join(prefix, f.path)
file_info.append(
dan
scm: change ._get_content() to .raw_bytes attribute to file nodes to...
r501 (f_path, f.mode, f.is_link(), f.raw_bytes))
project: added all source files and assets