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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
gboolean
|
||||||
checkout_tree (OstreeRepo *self,
|
ostree_repo_checkout_tree (OstreeRepo *self,
|
||||||
OstreeRepoCheckoutMode mode,
|
OstreeRepoCheckoutMode mode,
|
||||||
GFile *destination,
|
GFile *destination,
|
||||||
OstreeRepoFile *source,
|
OstreeRepoFile *source,
|
||||||
GFileInfo *source_info,
|
GFileInfo *source_info,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
@ -2541,7 +2541,8 @@ checkout_tree (OstreeRepo *self,
|
||||||
|
|
||||||
if (type == G_FILE_TYPE_DIRECTORY)
|
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;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -2620,43 +2621,6 @@ checkout_tree (OstreeRepo *self,
|
||||||
return ret;
|
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
|
static gboolean
|
||||||
get_file_checksum (GFile *f,
|
get_file_checksum (GFile *f,
|
||||||
GFileInfo *f_info,
|
GFileInfo *f_info,
|
||||||
|
|
|
||||||
|
|
@ -205,12 +205,14 @@ typedef enum {
|
||||||
OSTREE_REPO_CHECKOUT_MODE_USER
|
OSTREE_REPO_CHECKOUT_MODE_USER
|
||||||
} OstreeRepoCheckoutMode;
|
} OstreeRepoCheckoutMode;
|
||||||
|
|
||||||
gboolean ostree_repo_checkout (OstreeRepo *self,
|
gboolean
|
||||||
OstreeRepoCheckoutMode mode,
|
ostree_repo_checkout_tree (OstreeRepo *self,
|
||||||
const char *ref,
|
OstreeRepoCheckoutMode mode,
|
||||||
GFile *destination,
|
GFile *destination,
|
||||||
GCancellable *cancellable,
|
OstreeRepoFile *source,
|
||||||
GError **error);
|
GFileInfo *source_info,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_repo_read_commit (OstreeRepo *self,
|
gboolean ostree_repo_read_commit (OstreeRepo *self,
|
||||||
const char *rev,
|
const char *rev,
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,14 @@ gboolean
|
||||||
ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error)
|
ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
{
|
{
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
|
GCancellable *cancellable = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
OstreeRepo *repo = NULL;
|
OstreeRepo *repo = NULL;
|
||||||
const char *commit;
|
const char *commit;
|
||||||
|
char *resolved_commit = NULL;
|
||||||
const char *destination;
|
const char *destination;
|
||||||
|
OstreeRepoFile *root = NULL;
|
||||||
|
GFileInfo *root_info = NULL;
|
||||||
GFile *destf = NULL;
|
GFile *destf = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("COMMIT DESTINATION - Check out a commit into a filesystem tree");
|
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];
|
destination = argv[2];
|
||||||
|
|
||||||
destf = ot_gfile_new_for_path (destination);
|
destf = ot_gfile_new_for_path (destination);
|
||||||
|
|
||||||
if (!ostree_repo_checkout (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error))
|
||||||
commit, destf, NULL, 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;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
g_free (resolved_commit);
|
||||||
if (context)
|
if (context)
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
g_clear_object (&repo);
|
g_clear_object (&repo);
|
||||||
g_clear_object (&destf);
|
g_clear_object (&destf);
|
||||||
|
g_clear_object (&root);
|
||||||
|
g_clear_object (&root_info);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue