Merge branch 'submodule' · gitpython-developers/GitPython@f1545bd · GitHub
Skip to content

Commit f1545bd

Browse files
committed
Merge branch 'submodule'
2 parents a1d1d2c + 7cf2d5f commit f1545bd

29 files changed

Lines changed: 2094 additions & 187 deletions

lib/git/config.py

Lines changed: 54 additions & 18 deletions

lib/git/ext/gitdb

Submodule gitdb updated from 78665b1 to 2ddc5ba

lib/git/index/base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
)
3636

3737
from git.objects import (
38-
Blob,
38+
Blob,
39+
Submodule,
3940
Tree,
4041
Object,
4142
Commit,
@@ -553,7 +554,7 @@ def _preprocess_add_items(self, items):
553554
for item in items:
554555
if isinstance(item, basestring):
555556
paths.append(self._to_relative_path(item))
556-
elif isinstance(item, Blob):
557+
elif isinstance(item, (Blob, Submodule)):
557558
entries.append(BaseIndexEntry.from_blob(item))
558559
elif isinstance(item, BaseIndexEntry):
559560
entries.append(item)
@@ -588,7 +589,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
588589
589590
They are added at stage 0
590591
591-
- Blob object
592+
- Blob or Submodule object
592593
Blobs are added as they are assuming a valid mode is set.
593594
The file they refer to may or may not exist in the file system, but
594595
must be a path relative to our repository.
@@ -612,6 +613,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
612613
explicitly set. Please note that Index Entries require binary sha's.
613614
614615
:param force:
616+
**CURRENTLY INEFFECTIVE**
615617
If True, otherwise ignored or excluded files will be
616618
added anyway.
617619
As opposed to the git-add command, we enable this flag by default
@@ -748,7 +750,7 @@ def _items_to_rela_paths(self, items):
748750
may be absolute or relative paths, entries or blobs"""
749751
paths = list()
750752
for item in items:
751-
if isinstance(item, (BaseIndexEntry,Blob)):
753+
if isinstance(item, (BaseIndexEntry,(Blob, Submodule))):
752754
paths.append(self._to_relative_path(item.path))
753755
elif isinstance(item, basestring):
754756
paths.append(self._to_relative_path(item))
@@ -775,7 +777,7 @@ def remove(self, items, working_tree=False, **kwargs):
775777
776778
The path string may include globs, such as *.c.
777779
778-
- Blob object
780+
- Blob Object
779781
Only the path portion is used in this case.
780782
781783
- BaseIndexEntry or compatible type

lib/git/index/fun.py

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
CE_NAMEMASK,
3131
CE_STAGESHIFT
3232
)
33+
CE_NAMEMASK_INV = ~CE_NAMEMASK
3334

3435
from util import (
3536
pack,
@@ -53,22 +54,6 @@ def stat_mode_to_index_mode(mode):
5354
return S_IFREG | 0644 | (mode & 0100) # blobs with or without executable bit
5455

5556

56-
def write_cache_entry(entry, stream):
57-
"""Write the given entry to the stream"""
58-
beginoffset = stream.tell()
59-
write = stream.write
60-
write(entry[4]) # ctime
61-
write(entry[5]) # mtime
62-
path = entry[3]
63-
plen = len(path) & CE_NAMEMASK # path length
64-
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
65-
flags = plen | entry[2]
66-
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
67-
entry[8], entry[9], entry[10], entry[1], flags))
68-
write(path)
69-
real_size = ((stream.tell() - beginoffset + 8) & ~7)
70-
write("\0" * ((beginoffset + real_size) - stream.tell()))
71-
7257
def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer):
7358
"""Write the cache represented by entries to a stream
7459
@@ -83,15 +68,29 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
8368
a 4 byte identifier, followed by its size ( 4 bytes )"""
8469
# wrap the stream into a compatible writer
8570
stream = ShaStreamCls(stream)
71+
72+
tell = stream.tell
73+
write = stream.write
8674

8775
# header
8876
version = 2
89-
stream.write("DIRC")
90-
stream.write(pack(">LL", version, len(entries)))
77+
write("DIRC")
78+
write(pack(">LL", version, len(entries)))
9179

9280
# body
9381
for entry in entries:
94-
write_cache_entry(entry, stream)
82+
beginoffset = tell()
83+
write(entry[4]) # ctime
84+
write(entry[5]) # mtime
85+
path = entry[3]
86+
plen = len(path) & CE_NAMEMASK # path length
87+
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
88+
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
89+
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
90+
entry[8], entry[9], entry[10], entry[1], flags))
91+
write(path)
92+
real_size = ((tell() - beginoffset + 8) & ~7)
93+
write("\0" * ((beginoffset + real_size) - tell()))
9594
# END for each entry
9695

9796
# write previously cached extensions data
@@ -101,21 +100,6 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
101100
# write the sha over the content
102101
stream.write_sha()
103102

104-
def read_entry(stream):
105-
"""Return: One entry of the given stream"""
106-
beginoffset = stream.tell()
107-
read = stream.read
108-
ctime = unpack(">8s", read(8))[0]
109-
mtime = unpack(">8s", read(8))[0]
110-
(dev, ino, mode, uid, gid, size, sha, flags) = \
111-
unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2))
112-
path_size = flags & CE_NAMEMASK
113-
path = read(path_size)
114-
115-
real_size = ((stream.tell() - beginoffset + 8) & ~7)
116-
data = read((beginoffset + real_size) - stream.tell())
117-
return IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size))
118-
119103
def read_header(stream):
120104
"""Return tuple(version_long, num_entries) from the given stream"""
121105
type_id = stream.read(4)
@@ -147,10 +131,23 @@ def read_cache(stream):
147131
version, num_entries = read_header(stream)
148132
count = 0
149133
entries = dict()
134+
135+
read = stream.read
136+
tell = stream.tell
150137
while count < num_entries:
151-
entry = read_entry(stream)
138+
beginoffset = tell()
139+
ctime = unpack(">8s", read(8))[0]
140+
mtime = unpack(">8s", read(8))[0]
141+
(dev, ino, mode, uid, gid, size, sha, flags) = \
142+
unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2))
143+
path_size = flags & CE_NAMEMASK
144+
path = read(path_size)
145+
146+
real_size = ((tell() - beginoffset + 8) & ~7)
147+
data = read((beginoffset + real_size) - tell())
148+
entry = IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size))
152149
# entry_key would be the method to use, but we safe the effort
153-
entries[(entry.path, entry.stage)] = entry
150+
entries[(path, entry.stage)] = entry
154151
count += 1
155152
# END for each entry
156153

lib/git/objects/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
"""
44
import inspect
55
from base import *
6+
# Fix import dependency - add IndexObject to the util module, so that it can be
7+
# imported by the submodule.base
8+
import submodule.util
9+
submodule.util.IndexObject = IndexObject
10+
from submodule.base import *
11+
from submodule.root import *
12+
13+
# must come after submodule was made available
614
from tag import *
715
from blob import *
8-
from tree import *
916
from commit import *
10-
from submodule import *
17+
from tree import *
1118
from util import Actor
1219

1320
__all__ = [ name for name, obj in locals().items()

lib/git/objects/base.py

Lines changed: 8 additions & 13 deletions

0 commit comments

Comments
 (0)