diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt index f5abbd57..1e4a6f54 100644 --- a/doc/ostree-sections.txt +++ b/doc/ostree-sections.txt @@ -64,6 +64,7 @@ ostree_repo_copy_config ostree_repo_get_parent ostree_repo_write_config OstreeRepoTransactionStats +ostree_repo_scan_hardlinks ostree_repo_prepare_transaction ostree_repo_commit_transaction ostree_repo_abort_transaction diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 8b69e48e..32b0e2e8 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -524,10 +524,46 @@ devino_cache_lookup (OstreeRepo *self, return g_hash_table_lookup (self->loose_object_devino_hash, &dev_ino); } +/** + * ostree_repo_scan_hardlinks: + * @self: An #OstreeRepo + * @cancellable: Cancellable + * @error: Error + * + * When ostree builds a mutable tree from directory like in + * ostree_repo_write_directory_to_mtree(), it has to scan all files that you + * pass in and compute their checksums. If your commit contains hardlinks from + * ostree's existing repo, ostree can build a mapping of device numbers and + * inodes to their checksum. + * + * There is an upfront cost to creating this mapping, as this will scan the + * entire objects directory. If your commit is composed of mostly hardlinks to + * existing ostree objects, then this will speed up considerably, so call it + * before you call ostree_write_directory_to_mtree() or similar. + */ +gboolean +ostree_repo_scan_hardlinks (OstreeRepo *self, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + + g_return_val_if_fail (self->in_transaction == TRUE, FALSE); + + if (!self->loose_object_devino_hash) + self->loose_object_devino_hash = g_hash_table_new_full (devino_hash, devino_equal, g_free, g_free); + g_hash_table_remove_all (self->loose_object_devino_hash); + if (!scan_loose_devino (self, self->loose_object_devino_hash, cancellable, error)) + goto out; + + ret = TRUE; + out: + return ret; +} + /** * ostree_repo_prepare_transaction: * @self: An #OstreeRepo - * @enable_commit_hardlink_scan: * @out_transaction_resume: (allow-none) (out): Whether this transaction * is resuming from a previous one. * @cancellable: Cancellable @@ -543,7 +579,6 @@ devino_cache_lookup (OstreeRepo *self, */ gboolean ostree_repo_prepare_transaction (OstreeRepo *self, - gboolean enable_commit_hardlink_scan, gboolean *out_transaction_resume, GCancellable *cancellable, GError **error) @@ -575,15 +610,6 @@ ostree_repo_prepare_transaction (OstreeRepo *self, cancellable, error)) goto out; - if (enable_commit_hardlink_scan) - { - if (!self->loose_object_devino_hash) - self->loose_object_devino_hash = g_hash_table_new_full (devino_hash, devino_equal, g_free, g_free); - g_hash_table_remove_all (self->loose_object_devino_hash); - if (!scan_loose_devino (self, self->loose_object_devino_hash, cancellable, error)) - goto out; - } - ret = TRUE; if (out_transaction_resume) *out_transaction_resume = ret_transaction_resume; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 0a42e3f9..d557e420 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -1286,7 +1286,7 @@ ostree_repo_pull (OstreeRepo *self, } } - if (!ostree_repo_prepare_transaction (pull_data->repo, FALSE, &pull_data->transaction_resuming, + if (!ostree_repo_prepare_transaction (pull_data->repo, &pull_data->transaction_resuming, cancellable, error)) goto out; diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 882e3061..8a4c75d8 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -112,8 +112,11 @@ struct _OstreeRepoTransactionStats { GType ostree_repo_transaction_stats_get_type (void); +gboolean ostree_repo_scan_hardlinks (OstreeRepo *self, + GCancellable *cancellable, + GError **error); + gboolean ostree_repo_prepare_transaction (OstreeRepo *self, - gboolean enable_commit_hardlink_scan, gboolean *out_transaction_resume, GCancellable *cancellable, GError **error); diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 80d0e50d..d9ed29dc 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -290,7 +290,10 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca goto out; } - if (!ostree_repo_prepare_transaction (repo, opt_link_checkout_speedup, NULL, cancellable, error)) + if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) + goto out; + + if (opt_link_checkout_speedup && !ostree_repo_scan_hardlinks (repo, cancellable, error)) goto out; mtree = ostree_mutable_tree_new (); diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c index 98ba6cd2..e435457d 100644 --- a/src/ostree/ot-builtin-pull-local.c +++ b/src/ostree/ot-builtin-pull-local.c @@ -230,7 +230,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable } } - if (!ostree_repo_prepare_transaction (data->dest_repo, FALSE, &transaction_resuming, + if (!ostree_repo_prepare_transaction (data->dest_repo, &transaction_resuming, cancellable, error)) goto out;