core: Improve checkout API
Expose the lower-level functionality in libostree, change checkout builtin to be a higher level driver. This will allow us to more easily improve the "checkout" builtin..
This commit is contained in:
parent
f44b8aca44
commit
1f7d776a18
|
|
@ -2486,14 +2486,14 @@ checkout_file_from_input (GFile *file,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
checkout_tree (OstreeRepo *self,
|
||||
OstreeRepoCheckoutMode mode,
|
||||
GFile *destination,
|
||||
OstreeRepoFile *source,
|
||||
GFileInfo *source_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
gboolean
|
||||
ostree_repo_checkout_tree (OstreeRepo *self,
|
||||
OstreeRepoCheckoutMode mode,
|
||||
GFile *destination,
|
||||
OstreeRepoFile *source,
|
||||
GFileInfo *source_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||
gboolean ret = FALSE;
|
||||
|
|
@ -2541,7 +2541,8 @@ checkout_tree (OstreeRepo *self,
|
|||
|
||||
if (type == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
if (!checkout_tree (self, mode, dest_path, (OstreeRepoFile*)src_child, file_info, cancellable, error))
|
||||
if (!ostree_repo_checkout_tree (self, mode, dest_path, (OstreeRepoFile*)src_child, file_info,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
|
|
@ -2620,43 +2621,6 @@ checkout_tree (OstreeRepo *self,
|
|||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_checkout (OstreeRepo *self,
|
||||
OstreeRepoCheckoutMode mode,
|
||||
const char *ref,
|
||||
GFile *destination,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
char *resolved = NULL;
|
||||
OstreeRepoFile *root = NULL;
|
||||
GFileInfo *root_info = NULL;
|
||||
|
||||
if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved, error))
|
||||
goto out;
|
||||
|
||||
root = (OstreeRepoFile*)ostree_repo_file_new_root (self, resolved);
|
||||
if (!ostree_repo_file_ensure_resolved (root, error))
|
||||
goto out;
|
||||
|
||||
root_info = g_file_query_info ((GFile*)root, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
NULL, error);
|
||||
if (!root_info)
|
||||
goto out;
|
||||
|
||||
if (!checkout_tree (self, mode, destination, root, root_info, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_free (resolved);
|
||||
g_clear_object (&root);
|
||||
g_clear_object (&root_info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_file_checksum (GFile *f,
|
||||
GFileInfo *f_info,
|
||||
|
|
|
|||
|
|
@ -205,12 +205,14 @@ typedef enum {
|
|||
OSTREE_REPO_CHECKOUT_MODE_USER
|
||||
} OstreeRepoCheckoutMode;
|
||||
|
||||
gboolean ostree_repo_checkout (OstreeRepo *self,
|
||||
OstreeRepoCheckoutMode mode,
|
||||
const char *ref,
|
||||
GFile *destination,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean
|
||||
ostree_repo_checkout_tree (OstreeRepo *self,
|
||||
OstreeRepoCheckoutMode mode,
|
||||
GFile *destination,
|
||||
OstreeRepoFile *source,
|
||||
GFileInfo *source_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_read_commit (OstreeRepo *self,
|
||||
const char *rev,
|
||||
|
|
|
|||
|
|
@ -38,10 +38,14 @@ gboolean
|
|||
ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error)
|
||||
{
|
||||
GOptionContext *context;
|
||||
GCancellable *cancellable = NULL;
|
||||
gboolean ret = FALSE;
|
||||
OstreeRepo *repo = NULL;
|
||||
const char *commit;
|
||||
char *resolved_commit = NULL;
|
||||
const char *destination;
|
||||
OstreeRepoFile *root = NULL;
|
||||
GFileInfo *root_info = NULL;
|
||||
GFile *destf = NULL;
|
||||
|
||||
context = g_option_context_new ("COMMIT DESTINATION - Check out a commit into a filesystem tree");
|
||||
|
|
@ -68,16 +72,32 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
|
|||
destination = argv[2];
|
||||
|
||||
destf = ot_gfile_new_for_path (destination);
|
||||
|
||||
if (!ostree_repo_checkout (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
||||
commit, destf, NULL, error))
|
||||
|
||||
if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error))
|
||||
goto out;
|
||||
|
||||
root = (OstreeRepoFile*)ostree_repo_file_new_root (repo, resolved_commit);
|
||||
if (!ostree_repo_file_ensure_resolved (root, error))
|
||||
goto out;
|
||||
|
||||
root_info = g_file_query_info ((GFile*)root, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
if (!root_info)
|
||||
goto out;
|
||||
|
||||
if (!ostree_repo_checkout_tree (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
||||
destf, root, root_info, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_free (resolved_commit);
|
||||
if (context)
|
||||
g_option_context_free (context);
|
||||
g_clear_object (&repo);
|
||||
g_clear_object (&destf);
|
||||
g_clear_object (&root);
|
||||
g_clear_object (&root_info);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue