unpack-trees: add the dry_run flag to unpack_trees_options

Until now there was no way to test if unpack_trees() with update=1 would succeed without really updating the work tree. The reason for that is that setting update to 0 does skip the tests for new files and deactivates the sparse handling, thereby making that unsuitable as a dry run. Add the new dry_run flag to struct unpack_trees_options unpack_trees(). Setting that together with the update flag will check if the work tree update would be successful without doing it for real. The only class of problems that is not detected at the moment are file system conditions like ENOSPC or missing permissions. Also the index entries of updated files are not as they would be after a real checkout because lstat() isn't run as the files aren't updated for real. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed May 25, 2011 at 22:07 UTC 2c9078d05bf2200c9671e0b292638d42e7e4fd71
2 files changed +4 -3
unpack-trees.c
+2 -2
@@ -203,7 +203,7 @@ static int check_updates(struct unpack_trees_options *o)
203
204 if (ce->ce_flags & CE_WT_REMOVE) {
205 display_progress(progress, ++cnt);
206 - if (o->update)
206 + if (o->update && !o->dry_run)
207 unlink_entry(ce);
208 continue;
209 }
@@ -217,7 +217,7 @@ static int check_updates(struct unpack_trees_options *o)
217 if (ce->ce_flags & CE_UPDATE) {
218 display_progress(progress, ++cnt);
219 ce->ce_flags &= ~CE_UPDATE;
220 - if (o->update) {
220 + if (o->update && !o->dry_run) {
221 errs |= checkout_entry(ce, &state, NULL);
222 }
223 }
unpack-trees.h
+2 -1
@@ -46,7 +46,8 @@ struct unpack_trees_options {
46 debug_unpack,
47 skip_sparse_checkout,
48 gently,
49 - show_all_errors;
49 + show_all_errors,
50 + dry_run;
51 const char *prefix;
52 int cache_bottom;
53 struct dir_struct *dir;