Skip to content

Commit e77d2d0

Browse files
committed
Removed all parts of the reference implementation which doesn't require the git command. everything else was moved to GitDB. None of the tests is yet expected to run, although git-python should have less trouble getting the tests back up running than GitDB. plenty of code needs to be de-duplicated though in case of the tests, which will be some work
1 parent 8af9416 commit e77d2d0

File tree

13 files changed

+87
-1474
lines changed

13 files changed

+87
-1474
lines changed

doc/source/changes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Changelog
55
NEXT
66
====
77
* ### Interface Changes ###
8-
* None yet
8+
* SymbolicReference
9+
* object_binsha property added
910
* Blob Type
1011
* Added mode constants to ease the manual creation of blobs
1112

git/db.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class PushInfo(GitdbPushInfo):
5050
info.remote_ref_string # path to the remote reference located on the remote side
5151
info.remote_ref # Remote Reference on the local side corresponding to
5252
# the remote_ref_string. It can be a TagReference as well.
53-
info.old_commit # commit at which the remote_ref was standing before we pushed
53+
info.old_commit_binsha # binary sha at which the remote_ref was standing before we pushed
5454
# it to local_ref.commit. Will be None if an error was indicated
5555
info.summary # summary line providing human readable english text about the push
5656
"""
57-
__slots__ = ('local_ref', 'remote_ref_string', 'flags', 'old_commit', '_remote', 'summary')
57+
__slots__ = ('local_ref', 'remote_ref_string', 'flags', 'old_commit_binsha', '_remote', 'summary')
5858

5959
_flag_map = { 'X' : GitdbPushInfo.NO_MATCH,
6060
'-' : GitdbPushInfo.DELETED, '*' : 0,
@@ -63,14 +63,14 @@ class PushInfo(GitdbPushInfo):
6363
'=' : GitdbPushInfo.UP_TO_DATE,
6464
'!' : GitdbPushInfo.ERROR }
6565

66-
def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit=None,
66+
def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit_binsha=None,
6767
summary=''):
6868
""" Initialize a new instance """
6969
self.flags = flags
7070
self.local_ref = local_ref
7171
self.remote_ref_string = remote_ref_string
7272
self._remote = remote
73-
self.old_commit = old_commit
73+
self.old_commit_binsha = old_commit_binsha
7474
self.summary = summary
7575

7676
@property
@@ -111,7 +111,7 @@ def _from_line(cls, remote, line):
111111
from_ref = Reference.from_path(remote.repo, from_ref_string)
112112

113113
# commit handling, could be message or commit info
114-
old_commit = None
114+
old_commit_binsha = None
115115
if summary.startswith('['):
116116
if "[rejected]" in summary:
117117
flags |= cls.REJECTED
@@ -134,10 +134,10 @@ def _from_line(cls, remote, line):
134134
split_token = ".."
135135
old_sha, new_sha = summary.split(' ')[0].split(split_token)
136136
# have to use constructor here as the sha usually is abbreviated
137-
old_commit = remote.repo.commit(old_sha)
137+
old_commit_binsha = remote.repo.commit(old_sha)
138138
# END message handling
139139

140-
return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary)
140+
return PushInfo(flags, from_ref, to_ref_string, remote, old_commit_binsha, summary)
141141

142142

143143
class FetchInfo(GitdbFetchInfo):
@@ -151,10 +151,10 @@ class FetchInfo(GitdbFetchInfo):
151151
# i.e. info.flags & info.REJECTED
152152
# is 0 if ref is FETCH_HEAD
153153
info.note # additional notes given by git-fetch intended for the user
154-
info.old_commit # if info.flags & info.FORCED_UPDATE|info.FAST_FORWARD,
154+
info.old_commit_binsha # if info.flags & info.FORCED_UPDATE|info.FAST_FORWARD,
155155
# field is set to the previous location of ref, otherwise None
156156
"""
157-
__slots__ = ('ref','old_commit', 'flags', 'note')
157+
__slots__ = ('ref','old_commit_binsha', 'flags', 'note')
158158

159159
# %c %-*s %-*s -> %s (%s)
160160
re_fetch_result = re.compile("^\s*(.) (\[?[\w\s\.]+\]?)\s+(.+) -> ([/\w_\+\.-]+)( \(.*\)?$)?")
@@ -166,14 +166,14 @@ class FetchInfo(GitdbFetchInfo):
166166
'=' : GitdbFetchInfo.HEAD_UPTODATE,
167167
' ' : GitdbFetchInfo.FAST_FORWARD }
168168

169-
def __init__(self, ref, flags, note = '', old_commit = None):
169+
def __init__(self, ref, flags, note = '', old_commit_binsha = None):
170170
"""
171171
Initialize a new instance
172172
"""
173173
self.ref = ref
174174
self.flags = flags
175175
self.note = note
176-
self.old_commit = old_commit
176+
self.old_commit_binsha = old_commit_binsha
177177

178178
def __str__(self):
179179
return self.name
@@ -250,7 +250,7 @@ def _from_line(cls, repo, line, fetch_line):
250250
# END control char exception hanlding
251251

252252
# parse operation string for more info - makes no sense for symbolic refs
253-
old_commit = None
253+
old_commit_binsha = None
254254
if isinstance(remote_local_ref, Reference):
255255
if 'rejected' in operation:
256256
flags |= cls.REJECTED
@@ -262,11 +262,11 @@ def _from_line(cls, repo, line, fetch_line):
262262
split_token = '...'
263263
if control_character == ' ':
264264
split_token = split_token[:-1]
265-
old_commit = repo.rev_parse(operation.split(split_token)[0])
265+
old_commit_binsha = repo.rev_parse(operation.split(split_token)[0])
266266
# END handle refspec
267267
# END reference flag handling
268268

269-
return cls(remote_local_ref, flags, note, old_commit)
269+
return cls(remote_local_ref, flags, note, old_commit_binsha)
270270

271271

272272
class GitCmdObjectDB(LooseObjectDB, TransportDBMixin):

git/refs/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
# name fixes
1010
import head
11-
head.RemoteReference = RemoteReference
11+
head.Head.RemoteReferenceCls = RemoteReference
1212
del(head)
1313

1414

1515
import symbolic
16-
for item in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference):
17-
setattr(symbolic, item.__name__, item)
16+
for item in (HEAD, Head, RemoteReference, TagReference, Reference):
17+
setattr(symbolic.SymbolicReference, item.__name__+'Cls', item)
1818
del(symbolic)
1919

2020

git/refs/head.py

Lines changed: 11 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1-
from symbolic import SymbolicReference
2-
from reference import Reference
3-
4-
from git.config import SectionConstraint
5-
6-
from git.util import join_path
71

2+
from gitdb.ref.head import HEAD as GitDB_HEAD
3+
from gitdb.ref.head import Head as GitDB_Head
84
from git.exc import GitCommandError
5+
from git.util import RepoAliasMixin
96

107
__all__ = ["HEAD", "Head"]
118

12-
139

14-
class HEAD(SymbolicReference):
15-
"""Special case of a Symbolic Reference as it represents the repository's
16-
HEAD reference."""
17-
_HEAD_NAME = 'HEAD'
18-
_ORIG_HEAD_NAME = 'ORIG_HEAD'
10+
class HEAD(GitDB_HEAD, RepoAliasMixin):
11+
"""Provides additional functionality using the git command"""
1912
__slots__ = tuple()
20-
21-
def __init__(self, repo, path=_HEAD_NAME):
22-
if path != self._HEAD_NAME:
23-
raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path))
24-
super(HEAD, self).__init__(repo, path)
25-
26-
def orig_head(self):
27-
"""
28-
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
29-
to contain the previous value of HEAD"""
30-
return SymbolicReference(self.repo, self._ORIG_HEAD_NAME)
3113

3214
def reset(self, commit='HEAD', index=True, working_tree = False,
3315
paths=None, **kwargs):
@@ -91,8 +73,10 @@ def reset(self, commit='HEAD', index=True, working_tree = False,
9173
return self
9274

9375

94-
class Head(Reference):
95-
"""A Head is a named reference to a Commit. Every Head instance contains a name
76+
class Head(GitDB_Head, RepoAliasMixin):
77+
"""The GitPyhton Head implementation provides more git-command based features
78+
79+
A Head is a named reference to a Commit. Every Head instance contains a name
9680
and a Commit object.
9781
9882
Examples::
@@ -108,6 +92,8 @@ class Head(Reference):
10892
10993
>>> head.commit.hexsha
11094
'1c09f116cbc2cb4100fb6935bb162daa4723f455'"""
95+
__slots__ = tuple()
96+
11197
_common_path_default = "refs/heads"
11298
k_config_remote = "remote"
11399
k_config_remote_ref = "merge" # branch to merge from remote
@@ -125,47 +111,7 @@ def delete(cls, repo, *heads, **kwargs):
125111
flag = "-D"
126112
repo.git.branch(flag, *heads)
127113

128-
def set_tracking_branch(self, remote_reference):
129-
"""
130-
Configure this branch to track the given remote reference. This will alter
131-
this branch's configuration accordingly.
132-
133-
:param remote_reference: The remote reference to track or None to untrack
134-
any references
135-
:return: self"""
136-
if remote_reference is not None and not isinstance(remote_reference, RemoteReference):
137-
raise ValueError("Incorrect parameter type: %r" % remote_reference)
138-
# END handle type
139-
140-
writer = self.config_writer()
141-
if remote_reference is None:
142-
writer.remove_option(self.k_config_remote)
143-
writer.remove_option(self.k_config_remote_ref)
144-
if len(writer.options()) == 0:
145-
writer.remove_section()
146-
# END handle remove section
147-
else:
148-
writer.set_value(self.k_config_remote, remote_reference.remote_name)
149-
writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head))
150-
# END handle ref value
151-
152-
return self
153-
154114

155-
def tracking_branch(self):
156-
"""
157-
:return: The remote_reference we are tracking, or None if we are
158-
not a tracking branch"""
159-
reader = self.config_reader()
160-
if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref):
161-
ref = Head(self.repo, Head.to_full_path(reader.get_value(self.k_config_remote_ref)))
162-
remote_refpath = RemoteReference.to_full_path(join_path(reader.get_value(self.k_config_remote), ref.name))
163-
return RemoteReference(self.repo, remote_refpath)
164-
# END handle have tracking branch
165-
166-
# we are not a tracking branch
167-
return None
168-
169115
def rename(self, new_path, force=False):
170116
"""Rename self to a new path
171117
@@ -217,30 +163,4 @@ def checkout(self, force=False, **kwargs):
217163

218164
self.repo.git.checkout(self, **kwargs)
219165
return self.repo.active_branch
220-
221-
#{ Configruation
222-
223-
def _config_parser(self, read_only):
224-
if read_only:
225-
parser = self.repo.config_reader()
226-
else:
227-
parser = self.repo.config_writer()
228-
# END handle parser instance
229-
230-
return SectionConstraint(parser, 'branch "%s"' % self.name)
231-
232-
def config_reader(self):
233-
"""
234-
:return: A configuration parser instance constrained to only read
235-
this instance's values"""
236-
return self._config_parser(read_only=True)
237-
238-
def config_writer(self):
239-
"""
240-
:return: A configuration writer instance with read-and write acccess
241-
to options of this head"""
242-
return self._config_parser(read_only=False)
243-
244-
#} END configuration
245-
246166

0 commit comments

Comments
 (0)