12
12
import glob
13
13
from cStringIO import StringIO
14
14
15
- from stat import (
16
- S_ISLNK ,
17
- S_ISDIR ,
18
- S_IFMT ,
19
- S_IFDIR ,
20
- S_IFLNK ,
21
- S_IFREG
22
- )
15
+ from stat import S_ISLNK
23
16
24
17
from typ import (
25
18
BaseIndexEntry ,
65
58
write_cache ,
66
59
read_cache ,
67
60
aggressive_tree_merge ,
68
- write_tree_from_cache
61
+ write_tree_from_cache ,
62
+ stat_mode_to_index_mode ,
63
+ S_IFGITLINK
69
64
)
70
65
71
66
from gitdb .base import IStream
@@ -99,7 +94,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
99
94
before operating on it using the git command"""
100
95
__slots__ = ("repo" , "version" , "entries" , "_extension_data" , "_file_path" )
101
96
_VERSION = 2 # latest version we support
102
- S_IFGITLINK = 0160000 # a submodule
97
+ S_IFGITLINK = S_IFGITLINK # a submodule
103
98
104
99
def __init__ (self , repo , file_path = None ):
105
100
"""Initialize this Index instance, optionally from the given ``file_path``.
@@ -350,16 +345,6 @@ def from_tree(cls, repo, *treeish, **kwargs):
350
345
351
346
return index
352
347
353
- @classmethod
354
- def _stat_mode_to_index_mode (cls , mode ):
355
- """Convert the given mode from a stat call to the corresponding index mode
356
- and return it"""
357
- if S_ISLNK (mode ): # symlinks
358
- return S_IFLNK
359
- if S_ISDIR (mode ) or S_IFMT (mode ) == cls .S_IFGITLINK : # submodules
360
- return cls .S_IFGITLINK
361
- return S_IFREG | 0644 | (mode & 0100 ) # blobs with or without executable bit
362
-
363
348
# UTILITIES
364
349
def _iter_expand_paths (self , paths ):
365
350
"""Expand the directories in list of paths to the corresponding paths accordingly,
@@ -437,8 +422,8 @@ def iter_blobs(self, predicate = lambda t: True):
437
422
for entry in self .entries .itervalues ():
438
423
# TODO: is it necessary to convert the mode ? We did that when adding
439
424
# it to the index, right ?
440
- mode = self . _stat_mode_to_index_mode (entry .mode )
441
- blob = Blob (self .repo , entry . binsha , mode , entry . path )
425
+ mode = stat_mode_to_index_mode (entry .mode )
426
+ blob = entry . to_blob (self .repo )
442
427
blob .size = entry .size
443
428
output = (entry .stage , blob )
444
429
if predicate (output ):
@@ -672,7 +657,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
672
657
abspath = os .path .abspath (path )
673
658
gitrelative_path = abspath [len (self .repo .working_tree_dir )+ 1 :]
674
659
blob = Blob (self .repo , Blob .NULL_BIN_SHA ,
675
- self . _stat_mode_to_index_mode (os .stat (abspath ).st_mode ),
660
+ stat_mode_to_index_mode (os .stat (abspath ).st_mode ),
676
661
to_native_path_linux (gitrelative_path ))
677
662
entries .append (BaseIndexEntry .from_blob (blob ))
678
663
# END for each path
@@ -692,7 +677,7 @@ def store_path(filepath):
692
677
fprogress (filepath , False , filepath )
693
678
istream = self .repo .odb .store (IStream (Blob .type , st .st_size , stream ))
694
679
fprogress (filepath , True , filepath )
695
- return BaseIndexEntry ((self . _stat_mode_to_index_mode (st .st_mode ),
680
+ return BaseIndexEntry ((stat_mode_to_index_mode (st .st_mode ),
696
681
istream .binsha , 0 , to_native_path_linux (filepath )))
697
682
# END utility method
698
683
0 commit comments