From 192472f9673b18c91ce618e64e935f91769c50e7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Jul 2010 16:18:01 +0200 Subject: BaseIndexEntry: Added to_blob method, refactored functionality sligthly repo.clone: assured backslashes won't reach the remote configuration, as it can cause trouble when re-reading the file later on. Some git commands don't appear to be able to properly deal with backslashes, other's do --- lib/git/index/fun.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/git/index/fun.py') diff --git a/lib/git/index/fun.py b/lib/git/index/fun.py index 4478228a..48c4fa74 100644 --- a/lib/git/index/fun.py +++ b/lib/git/index/fun.py @@ -2,7 +2,18 @@ Contains standalone functions to accompany the index implementation and make it more versatile """ -from stat import S_IFDIR +from stat import ( + S_IFDIR, + S_IFLNK, + S_ISLNK, + S_IFDIR, + S_ISDIR, + S_IFMT, + S_IFREG, + ) + +S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule + from cStringIO import StringIO from git.util import IndexFileSHA1Writer @@ -28,7 +39,19 @@ from util import ( from gitdb.base import IStream from gitdb.typ import str_tree_type -__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key' ) +__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key', + 'stat_mode_to_index_mode', 'S_IFGITLINK') + + +def stat_mode_to_index_mode(mode): + """Convert the given mode from a stat call to the corresponding index mode + and return it""" + if S_ISLNK(mode): # symlinks + return S_IFLNK + if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules + return S_IFGITLINK + return S_IFREG | 0644 | (mode & 0100) # blobs with or without executable bit + def write_cache_entry(entry, stream): """Write the given entry to the stream""" -- cgit v1.2.1