Skip to content

Commit 2b2ca10

Browse files
committed
Renaemd odb to repo (once again) as references require a full repository with reference support, as opposed to a plain odb which objects are already happy with. Tests now work up to the point where a rev-parse is required. This could be helped, but revparse could also be implemented somewhere which was the reason for pulling in so much code in the first place
1 parent 7e0dc3c commit 2b2ca10

File tree

7 files changed

+151
-140
lines changed

7 files changed

+151
-140
lines changed

gitdb/ref/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# import all modules in order, fix the names they require
33
from symbolic import *
44
from reference import *
5+
from headref import *
56
from head import *
67
from tag import *
78
from remote import *
89

910
# name fixes
10-
import head
11-
head.Head.RemoteReferenceCls = RemoteReference
12-
del(head)
11+
import headref
12+
headref.Head.RemoteReferenceCls = RemoteReference
13+
del(headref)
1314

1415

1516
import symbolic

gitdb/ref/head.py

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,22 @@
11
from symbolic import SymbolicReference
2-
from reference import Reference
3-
from gitdb.config import SectionConstraint
4-
from gitdb.util import join_path
52

6-
__all__ = ["HEAD", "Head"]
3+
__all__ = ["HEAD"]
74

8-
9-
105
class HEAD(SymbolicReference):
116
"""Special case of a Symbolic Reference as it represents the repository's
127
HEAD reference."""
138
_HEAD_NAME = 'HEAD'
149
_ORIG_HEAD_NAME = 'ORIG_HEAD'
1510
__slots__ = tuple()
1611

17-
def __init__(self, odb, path=_HEAD_NAME):
12+
def __init__(self, repo, path=_HEAD_NAME):
1813
if path != self._HEAD_NAME:
1914
raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path))
20-
super(HEAD, self).__init__(odb, path)
15+
super(HEAD, self).__init__(repo, path)
2116

2217
def orig_head(self):
2318
"""
2419
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
2520
to contain the previous value of HEAD"""
26-
return SymbolicReference(self.odb, 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.odb, 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.odb, 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.odb.config_reader()
86-
else:
87-
parser = self.odb.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-
21+
return SymbolicReference(self.repo, self._ORIG_HEAD_NAME)
10622

gitdb/ref/headref.py

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

gitdb/ref/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def path(cls, ref):
151151
instance would be found. The path is not guaranteed to point to a valid
152152
file though.
153153
:param ref: SymbolicReference instance"""
154-
return join(ref.odb.git_path(), "logs", to_native_path(ref.path))
154+
return join(ref.repo.git_path(), "logs", to_native_path(ref.path))
155155

156156
@classmethod
157157
def iter_entries(cls, stream):

gitdb/ref/reference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
from symbolic import SymbolicReference
4+
from head import HEAD
45
from gitdb.util import (
56
LazyMixin,
67
Iterable,
@@ -37,8 +38,8 @@ def __str__(self):
3738
def set_object(self, object, logmsg = None):
3839
"""Special version which checks if the head-log needs an update as well"""
3940
oldbinsha = None
41+
head = HEAD(self.repo)
4042
if logmsg is not None:
41-
head = self.repo.head
4243
if not head.is_detached and head.ref == self:
4344
oldbinsha = self.commit.binsha
4445
#END handle commit retrieval
@@ -59,7 +60,7 @@ def set_object(self, object, logmsg = None):
5960
# * check with HEAD only which should cover 99% of all usage
6061
# * scenarios (even 100% of the default ones).
6162
# */
62-
self.repo.head.log_append(oldbinsha, logmsg)
63+
head.log_append(oldbinsha, logmsg)
6364
#END check if the head
6465

6566
# NOTE: Don't have to overwrite properties as the will only work without a the log

gitdb/ref/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from head import Head
1+
from headref import Head
22
from gitdb.util import (
33
join,
44
join_path

0 commit comments

Comments
 (0)