Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d4138c

Browse files
committed
Refactored the working tree dependent code for add.
Adding to a bare repository is now possible because @git_working_diris only used on the relevant methods.
1 parentf913337 commit4d4138c

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

‎git/index/base.py

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,48 @@ def _preprocess_add_items(self, items):
562562
# END for each item
563563
return (paths,entries)
564564

565+
566+
@git_working_dir
567+
def_store_path(self,filepath,fprogress):
568+
"""Store file at filepath in the database and return the base index entry"""
569+
st=os.lstat(filepath)# handles non-symlinks as well
570+
stream=None
571+
ifS_ISLNK(st.st_mode):
572+
stream=StringIO(os.readlink(filepath))
573+
else:
574+
stream=open(filepath,'rb')
575+
# END handle stream
576+
fprogress(filepath,False,filepath)
577+
istream=self.repo.odb.store(IStream(Blob.type,st.st_size,stream))
578+
fprogress(filepath,True,filepath)
579+
returnBaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
580+
istream.binsha,0,to_native_path_linux(filepath)))
581+
565582
@git_working_dir
583+
def_entries_for_paths(self,paths,path_rewriter,fprogress):
584+
entries_added=list()
585+
ifpath_rewriter:
586+
forpathinpaths:
587+
abspath=os.path.abspath(path)
588+
gitrelative_path=abspath[len(self.repo.working_tree_dir)+1:]
589+
blob=Blob(self.repo,Blob.NULL_BIN_SHA,
590+
stat_mode_to_index_mode(os.stat(abspath).st_mode),
591+
to_native_path_linux(gitrelative_path))
592+
entries.append(BaseIndexEntry.from_blob(blob))
593+
# END for each path
594+
del(paths[:])
595+
# END rewrite paths
596+
597+
# HANDLE PATHS
598+
assertlen(entries_added)==0
599+
added_files=list()
600+
forfilepathinself._iter_expand_paths(paths):
601+
entries_added.append(self._store_path(filepath,fprogress))
602+
# END for each filepath
603+
# END path handling
604+
returnentries_added
605+
606+
566607
defadd(self,items,force=True,fprogress=lambda*args:None,path_rewriter=None,
567608
write=True):
568609
"""Add files from the working tree, specific blobs or BaseIndexEntries
@@ -651,47 +692,10 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
651692
# sort the entries into strings and Entries, Blobs are converted to entries
652693
# automatically
653694
# paths can be git-added, for everything else we use git-update-index
654-
entries_added=list()
655695
paths,entries=self._preprocess_add_items(items)
656-
ifpathsandpath_rewriter:
657-
forpathinpaths:
658-
abspath=os.path.abspath(path)
659-
gitrelative_path=abspath[len(self.repo.working_tree_dir)+1:]
660-
blob=Blob(self.repo,Blob.NULL_BIN_SHA,
661-
stat_mode_to_index_mode(os.stat(abspath).st_mode),
662-
to_native_path_linux(gitrelative_path))
663-
entries.append(BaseIndexEntry.from_blob(blob))
664-
# END for each path
665-
del(paths[:])
666-
# END rewrite paths
667-
668-
669-
defstore_path(filepath):
670-
"""Store file at filepath in the database and return the base index entry"""
671-
st=os.lstat(filepath)# handles non-symlinks as well
672-
stream=None
673-
ifS_ISLNK(st.st_mode):
674-
stream=StringIO(os.readlink(filepath))
675-
else:
676-
stream=open(filepath,'rb')
677-
# END handle stream
678-
fprogress(filepath,False,filepath)
679-
istream=self.repo.odb.store(IStream(Blob.type,st.st_size,stream))
680-
fprogress(filepath,True,filepath)
681-
returnBaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
682-
istream.binsha,0,to_native_path_linux(filepath)))
683-
# END utility method
684-
685-
686-
# HANDLE PATHS
696+
entries_added=list()
687697
ifpaths:
688-
assertlen(entries_added)==0
689-
added_files=list()
690-
forfilepathinself._iter_expand_paths(paths):
691-
entries_added.append(store_path(filepath))
692-
# END for each filepath
693-
# END path handling
694-
698+
entries_added.extend(self._entries_for_paths(paths,path_rewriter,fprogress))
695699

696700
# HANDLE ENTRIES
697701
ifentries:
@@ -706,7 +710,7 @@ def store_path(filepath):
706710
ifnull_entries_indices:
707711
foreiinnull_entries_indices:
708712
null_entry=entries[ei]
709-
new_entry=store_path(null_entry.path)
713+
new_entry=self._store_path(null_entry.path,fprogress)
710714

711715
# update null entry
712716
entries[ei]=BaseIndexEntry((null_entry.mode,new_entry.binsha,null_entry.stage,null_entry.path))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp