diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-06 17:56:21 +0000 |
---|---|---|
committer | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2015-01-23 10:04:15 +0000 |
commit | 27863bbea230ef473832656ad4c26fcf878995d1 (patch) | |
tree | 74c93175f28fa8164cf3fcf7713c151fa69ca145 /morphlib/cachedrepo.py | |
parent | a17993010eea9de1774b6912d6a087f0c086291a (diff) | |
download | morph-27863bbea230ef473832656ad4c26fcf878995d1.tar.gz |
Add a mechanism for extracting all files from a given commit to a dir
This is nice because it's fast. We don't have to copy all the Git
history along with it like we do with a clone. And it doesn't touch
any files in the cached repo.
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r-- | morphlib/cachedrepo.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index aa2b5af1..c9a6bb6b 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 Codethink Limited +# Copyright (C) 2012-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,9 @@ import cliapp + import os +import tempfile import morphlib @@ -169,6 +171,29 @@ class CachedRepo(object): self._checkout_ref_in_clone(ref, target_dir) + def extract_commit(self, ref, target_dir): + # FIXME: surely this should do what 'checkout' does, and 'checkout' + # should be called something else? Or maybe there's no speed benefit + # to this function and it shouldn't exist in the first place? Or the + # other 'checkout' shouldn't exist? + '''Extract files from a given commit into target_dir. + + This is different to a 'checkout': a checkout assumes a working tree + associated with a repository. Here, the repository is immutable (it's + in the cache) and we just want to look at the files in a quick way + (quicker than going 'git cat-file everything'). + + This is really fast so it's cool really. + + ''' + if not os.path.exists(target_dir): + os.makedirs(target_dir) + + with tempfile.NamedTemporaryFile() as index_file: + index = self._gitdir.get_index(index_file=index_file.name) + index.set_to_tree(ref) + index.checkout(working_tree=target_dir) + def requires_update_for_ref(self, ref): '''Returns False if there's no need to update this cached repo. |