# -*- coding: utf-8 -*-
"""
vcs.backends.git.repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Git repository implementation.
:created_on: Apr 8, 2010
:copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
import os
import re
import time
import urllib
import urllib2
import logging
import posixpath
import string
import sys
if sys.platform == "win32":
from subprocess import list2cmdline
def quote(s):
return list2cmdline([s])
else:
try:
# Python <=2.7
from pipes import quote
except ImportError:
# Python 3.3+
from shlex import quote
from dulwich.objects import Tag
from dulwich.repo import Repo, NotGitRepository
from dulwich.config import ConfigFile
from kallithea.lib.vcs import subprocessio
from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator
from kallithea.lib.vcs.conf import settings
from kallithea.lib.vcs.exceptions import (
BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError,
RepositoryError, TagAlreadyExistError, TagDoesNotExistError
)
from kallithea.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp
from kallithea.lib.vcs.utils.lazy import LazyProperty
from kallithea.lib.vcs.utils.ordered_dict import OrderedDict
from kallithea.lib.vcs.utils.paths import abspath, get_user_home
from kallithea.lib.vcs.utils.hgcompat import (
hg_url, httpbasicauthhandler, httpdigestauthhandler
from .changeset import GitChangeset
from .inmemory import GitInMemoryChangeset
from .workdir import GitWorkdir
SHA_PATTERN = re.compile(r'^[[0-9a-fA-F]{12}|[0-9a-fA-F]{40}]$')
log = logging.getLogger(__name__)
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)
repo = self._get_repo(create, src_url, update_after_clone, bare)
self.bare = repo.bare
@property
def _config_files(self):
return [
self.bare and abspath(self.path, 'config')
or abspath(self.path, '.git', 'config'),
abspath(get_user_home(), '.gitconfig'),
]
def _repo(self):
return Repo(self.path)
def head(self):
return self._repo.head()
except KeyError:
return None
def _empty(self):
Checks if repository is empty ie. without any changesets
self.revisions[0]
except (KeyError, IndexError):
return True
return False
@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()
@classmethod
def _run_git_command(cls, cmd, **opts):
Runs given ``cmd`` as git command and returns tuple
(stdout, stderr).
Status change: