repo: Move the scanning hardlinks optimization out of prepare_transaction
This is just a terrible API to have. Make the scanning a separate method, and document it as an optimization.
This commit is contained in:
parent
f84504a8c4
commit
bd2948e964
|
|
@ -64,6 +64,7 @@ ostree_repo_copy_config
|
||||||
ostree_repo_get_parent
|
ostree_repo_get_parent
|
||||||
ostree_repo_write_config
|
ostree_repo_write_config
|
||||||
OstreeRepoTransactionStats
|
OstreeRepoTransactionStats
|
||||||
|
ostree_repo_scan_hardlinks
|
||||||
ostree_repo_prepare_transaction
|
ostree_repo_prepare_transaction
|
||||||
ostree_repo_commit_transaction
|
ostree_repo_commit_transaction
|
||||||
ostree_repo_abort_transaction
|
ostree_repo_abort_transaction
|
||||||
|
|
|
||||||
|
|
@ -524,10 +524,46 @@ devino_cache_lookup (OstreeRepo *self,
|
||||||
return g_hash_table_lookup (self->loose_object_devino_hash, &dev_ino);
|
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:
|
* ostree_repo_prepare_transaction:
|
||||||
* @self: An #OstreeRepo
|
* @self: An #OstreeRepo
|
||||||
* @enable_commit_hardlink_scan:
|
|
||||||
* @out_transaction_resume: (allow-none) (out): Whether this transaction
|
* @out_transaction_resume: (allow-none) (out): Whether this transaction
|
||||||
* is resuming from a previous one.
|
* is resuming from a previous one.
|
||||||
* @cancellable: Cancellable
|
* @cancellable: Cancellable
|
||||||
|
|
@ -543,7 +579,6 @@ devino_cache_lookup (OstreeRepo *self,
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_prepare_transaction (OstreeRepo *self,
|
ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
gboolean enable_commit_hardlink_scan,
|
|
||||||
gboolean *out_transaction_resume,
|
gboolean *out_transaction_resume,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
|
@ -575,15 +610,6 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
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;
|
ret = TRUE;
|
||||||
if (out_transaction_resume)
|
if (out_transaction_resume)
|
||||||
*out_transaction_resume = ret_transaction_resume;
|
*out_transaction_resume = ret_transaction_resume;
|
||||||
|
|
|
||||||
|
|
@ -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))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,8 +112,11 @@ struct _OstreeRepoTransactionStats {
|
||||||
|
|
||||||
GType ostree_repo_transaction_stats_get_type (void);
|
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 ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
gboolean enable_commit_hardlink_scan,
|
|
||||||
gboolean *out_transaction_resume,
|
gboolean *out_transaction_resume,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,10 @@ ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
|
||||||
goto out;
|
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;
|
goto out;
|
||||||
|
|
||||||
mtree = ostree_mutable_tree_new ();
|
mtree = ostree_mutable_tree_new ();
|
||||||
|
|
|
||||||
|
|
@ -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))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue