diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-11-23 23:20:11 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-11-23 23:20:11 +0100 |
commit | 7029773512eee5a0bb765b82cfdd90fd5ab34e15 (patch) | |
tree | 945d209ed7437820ee13e1bb1d617c9ffd922f2f /util.py | |
parent | 61f3db7bd07ac2f3c2ff54615c13bf9219289932 (diff) | |
download | gitpython-7029773512eee5a0bb765b82cfdd90fd5ab34e15.tar.gz |
Implemented revlog.append_entry as classmethod, to assure we will always actually write_append the new entry, instead of rewriting the whole file. Added file-locking and directory handling, so the implementation should be similar (enough) to the git reference implementation.
Next up is to implement a way to update the reflog when changing references, which is going to be a little more complicated
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -22,7 +22,7 @@ from gitdb.util import ( __all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", - "BlockingLockFile", "LockFile", 'Actor', 'get_user_id' ) + "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists') #{ Utility Methods @@ -73,6 +73,20 @@ def join_path_native(a, *p): needed to play it safe on my dear windows and to assure nice paths that only use '\'""" return to_native_path(join_path(a, *p)) + +def assure_directory_exists(path, is_file=False): + """Assure that the directory pointed to by path exists. + :param is_file: If True, path is assumed to be a file and handled correctly. + Otherwise it must be a directory + :return: True if the directory was created, False if it already existed""" + if is_file: + path = os.path.dirname(path) + #END handle file + if not os.path.isdir(path): + os.makedirs(path) + return True + return False + def get_user_id(): """:return: string identifying the currently active system user as name@node |