##// END OF EJS Templates
fixed gravatar tests
fixed gravatar tests

File last commit:

r3890:f5a13148 beta
r3913:5f192af1 beta
Show More
repository.py
708 lines | 24.1 KiB | text/x-python | PythonLexer
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 # -*- coding: utf-8 -*-
"""
synced vcs with upstream...
r3797 vcs.backends.git.repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
synced vcs with upstream...
r3797 Git repository implementation.
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
:created_on: Apr 8, 2010
:copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
"""
import os
import re
import time
Added url validator for git
r2704 import urllib
import urllib2
synced vcs with upstream...
r3797 import logging
import posixpath
import string
fixes #625 Git-Tags are not displayed in Shortlog...
r2975 from dulwich.objects import Tag
synced vcs with upstream...
r3797 from dulwich.repo import Repo, NotGitRepository
git executable is now configurable via .ini files
r3376
synced vcs with upstream...
r3797 from rhodecode.lib.vcs import subprocessio
changelog pagination with branch filtering now uses...
r3747 from rhodecode.lib.vcs.backends.base import BaseRepository, CollectionGenerator
synced vcs with upstream...
r3797 from rhodecode.lib.vcs.conf import settings
from rhodecode.lib.vcs.exceptions import (
BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError,
RepositoryError, TagAlreadyExistError, TagDoesNotExistError
)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from rhodecode.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp
synced vcs with upstream...
r3797 from rhodecode.lib.vcs.utils.lazy import LazyProperty
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict
synced vcs with upstream...
r3797 from rhodecode.lib.vcs.utils.paths import abspath, get_user_home
from rhodecode.lib.vcs.utils.hgcompat import (
hg_url, httpbasicauthhandler, httpdigestauthhandler
)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from .changeset import GitChangeset
synced vcs with upstream...
r3797 from .config import ConfigFile
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from .inmemory import GitInMemoryChangeset
synced vcs with upstream...
r3797 from .workdir import GitWorkdir
switched git_command to subprocession for non-blocking Popen.
r2676
synced with latest vcs
r3805 SHA_PATTERN = re.compile(r'^[[0-9a-fA-F]{12}|[0-9a-fA-F]{40}]$')
switched git_command to subprocession for non-blocking Popen.
r2676 log = logging.getLogger(__name__)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
class GitRepository(BaseRepository):
"""
Git repository backend.
"""
DEFAULT_BRANCH_NAME = 'master'
scm = 'git'
def __init__(self, repo_path, create=False, src_url=None,
update_after_clone=False, bare=False):
self.path = abspath(repo_path)
Don't cache dulwich Repos, in pararell multithreaded evniroment dulwich pack file openers...
r3043 repo = self._get_repo(create, src_url, update_after_clone, bare)
self.bare = repo.bare
synced with latest vcs
r3805 @property
def _config_files(self):
return [
self.bare and abspath(self.path, 'config')
or abspath(self.path, '.git', 'config'),
abspath(get_user_home(), '.gitconfig'),
]
Don't cache dulwich Repos, in pararell multithreaded evniroment dulwich pack file openers...
r3043
after hooks cleanup we don't need to have ui injections into repo so we don't need to cache git repos...
r3579 @property
Don't cache dulwich Repos, in pararell multithreaded evniroment dulwich pack file openers...
r3043 def _repo(self):
Switched handling of RhodeCode extra params in consistent way...
r3577 return Repo(self.path)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
Don't cache dulwich Repos, in pararell multithreaded evniroment dulwich pack file openers...
r3043 @property
def head(self):
try:
return self._repo.head()
except KeyError:
return None
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
vcs: fixed issues with calling get_changesets method doesn't...
r3835 @property
def _empty(self):
"""
Checks if repository is empty ie. without any changesets
"""
try:
self.revisions[0]
except (KeyError, IndexError):
return True
return False
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 @LazyProperty
def revisions(self):
"""
Returns list of revisions' ids, in ascending order. Being lazy
attribute allows external tools to inject shas from cache.
"""
return self._get_all_revisions()
git executable is now configurable via .ini files
r3376 @classmethod
def _run_git_command(cls, cmd, **opts):
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 """
Runs given ``cmd`` as git command and returns tuple
git executable is now configurable via .ini files
r3376 (stdout, stderr).
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
:param cmd: git command to be executed
git executable is now configurable via .ini files
r3376 :param opts: env options to pass into Subprocess command
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 """
Extend GIT command wrapper with GIT_CONFIG_NOGLOBAL=1 to bypass gitconfig global
r2183
--version command should be safe, and bare no modifications...
r3397 if '_bare' in opts:
_copts = []
del opts['_bare']
else:
_copts = ['-c', 'core.quotepath=false', ]
safe_call = False
if '_safe' in opts:
#no exc on failure
del opts['_safe']
safe_call = True
fixed git-command wrapper
r2200 _str_cmd = False
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if isinstance(cmd, basestring):
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files...
r2199 cmd = [cmd]
fixed git-command wrapper
r2200 _str_cmd = True
white space cleanup
r2367
fix for issue #417, git execution was broken on windows for certain commands....
r2325 gitenv = os.environ
Remove GIT_DIT from environ on calling git_command, it can break a lot of stuff
r2616 # need to clean fix GIT_DIR !
if 'GIT_DIR' in gitenv:
del gitenv['GIT_DIR']
fix for issue #417, git execution was broken on windows for certain commands....
r2325 gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
various fixes for git and mercurial with InMemoryCommit backend and non-ascii files...
r2199
synced vcs with upstream...
r3797 _git_path = settings.GIT_EXECUTABLE_PATH
git executable is now configurable via .ini files
r3376 cmd = [_git_path] + _copts + cmd
fixed git-command wrapper
r2200 if _str_cmd:
cmd = ' '.join(cmd)
fixed handling shell argument in subprocess calls, it always was hardcoded even when passed properly in arguments
r3830
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 try:
git executable is now configurable via .ini files
r3376 _opts = dict(
fix for issue #417, git execution was broken on windows for certain commands....
r2325 env=gitenv,
fixed handling shell argument in subprocess calls, it always was hardcoded even when passed properly in arguments
r3830 shell=True,
fix for issue #417, git execution was broken on windows for certain commands....
r2325 )
git executable is now configurable via .ini files
r3376 _opts.update(opts)
p = subprocessio.SubprocessIOChunker(cmd, **_opts)
switched git_command to subprocession for non-blocking Popen.
r2676 except (EnvironmentError, OSError), err:
--version command should be safe, and bare no modifications...
r3397 tb_err = ("Couldn't run git command (%s).\n"
"Original error was:%s\n" % (cmd, err))
log.error(tb_err)
if safe_call:
return '', err
else:
raise RepositoryError(tb_err)
switched git_command to subprocession for non-blocking Popen.
r2676
get stderr also for git commands, pass in shell = False
r2760 return ''.join(p.output), ''.join(p.error)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
git executable is now configurable via .ini files
r3376 def run_git_command(self, cmd):
opts = {}
if os.path.isdir(self.path):
opts['cwd'] = self.path
return self._run_git_command(cmd, **opts)
Added url validator for git
r2704 @classmethod
def _check_url(cls, url):
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 """
Functon will check given url and try to verify if it's a valid
link. Sometimes it may happened that mercurial will issue basic
auth request that can cause whole API to hang when used from python
or other external calls.
On failures it'll raise urllib2.HTTPError
"""
Added url validator for git
r2704
# check first if it's not an local url
if os.path.isdir(url) or url.startswith('file:'):
return True
if('+' in url[:url.find('://')]):
url = url[url.find('+') + 1:]
handlers = []
synced vcs with upstream...
r3797 test_uri, authinfo = hg_url(url).authinfo()
Added url validator for git
r2704 if not test_uri.endswith('info/refs'):
test_uri = test_uri.rstrip('/') + '/info/refs'
if authinfo:
#create a password manager
passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmgr.add_password(*authinfo)
handlers.extend((httpbasicauthhandler(passmgr),
httpdigestauthhandler(passmgr)))
o = urllib2.build_opener(*handlers)
o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git
q = {"service": 'git-upload-pack'}
qs = '?%s' % urllib.urlencode(q)
cu = "%s%s" % (test_uri, qs)
req = urllib2.Request(cu, None, {})
try:
resp = o.open(req)
return resp.code == 200
except Exception, e:
# means it cannot be cloned
Fixed validators for remote repos...
r2706 raise urllib2.URLError("[%s] %s" % (url, e))
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
def _get_repo(self, create, src_url=None, update_after_clone=False,
git forks were not created as bare repos
r2807 bare=False):
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if create and os.path.exists(self.path):
raise RepositoryError("Location already exist")
if src_url and not create:
raise RepositoryError("Create should be set to True if src_url is "
"given (clone operation creates repository)")
try:
if create and src_url:
Added url validator for git
r2704 GitRepository._check_url(src_url)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 self.clone(src_url, update_after_clone, bare)
return Repo(self.path)
elif create:
os.mkdir(self.path)
if bare:
return Repo.init_bare(self.path)
else:
return Repo.init(self.path)
else:
use cache repo when creating GitRepository instances
r3396 return self._repo
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 except (NotGitRepository, OSError), err:
raise RepositoryError(err)
def _get_all_revisions(self):
switched git_command to subprocession for non-blocking Popen.
r2676 # we must check if this repo is not empty, since later command
# fails if it is. And it's cheaper to ask than throw the subprocess
# errors
try:
self._repo.head()
except KeyError:
return []
synced vcs with upstream...
r3797
rev_filter = _git_path = settings.GIT_REV_FILTER
made git refs filter configurable ref issue #797...
r3561 cmd = 'rev-list %s --reverse --date-order' % (rev_filter)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 try:
so, se = self.run_git_command(cmd)
except RepositoryError:
# Can be raised for empty repositories
return []
Get tags and branches using _parsed_refs
r2535 return so.splitlines()
def _get_all_revisions2(self):
#alternate implementation using dulwich
includes = [x[1][0] for x in self._parsed_refs.iteritems()
if x[1][1] != 'T']
return [c.commit.id for c in self._repo.get_walker(include=includes)]
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
def _get_revision(self, revision):
"""
For git backend we always return integer here. This way we ensure
that changset's revision attribute would become integer.
"""
synced with latest vcs
r3805
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 is_null = lambda o: len(o) == revision.count('0')
vcs: fixed issues with calling get_changesets method doesn't...
r3835 if self._empty:
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 raise EmptyRepositoryError("There are no changesets yet")
if revision in (None, '', 'tip', 'HEAD', 'head', -1):
synced with latest vcs
r3805 return self.revisions[-1]
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
synced with latest vcs
r3805 is_bstr = isinstance(revision, (str, unicode))
if ((is_bstr and revision.isdigit() and len(revision) < 12)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 or isinstance(revision, int) or is_null(revision)):
try:
revision = self.revisions[int(revision)]
Don't catch all exceptions
r3631 except Exception:
Mads Kiilerich
avoid %r markup of unicode strings in user facing messages...
r3575 raise ChangesetDoesNotExistError("Revision %s does not exist "
Mads Kiilerich
avoid displaying repr of internal classes in user facing messages...
r3574 "for this repository" % (revision))
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
synced with latest vcs
r3805 elif is_bstr:
Fixed lookup by Tag sha in git backend
r2536 # get by branch/tag name
added discovery by branches and tags for git
r2449 _ref_revision = self._parsed_refs.get(revision)
if _ref_revision: # and _ref_revision[1] in ['H', 'RH', 'T']:
return _ref_revision[0]
synced with latest vcs
r3805 _tags_shas = self.tags.values()
Fixed lookup by Tag sha in git backend
r2536 # maybe it's a tag ? we don't have them in self.revisions
synced with latest vcs
r3805 if revision in _tags_shas:
Fixed lookup by Tag sha in git backend
r2536 return _tags_shas[_tags_shas.index(revision)]
synced with latest vcs
r3805 elif not SHA_PATTERN.match(revision) or revision not in self.revisions:
Mads Kiilerich
avoid %r markup of unicode strings in user facing messages...
r3575 raise ChangesetDoesNotExistError("Revision %s does not exist "
Mads Kiilerich
avoid displaying repr of internal classes in user facing messages...
r3574 "for this repository" % (revision))
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
# Ensure we return full id
synced with latest vcs
r3805 if not SHA_PATTERN.match(str(revision)):
Mads Kiilerich
avoid %r markup of unicode strings in user facing messages...
r3575 raise ChangesetDoesNotExistError("Given revision %s not recognized"
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 % revision)
return revision
def _get_archives(self, archive_name='tip'):
for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
yield {"type": i[0], "extension": i[1], "node": archive_name}
def _get_url(self, url):
"""
Returns normalized url. If schema is not given, would fall to
filesystem (``file:///``) schema.
"""
url = str(url)
if url != 'default' and not '://' in url:
url = ':///'.join(('file', url))
return url
Added get_hook_location method for easier hook extraction
r3456 def get_hook_location(self):
"""
returns absolute path to location where hooks are stored
"""
loc = os.path.join(self.path, 'hooks')
if not self.bare:
loc = os.path.join(self.path, '.git', 'hooks')
return loc
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 @LazyProperty
def name(self):
return os.path.basename(self.path)
@LazyProperty
def last_change(self):
"""
Returns last change made on this repository as datetime object
"""
return date_fromtimestamp(self._get_mtime(), makedate()[1])
def _get_mtime(self):
try:
return time.mktime(self.get_changeset().date.timetuple())
except RepositoryError:
fixed issues with support of bare-repos by vcs lib
r2320 idx_loc = '' if self.bare else '.git'
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 # fallback to filesystem
fixed issues with support of bare-repos by vcs lib
r2320 in_path = os.path.join(self.path, idx_loc, "index")
he_path = os.path.join(self.path, idx_loc, "HEAD")
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if os.path.exists(in_path):
return os.stat(in_path).st_mtime
else:
return os.stat(he_path).st_mtime
@LazyProperty
def description(self):
fixed issues with support of bare-repos by vcs lib
r2320 idx_loc = '' if self.bare else '.git'
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 undefined_description = u'unknown'
fixed issues with support of bare-repos by vcs lib
r2320 description_path = os.path.join(self.path, idx_loc, 'description')
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if os.path.isfile(description_path):
return safe_unicode(open(description_path).read())
else:
return undefined_description
@LazyProperty
def contact(self):
undefined_contact = u'Unknown'
return undefined_contact
@property
def branches(self):
if not self.revisions:
return {}
sortkey = lambda ctx: ctx[0]
Get tags and branches using _parsed_refs
r2535 _branches = [(x[0], x[1][0])
for x in self._parsed_refs.iteritems() if x[1][1] == 'H']
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
added discovery by branches and tags for git
r2449 @LazyProperty
def tags(self):
return self._get_tags()
display current heads of branches for git in changelog and shortlog
r2198
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 def _get_tags(self):
if not self.revisions:
return {}
Get tags and branches using _parsed_refs
r2535
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 sortkey = lambda ctx: ctx[0]
Get tags and branches using _parsed_refs
r2535 _tags = [(x[0], x[1][0])
for x in self._parsed_refs.iteritems() if x[1][1] == 'T']
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 return OrderedDict(sorted(_tags, key=sortkey, reverse=True))
def tag(self, name, user, revision=None, message=None, date=None,
**kwargs):
"""
Creates and returns a tag for the given ``revision``.
:param name: name for new tag
:param user: full username, i.e.: "Joe Doe <joe.doe@example.com>"
:param revision: changeset 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
"""
if name in self.tags:
raise TagAlreadyExistError("Tag %s already exists" % name)
changeset = self.get_changeset(revision)
message = message or "Added tag %s for commit %s" % (name,
changeset.raw_id)
self._repo.refs["refs/tags/%s" % name] = changeset._commit.id
Invalidate gits parsed_refs cache after commit, tagging or tag remove
r2539 self._parsed_refs = self._get_parsed_refs()
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 self.tags = self._get_tags()
return changeset
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
"""
if name not in self.tags:
raise TagDoesNotExistError("Tag %s does not exist" % name)
tagpath = posixpath.join(self._repo.refs.path, 'refs', 'tags', name)
try:
os.remove(tagpath)
Invalidate gits parsed_refs cache after commit, tagging or tag remove
r2539 self._parsed_refs = self._get_parsed_refs()
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 self.tags = self._get_tags()
except OSError, e:
raise RepositoryError(e.strerror)
added discovery by branches and tags for git
r2449 @LazyProperty
def _parsed_refs(self):
Invalidate gits parsed_refs cache after commit, tagging or tag remove
r2539 return self._get_parsed_refs()
def _get_parsed_refs(self):
after hooks cleanup we don't need to have ui injections into repo so we don't need to cache git repos...
r3579 # cache the property
_repo = self._repo
refs = _repo.get_refs()
whitespace cleanup
r2453 keys = [('refs/heads/', 'H'),
added discovery by branches and tags for git
r2449 ('refs/remotes/origin/', 'RH'),
('refs/tags/', 'T')]
_refs = {}
for ref, sha in refs.iteritems():
for k, type_ in keys:
if ref.startswith(k):
_key = ref[len(k):]
fixes #625 Git-Tags are not displayed in Shortlog...
r2975 if type_ == 'T':
after hooks cleanup we don't need to have ui injections into repo so we don't need to cache git repos...
r3579 obj = _repo.get_object(sha)
fixes #625 Git-Tags are not displayed in Shortlog...
r2975 if isinstance(obj, Tag):
after hooks cleanup we don't need to have ui injections into repo so we don't need to cache git repos...
r3579 sha = _repo.get_object(sha).object[1]
added discovery by branches and tags for git
r2449 _refs[_key] = [sha, type_]
break
return _refs
def _heads(self, reverse=False):
refs = self._repo.get_refs()
heads = {}
for key, val in refs.items():
for ref_key in ['refs/heads/', 'refs/remotes/origin/']:
if key.startswith(ref_key):
n = key[len(ref_key):]
if n not in ['HEAD']:
heads[n] = val
return heads if reverse else dict((y, x) for x, y in heads.iteritems())
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 def get_changeset(self, revision=None):
"""
Returns ``GitChangeset`` object representing commit from git repository
at the given revision or head (most recent commit) if None given.
"""
if isinstance(revision, GitChangeset):
return revision
revision = self._get_revision(revision)
changeset = GitChangeset(repository=self, revision=revision)
return changeset
def get_changesets(self, start=None, end=None, start_date=None,
end_date=None, branch_name=None, reverse=False):
"""
Returns iterator of ``GitChangeset`` objects from start to end (both
are inclusive), in ascending date order (unless ``reverse`` is set).
:param start: changeset ID, as str; first returned changeset
:param end: changeset ID, as str; last returned changeset
:param start_date: if specified, changesets with commit date less than
``start_date`` would be filtered out from returned set
:param end_date: if specified, changesets with commit date greater than
``end_date`` would be filtered out from returned set
:param branch_name: if specified, changesets not reachable from given
branch would be filtered out from returned set
:param reverse: if ``True``, returned generator would be reversed
(meaning that returned changesets would have descending date order)
:raise BranchDoesNotExistError: If given ``branch_name`` does not
exist.
:raise ChangesetDoesNotExistError: If changeset for given ``start`` or
``end`` could not be found.
"""
if branch_name and branch_name not in self.branches:
raise BranchDoesNotExistError("Branch '%s' not found" \
% branch_name)
vcs: fixed issues with calling get_changesets method doesn't...
r3835 # actually we should check now if it's not an empty repo to not spaw
# subprocess commands
if self._empty:
raise EmptyRepositoryError("There are no changesets yet")
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 # %H at format means (full) commit hash, initial hashes are retrieved
# in ascending date order
cmd_template = 'log --date-order --reverse --pretty=format:"%H"'
cmd_params = {}
if start_date:
cmd_template += ' --since "$since"'
cmd_params['since'] = start_date.strftime('%m/%d/%y %H:%M:%S')
if end_date:
cmd_template += ' --until "$until"'
cmd_params['until'] = end_date.strftime('%m/%d/%y %H:%M:%S')
if branch_name:
cmd_template += ' $branch_name'
cmd_params['branch_name'] = branch_name
else:
synced vcs with upstream...
r3797 rev_filter = _git_path = settings.GIT_REV_FILTER
made git refs filter configurable ref issue #797...
r3561 cmd_template += ' %s' % (rev_filter)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
synced vcs with upstream...
r3797 cmd = string.Template(cmd_template).safe_substitute(**cmd_params)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 revs = self.run_git_command(cmd)[0].splitlines()
start_pos = 0
end_pos = len(revs)
if start:
_start = self._get_revision(start)
try:
start_pos = revs.index(_start)
except ValueError:
pass
if end is not None:
_end = self._get_revision(end)
try:
end_pos = revs.index(_end)
except ValueError:
pass
if None not in [start, end] and start_pos > end_pos:
raise RepositoryError('start cannot be after end')
if end_pos is not None:
end_pos += 1
revs = revs[start_pos:end_pos]
if reverse:
revs = reversed(revs)
changelog pagination with branch filtering now uses...
r3747 return CollectionGenerator(self, revs)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007
def get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
fixed issues with gitsubmodule diffs
r2233 context=3):
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 """
Returns (git like) *diff*, as plain text. Shows changes introduced by
``rev2`` since ``rev1``.
:param rev1: Entry point from which diff is shown. Can be
``self.EMPTY_CHANGESET`` - in this case, patch showing all
the changes since empty state of the repository until ``rev2``
:param rev2: Until which revision changes should be shown.
: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``.
"""
Implemented generation of changesets based...
r2995 flags = ['-U%s' % context, '--full-index', '--binary', '-p', '-M', '--abbrev=40']
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if ignore_whitespace:
flags.append('-w')
Added diff option into git and hg changeset objects, representing git formated patch against parent1
r2384 if hasattr(rev1, 'raw_id'):
rev1 = getattr(rev1, 'raw_id')
if hasattr(rev2, 'raw_id'):
rev2 = getattr(rev2, 'raw_id')
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 if rev1 == self.EMPTY_CHANGESET:
rev2 = self.get_changeset(rev2).raw_id
cmd = ' '.join(['show'] + flags + [rev2])
else:
rev1 = self.get_changeset(rev1).raw_id
rev2 = self.get_changeset(rev2).raw_id
cmd = ' '.join(['diff'] + flags + [rev1, rev2])
if path:
cmd += ' -- "%s"' % path
Implemented generation of changesets based...
r2995
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 stdout, stderr = self.run_git_command(cmd)
# If we used 'show' command, strip first few lines (until actual diff
# starts)
if rev1 == self.EMPTY_CHANGESET:
lines = stdout.splitlines()
x = 0
for line in lines:
if line.startswith('diff'):
break
x += 1
# Append new line just like 'diff' command do
stdout = '\n'.join(lines[x:]) + '\n'
return stdout
@LazyProperty
def in_memory_changeset(self):
"""
Returns ``GitInMemoryChangeset`` object for this repository.
"""
return GitInMemoryChangeset(self)
def clone(self, url, update_after_clone=True, bare=False):
"""
Tries to clone changes from external location.
:param update_after_clone: If set to ``False``, git won't checkout
working directory
:param bare: If set to ``True``, repository would be cloned into
*bare* git repository (no working directory at all).
"""
url = self._get_url(url)
cmd = ['clone']
if bare:
cmd.append('--bare')
elif not update_after_clone:
cmd.append('--no-checkout')
cmd += ['--', '"%s"' % url, '"%s"' % self.path]
cmd = ' '.join(cmd)
# If error occurs run_git_command raises RepositoryError already
self.run_git_command(cmd)
Implemented pull command for remote repos for git...
r2209 def pull(self, url):
"""
Tries to pull changes from external location.
"""
url = self._get_url(url)
replace list appends with list literals when possible
r3890 cmd = ['pull', "--ff-only", url]
Implemented pull command for remote repos for git...
r2209 cmd = ' '.join(cmd)
# If error occurs run_git_command raises RepositoryError already
self.run_git_command(cmd)
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
r2383 def fetch(self, url):
"""
Tries to pull changes from external location.
"""
url = self._get_url(url)
fixed bad merge on git fetch fix
r3178 so, se = self.run_git_command('ls-remote -h %s' % url)
fixed fetch command for git repos, now it properly fetches from remotes
r3157 refs = []
for line in (x for x in so.splitlines()):
sha, ref = line.split('\t')
refs.append(ref)
refs = ' '.join(('+%s:%s' % (r, r) for r in refs))
fixed bad merge on git fetch fix
r3178 cmd = '''fetch %s -- %s''' % (url, refs)
Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
r2383 self.run_git_command(cmd)
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 @LazyProperty
def workdir(self):
"""
Returns ``Workdir`` instance for this repository.
"""
return GitWorkdir(self)
def get_config_value(self, section, name, config_file=None):
"""
Returns configuration value for a given [``section``] and ``name``.
:param section: Section we want to retrieve value from
:param name: Name of configuration we want to retrieve
:param config_file: A path to file which should be used to retrieve
configuration from (might also be a list of file paths)
"""
if config_file is None:
config_file = []
elif isinstance(config_file, basestring):
config_file = [config_file]
def gen_configs():
for path in config_file + self._config_files:
try:
yield ConfigFile.from_path(path)
except (IOError, OSError, ValueError):
continue
for config in gen_configs():
try:
return config.get(section, name)
except KeyError:
continue
return None
def get_user_name(self, config_file=None):
"""
Returns user's name from global configuration file.
:param config_file: A path to file which should be used to retrieve
configuration from (might also be a list of file paths)
"""
return self.get_config_value('user', 'name', config_file)
def get_user_email(self, config_file=None):
"""
Returns user's email from global configuration file.
:param config_file: A path to file which should be used to retrieve
configuration from (might also be a list of file paths)
"""
return self.get_config_value('user', 'email', config_file)