[ostree: 13/70] commit: Support generating commits with no parent, or a custom one



commit c6b4ecd474257fa192743096a8dc94f6ae1e7be7
Author: Colin Walters <walters verbum org>
Date:   Fri Mar 25 11:03:32 2016 -0400

    commit: Support generating commits with no parent, or a custom one
    
    When I'm doing local development builds, it's quite common for me not
    to want to accumulate history.  There are also use cases for this on
    build servers as well.
    
    In particular, using this, one could write a build system that didn't
    necessarily need to have access to (a copy of) the OSTree repository.
    Instead, the build system would determine the last commit ID on the
    branch, and pass that to a worker node, then sync the generated
    content back.
    
    The API supported generating custom commits that don't necessarily
    reference the previous commit on the same branch, let's just expose
    this in the command line for convenience.
    
    I plan to also support this rpm-ostree.
    
    Closes: #223
    Approved by: jlebon

 src/ostree/ot-builtin-commit.c |   20 ++++++++++++++++++--
 tests/basic-test.sh            |   19 ++++++++++++++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 72b83bf..517ea70 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -32,6 +32,7 @@
 
 static char *opt_subject;
 static char *opt_body;
+static char *opt_parent;
 static char *opt_branch;
 static char *opt_statoverride_file;
 static char **opt_metadata_strings;
@@ -67,6 +68,7 @@ parse_fsync_cb (const char  *option_name,
 }
 
 static GOptionEntry options[] = {
+  { "parent", 0, 0, G_OPTION_ARG_STRING, &opt_parent, "Parent ref, or \"none\"", "REF" },
   { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" },
   { "body", 'm', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" },
   { "branch", 'b', 0, G_OPTION_ARG_STRING, &opt_branch, "Branch", "BRANCH" },
@@ -361,8 +363,22 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
       modifier = ostree_repo_commit_modifier_new (flags, commit_filter, mode_adds, NULL);
     }
 
-  if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
-    goto out;
+  if (opt_parent)
+    {
+      if (g_str_equal (opt_parent, "none"))
+        parent = NULL;
+      else
+        {
+          if (!ostree_validate_checksum_string (opt_parent, error))
+            goto out;
+          parent = g_strdup (opt_parent);
+        }
+    }
+  else
+    {
+      if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
+        goto out;
+    }
 
   if (!opt_subject && !opt_body)
     {
diff --git a/tests/basic-test.sh b/tests/basic-test.sh
index 8acec1c..4b46fc1 100755
--- a/tests/basic-test.sh
+++ b/tests/basic-test.sh
@@ -19,7 +19,7 @@
 
 set -euo pipefail
 
-echo "1..50"
+echo "1..52"
 
 $OSTREE checkout test2 checkout-test2
 echo "ok checkout"
@@ -97,6 +97,23 @@ assert_file_has_content four '4'
 echo "ok cwd contents"
 
 cd ${test_tmpdir}
+$OSTREE commit -b test2-no-parent -s '' $test_tmpdir/checkout-test2-4
+assert_streq $($OSTREE log test2-no-parent |grep '^commit' | wc -l) "1"
+$OSTREE commit -b test2-no-parent -s '' --parent=none $test_tmpdir/checkout-test2-4
+assert_streq $($OSTREE log test2-no-parent |grep '^commit' | wc -l) "1"
+echo "ok commit no parent"
+
+cd ${test_tmpdir}
+$OSTREE commit -b test2-custom-parent -s '' $test_tmpdir/checkout-test2-4
+$OSTREE commit -b test2-custom-parent -s '' $test_tmpdir/checkout-test2-4
+$OSTREE commit -b test2-custom-parent -s '' $test_tmpdir/checkout-test2-4
+assert_streq $($OSTREE log test2-custom-parent |grep '^commit' | wc -l) "3"
+prevparent=$($OSTREE rev-parse test2-custom-parent^)
+$OSTREE commit -b test2-custom-parent -s '' --parent=${prevparent} $test_tmpdir/checkout-test2-4
+assert_streq $($OSTREE log test2-custom-parent |grep '^commit' | wc -l) "3"
+echo "ok commit custom parent"
+
+cd ${test_tmpdir}
 $OSTREE diff test2^ test2 > diff-test2
 assert_file_has_content diff-test2 'D */a/5'
 assert_file_has_content diff-test2 'A */yet$'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]