Skip to content

Commit 1fe889e

Browse files
committed
All tests adjusted to work with the changed internal sha representation
1 parent 47e3138 commit 1fe889e

19 files changed

+198
-173
lines changed

‎lib/git/diff.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from objects.blob import Blob
99
from objects.utils import mode_str_to_int
1010
from errors import GitCommandError
11+
12+
from gitdb.util import hex_to_bin
1113

1214
__all__ = ('Diffable', 'DiffIndex', 'Diff')
1315

@@ -197,11 +199,11 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode,
197199
if a_blob_id is None:
198200
self.a_blob = None
199201
else:
200-
self.a_blob = Blob(repo, a_blob_id, mode=a_mode, path=a_path)
202+
self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=a_mode, path=a_path)
201203
if b_blob_id is None:
202204
self.b_blob = None
203205
else:
204-
self.b_blob = Blob(repo, b_blob_id, mode=b_mode, path=b_path)
206+
self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=b_mode, path=b_path)
205207

206208
self.a_mode = a_mode
207209
self.b_mode = b_mode

‎lib/git/objects/blob.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
__all__ = ('Blob', )
1111

1212
class Blob(base.IndexObject):
13-
"""A Blob encapsulates a git blob object"""
14-
DEFAULT_MIME_TYPE = "text/plain"
15-
type = "blob"
13+
"""A Blob encapsulates a git blob object"""
14+
DEFAULT_MIME_TYPE = "text/plain"
15+
type = "blob"
1616

17-
__slots__ = "data"
17+
__slots__ = "data"
1818

1919
def _set_cache_(self, attr):
2020
if attr == "data":
@@ -26,11 +26,11 @@ def _set_cache_(self, attr):
2626
super(Blob, self)._set_cache_(attr)
2727
# END handle data
2828

29-
@property
30-
def mime_type(self):
31-
""" :return:String describing the mime type of this file (based on the filename)
32-
:note: Defaults to 'text/plain' in case the actual file type is unknown. """
33-
guesses = None
34-
if self.path:
35-
guesses = guess_type(self.path)
36-
return guesses and guesses[0] or self.DEFAULT_MIME_TYPE
29+
@property
30+
def mime_type(self):
31+
""" :return:String describing the mime type of this file (based on the filename)
32+
:note: Defaults to 'text/plain' in case the actual file type is unknown. """
33+
guesses = None
34+
if self.path:
35+
guesses = guess_type(self.path)
36+
return guesses and guesses[0] or self.DEFAULT_MIME_TYPE

‎lib/git/objects/commit.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
get_user_id,
2424
parse_date,
2525
Actor,
26-
altz_to_utctz_str
26+
altz_to_utctz_str,
2727
parse_actor_and_date
2828
)
2929
from time import (
3030
time,
3131
altzone
3232
)
33+
import os
3334

3435
__all__ = ('Commit', )
3536

@@ -76,7 +77,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
7677
:param parents: tuple( Commit, ... )
7778
is a tuple of commit ids or actual Commits
7879
:param tree: Tree
79-
20 byte tree sha
80+
Tree object
8081
:param author: Actor
8182
is the author string ( will be implicitly converted into an Actor object )
8283
:param authored_date: int_seconds_since_epoch
@@ -103,7 +104,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
103104
:note: Timezone information is in the same format and in the same sign
104105
as what time.altzone returns. The sign is inverted compared to git's
105106
UTC timezone."""
106-
super(Commit,self).__init__(repo, sha)
107+
super(Commit,self).__init__(repo, binsha)
107108
self._set_self_from_args_(locals())
108109

109110
@classmethod
@@ -227,14 +228,14 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
227228
line = readline()
228229
if not line:
229230
break
230-
sha = line.strip()
231-
if len(sha) > 40:
231+
hexsha = line.strip()
232+
if len(hexsha) > 40:
232233
# split additional information, as returned by bisect for instance
233-
sha, rest = line.split(None, 1)
234+
hexsha, rest = line.split(None, 1)
234235
# END handle extra info
235236

236-
assert len(sha) == 40, "Invalid line: %s" % sha
237-
yield Commit(repo, sha)
237+
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
238+
yield Commit(repo, hex_to_bin(hexsha))
238239
# END for each line in stream
239240

240241

@@ -282,7 +283,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
282283

283284
# COMMITER AND AUTHOR INFO
284285
cr = repo.config_reader()
285-
env = environ
286+
env = os.environ
286287
default_email = get_user_id()
287288
default_name = default_email.split('@')[0]
288289

‎lib/git/objects/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, repo, binsha, object=None, tag=None,
3232
it into a different format
3333
:param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the
3434
authored_date is in, in a format similar to time.altzone"""
35-
super(TagObject, self).__init__(repo, sha )
35+
super(TagObject, self).__init__(repo, binsha )
3636
self._set_self_from_args_(locals())
3737

3838
def _set_cache_(self, attr):

‎lib/git/objects/tree.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
tree_to_stream
1616
)
1717

18-
from gitdb.util import to_bin_sha
18+
from gitdb.util import (
19+
to_bin_sha,
20+
join
21+
)
1922

2023
__all__ = ("TreeModifier", "Tree")
2124

@@ -61,7 +64,7 @@ def add(self, sha, mode, name, force=False):
6164
:return: self"""
6265
if '/' in name:
6366
raise ValueError("Name must not contain '/' characters")
64-
if (mode >> 12) not in self._map_id_to_type:
67+
if (mode >> 12) not in Tree._map_id_to_type:
6568
raise ValueError("Invalid object type according to mode %o" % mode)
6669

6770
sha = to_bin_sha(sha)
@@ -150,7 +153,7 @@ def _iter_convert_to_object(self, iterable):
150153
for binsha, mode, name in iterable:
151154
path = join(self.path, name)
152155
try:
153-
yield self._map_id_to_type[type_id](self.repo, binsha, mode >> 12, path)
156+
yield self._map_id_to_type[mode >> 12](self.repo, binsha, mode, path)
154157
except KeyError:
155158
raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path))
156159
# END for each item

‎lib/git/refs.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
isdir,
2626
exists,
2727
isfile,
28-
rename
28+
rename,
29+
hex_to_bin
2930
)
3031

3132

@@ -147,11 +148,11 @@ def _get_commit(self):
147148
Commit object we point to, works for detached and non-detached
148149
SymbolicReferences"""
149150
# we partially reimplement it to prevent unnecessary file access
150-
sha, target_ref_path = self._get_ref_info()
151+
hexsha, target_ref_path = self._get_ref_info()
151152

152153
# it is a detached reference
153-
if sha:
154-
return Commit(self.repo, sha)
154+
if hexsha:
155+
return Commit(self.repo, hex_to_bin(hexsha))
155156

156157
return self.from_path(self.repo, target_ref_path).commit
157158

@@ -402,9 +403,9 @@ def rename(self, new_path, force=False):
402403
os.remove(new_abs_path)
403404
# END handle existing target file
404405

405-
dirname = dirname(new_abs_path)
406-
if not isdir(dirname):
407-
os.makedirs(dirname)
406+
dname = dirname(new_abs_path)
407+
if not isdir(dname):
408+
os.makedirs(dname)
408409
# END create directory
409410

410411
rename(cur_abs_path, new_abs_path)

‎lib/git/remote.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
TagReference
2222
)
2323

24-
from gitdb.util import join
24+
from gitdb.util import (
25+
join,
26+
)
2527
import re
2628

2729
__all__ = ('RemoteProgress', 'PushInfo', 'FetchInfo', 'Remote')
@@ -256,7 +258,8 @@ def _from_line(cls, remote, line):
256258
if control_character == " ":
257259
split_token = ".."
258260
old_sha, new_sha = summary.split(' ')[0].split(split_token)
259-
old_commit = Commit(remote.repo, old_sha)
261+
# have to use constructor here as the sha usually is abbreviated
262+
old_commit = remote.repo.commit(old_sha)
260263
# END message handling
261264

262265
return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary)

‎lib/git/repo.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from gitdb.util import (
2222
join,
2323
isdir,
24-
isfile
24+
isfile,
25+
hex_to_bin
2526
)
2627
import os
2728
import sys
@@ -576,7 +577,7 @@ def blame(self, rev, file):
576577
sha = info['id']
577578
c = commits.get(sha)
578579
if c is None:
579-
c = Commit( self, sha,
580+
c = Commit( self, hex_to_bin(sha),
580581
author=Actor._from_string(info['author'] + ' ' + info['author_email']),
581582
authored_date=info['author_date'],
582583
committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']),

‎lib/git/utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
to_bin_sha
1919
)
2020

21+
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
22+
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
23+
"BlockingLockFile", "LockFile" )
2124

2225
def stream_copy(source, destination, chunk_size=512*1024):
2326
"""Copy all data from the source stream into the destination stream in chunks
@@ -104,7 +107,7 @@ def _list_from_string(cls, repo, text):
104107
"""Create a Stat object from output retrieved by git-diff.
105108
106109
:return: git.Stat"""
107-
hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': {}}
110+
hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': dict()}
108111
for line in text.splitlines():
109112
(raw_insertions, raw_deletions, filename) = line.split("\t")
110113
insertions = raw_insertions != '-' and int(raw_insertions) or 0
@@ -305,6 +308,7 @@ def __getitem__(self, index):
305308
except AttributeError:
306309
raise IndexError( "No item found with id %r" % (self._prefix + index) )
307310

311+
308312
class Iterable(object):
309313
"""Defines an interface for iterable items which is to assure a uniform
310314
way to retrieve and iterate items within the git repository"""

‎test/fixtures/diff_new_mode

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
diff --git a/conf/global_settings.py b/conf/global_settings.py
22
old mode 100644
33
new mode 100755
4-
index 9ec1bac..1c4f83b
4+
index 9ec1bac000000000000000000000000000000000..1c4f83b000000000000000000000000000000000
55
--- a/conf/global_settings.py
66
+++ b/conf/global_settings.py
77
@@ -58,6 +58,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (

0 commit comments

Comments
 (0)