Skip to content

Commit 7c4d3d6

Browse files
committed
Added ref implementation and tried to fix it so that it has a chance of running. Currently it requires an object implementation which will be ported next. None of the tests is expected to run yet.
1 parent 86388c5 commit 7c4d3d6

File tree

13 files changed

+2109
-14
lines changed

13 files changed

+2109
-14
lines changed

gitdb/db/base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class TransportDBMixin(object):
419419

420420
#{ Interface
421421

422-
def fetch(self, url, refspecs, progress=None):
422+
def fetch(self, url, refspecs, progress=None, **kwargs):
423423
"""Fetch the objects defined by the given refspec from the given url.
424424
:param url: url identifying the source of the objects. It may also be
425425
a symbol from which the respective url can be resolved, like the
@@ -428,7 +428,9 @@ def fetch(self, url, refspecs, progress=None):
428428
:param refspecs: iterable of reference specifiers or RefSpec instance,
429429
identifying the references to be fetch from the remote.
430430
:param progress: callable which receives progress messages for user consumption
431-
:return: List of binary object shas matching the respective remote ref which
431+
:param kwargs: may be used for additional parameters that the actual implementation could
432+
find useful.
433+
:return: List of FetchInfo compatible instances which provide information about what
432434
was previously fetched, in the order of the input refspecs.
433435
:note: even if the operation fails, one of the returned FetchInfo instances
434436
may still contain errors or failures in only part of the refspecs.
@@ -437,14 +439,16 @@ def fetch(self, url, refspecs, progress=None):
437439
"""
438440
raise NotImplementedError()
439441

440-
def push(self, url, refspecs, progress=None):
442+
def push(self, url, refspecs, progress=None, **kwargs):
441443
"""Transport the objects identified by the given refspec to the remote
442444
at the given url.
443445
:param url: Decribes the location which is to receive the objects
444446
see fetch() for more details
445447
:param refspecs: iterable of refspecs strings or RefSpec instances
446448
to identify the objects to push
447449
:param progress: see fetch()
450+
:param kwargs: additional arguments which may be provided by the caller
451+
as they may be useful to the actual implementation
448452
:todo: what to return ?
449453
:raise: if any issue arises during transport or if the url cannot be handled"""
450454
raise NotImplementedError()

gitdb/ref/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# import all modules in order, fix the names they require
3+
from symbolic import *
4+
from reference import *
5+
from head import *
6+
from tag import *
7+
from remote import *
8+
9+
# name fixes
10+
import head
11+
head.Head.RemoteReferenceCls = RemoteReference
12+
del(head)
13+
14+
15+
import symbolic
16+
for item in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference):
17+
setattr(symbolic.SymbolicReference, item.__name__+'Cls', item)
18+
del(symbolic)
19+
20+
21+
from log import *

gitdb/ref/head.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
from symbolic import SymbolicReference
2+
from reference import Reference
3+
from gitdb.config import SectionConstraint
4+
from gitdb.util import join_path
5+
6+
__all__ = ["HEAD", "Head"]
7+
8+
9+
10+
class HEAD(SymbolicReference):
11+
"""Special case of a Symbolic Reference as it represents the repository's
12+
HEAD reference."""
13+
_HEAD_NAME = 'HEAD'
14+
_ORIG_HEAD_NAME = 'ORIG_HEAD'
15+
__slots__ = tuple()
16+
17+
def __init__(self, repo, path=_HEAD_NAME):
18+
if path != self._HEAD_NAME:
19+
raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path))
20+
super(HEAD, self).__init__(repo, path)
21+
22+
def orig_head(self):
23+
"""
24+
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
25+
to contain the previous value of HEAD"""
26+
return SymbolicReference(self.repo, self._ORIG_HEAD_NAME)
27+
28+
29+
class Head(Reference):
30+
"""A Head is a named reference to a Commit"""
31+
_common_path_default = "refs/heads"
32+
k_config_remote = "remote"
33+
k_config_remote_ref = "merge" # branch to merge from remote
34+
35+
# will be set by init method !
36+
RemoteReferenceCls = None
37+
38+
#{ Configuration
39+
40+
def set_tracking_branch(self, remote_reference):
41+
"""
42+
Configure this branch to track the given remote reference. This will alter
43+
this branch's configuration accordingly.
44+
45+
:param remote_reference: The remote reference to track or None to untrack
46+
any references
47+
:return: self"""
48+
if remote_reference is not None and not isinstance(remote_reference, self.RemoteReferenceCls):
49+
raise ValueError("Incorrect parameter type: %r" % remote_reference)
50+
# END handle type
51+
52+
writer = self.config_writer()
53+
if remote_reference is None:
54+
writer.remove_option(self.k_config_remote)
55+
writer.remove_option(self.k_config_remote_ref)
56+
if len(writer.options()) == 0:
57+
writer.remove_section()
58+
# END handle remove section
59+
else:
60+
writer.set_value(self.k_config_remote, remote_reference.remote_name)
61+
writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head))
62+
# END handle ref value
63+
64+
return self
65+
66+
def tracking_branch(self):
67+
"""
68+
:return: The remote_reference we are tracking, or None if we are
69+
not a tracking branch"""
70+
reader = self.config_reader()
71+
if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref):
72+
ref = Head(self.repo, Head.to_full_path(reader.get_value(self.k_config_remote_ref)))
73+
remote_refpath = self.RemoteReferenceCls.to_full_path(join_path(reader.get_value(self.k_config_remote), ref.name))
74+
return self.RemoteReferenceCls(self.repo, remote_refpath)
75+
# END handle have tracking branch
76+
77+
# we are not a tracking branch
78+
return None
79+
80+
81+
#{ Configruation
82+
83+
def _config_parser(self, read_only):
84+
if read_only:
85+
parser = self.repo.config_reader()
86+
else:
87+
parser = self.repo.config_writer()
88+
# END handle parser instance
89+
90+
return SectionConstraint(parser, 'branch "%s"' % self.name)
91+
92+
def config_reader(self):
93+
"""
94+
:return: A configuration parser instance constrained to only read
95+
this instance's values"""
96+
return self._config_parser(read_only=True)
97+
98+
def config_writer(self):
99+
"""
100+
:return: A configuration writer instance with read-and write acccess
101+
to options of this head"""
102+
return self._config_parser(read_only=False)
103+
104+
#} END configuration
105+
106+

0 commit comments

Comments
 (0)