summaryrefslogtreecommitdiff
path: root/src/ostree/ot-builtin-pull.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2016-02-11 13:28:03 -0500
committerColin Walters <walters@verbum.org>2016-02-14 10:12:26 -0500
commit42c60effbe5037d674ce4b84979ccaf91edfad48 (patch)
tree87d66e1b3dc538f76819b41ad0cfa7c8d03de956 /src/ostree/ot-builtin-pull.c
parent355f8438ef4fe2720d25e8241aa76797b7029522 (diff)
downloadostree-42c60effbe5037d674ce4b84979ccaf91edfad48.tar.gz
pull: Support specifying exact commit to pull via branch@commit
I don't know why we didn't do this a long time ago. This extends the pull API to allow grabbing a specific commit, and will set the branch to it. There's some support for this in the deploy engine, but there are a lot of reasons to support it for raw pulls (such as subset mirroring cases). In fact I'm thinking we should also have the override-version logic here too. NOTE: One thing I debated here is inventing a new syntax on the command line. Git doesn't seem to have this functionality (probably because it'd be rarely used). The '@' character at least doesn't conflict with anything. Anyways, I wanted this for some other test cases. Without this, writing tests that go between different commits is more awkward as one must generate the content in one repo, then pull downstream, then generate more content, then pull again. But now I can just keep track of commit IDs and do exactly what I want without synchronizing the tests.
Diffstat (limited to 'src/ostree/ot-builtin-pull.c')
-rw-r--r--src/ostree/ot-builtin-pull.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 6aae8205..63dbc768 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -34,7 +34,7 @@ static gboolean opt_disable_static_deltas;
static char* opt_subpath;
static int opt_depth = 0;
- static GOptionEntry options[] = {
+static GOptionEntry options[] = {
{ "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Fetch only the commit metadata", NULL },
{ "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
{ "disable-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_disable_static_deltas, "Do not use static deltas", NULL },
@@ -70,6 +70,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
OstreeRepoPullFlags pullflags = 0;
GSConsole *console = NULL;
g_autoptr(GPtrArray) refs_to_fetch = NULL;
+ g_autoptr(GPtrArray) override_commit_ids = NULL;
glnx_unref_object OstreeAsyncProgress *progress = NULL;
gulong signal_handler_id = 0;
@@ -102,9 +103,36 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
if (argc > 2)
{
int i;
- refs_to_fetch = g_ptr_array_new ();
+ refs_to_fetch = g_ptr_array_new_with_free_func (g_free);
+
for (i = 2; i < argc; i++)
- g_ptr_array_add (refs_to_fetch, argv[i]);
+ {
+ const char *at = strrchr (argv[i], '@');
+
+ if (at)
+ {
+ guint j;
+ const char *override_commit_id = at + 1;
+
+ if (!ostree_validate_checksum_string (override_commit_id, error))
+ goto out;
+
+ if (!override_commit_ids)
+ override_commit_ids = g_ptr_array_new_with_free_func (g_free);
+
+ /* Backfill */
+ for (j = 2; j < i; i++)
+ g_ptr_array_add (override_commit_ids, g_strdup (""));
+
+ g_ptr_array_add (override_commit_ids, g_strdup (override_commit_id));
+ g_ptr_array_add (refs_to_fetch, g_strndup (argv[i], at - argv[i]));
+ }
+ else
+ {
+ g_ptr_array_add (refs_to_fetch, g_strdup (argv[i]));
+ }
+ }
+
g_ptr_array_add (refs_to_fetch, NULL);
}
}
@@ -147,6 +175,10 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
g_variant_builder_add (&builder, "{s@v}", "disable-static-deltas",
g_variant_new_variant (g_variant_new_boolean (opt_disable_static_deltas)));
+ if (override_commit_ids)
+ g_variant_builder_add (&builder, "{s@v}", "override-commit-ids",
+ g_variant_new_variant (g_variant_new_strv ((const char*const*)override_commit_ids->pdata, override_commit_ids->len)));
+
if (!ostree_repo_pull_with_options (repo, remote, g_variant_builder_end (&builder),
progress, cancellable, error))
goto out;