[ostree] core: remove HEAD file, use branches instead
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: remove HEAD file, use branches instead
- Date: Thu, 27 Oct 2011 18:32:52 +0000 (UTC)
commit 7ca1c3d2e730baa19eb4cbdfb7c43f5016241d27
Author: Colin Walters <walters verbum org>
Date: Thu Oct 27 09:21:07 2011 -0400
core: remove HEAD file, use branches instead
HEAD in git describes a working copy, and we don't have those.
Instead, default to a "master" branch. This also lets us support
multiple branches.
src/libostree/ostree-repo.c | 300 ++++++++++++++++++++++++++--------------
src/libostree/ostree-repo.h | 39 +++---
src/libotutil/ot-gio-utils.c | 55 ++++++--
src/libotutil/ot-gio-utils.h | 6 +
src/ot-builtin-commit.c | 20 ++--
src/ot-builtin-fsck.c | 7 -
src/ot-builtin-log.c | 25 ++--
src/ot-builtin-show.c | 25 ++--
tests/libtest.sh | 10 +-
tests/t0002-commit-one.sh | 2 +-
tests/t0003-commit-multiple.sh | 4 +-
tests/t0004-checkout-test1.sh | 2 +-
tests/t0005-nested-tree.sh | 2 +-
tests/t0006-removal.sh | 4 +-
tests/t0007-commit-stdin.sh | 4 +-
tests/t0009-commit-symlink.sh | 4 +-
16 files changed, 319 insertions(+), 190 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index cdebeb8..2f9ff5d 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -56,12 +56,11 @@ typedef struct _OstreeRepoPrivate OstreeRepoPrivate;
struct _OstreeRepoPrivate {
char *path;
GFile *repo_file;
- char *head_ref_path;
+ GFile *local_heads_dir;
char *objects_path;
char *config_path;
gboolean inited;
- char *current_head;
GKeyFile *config;
};
@@ -74,10 +73,9 @@ ostree_repo_finalize (GObject *object)
g_free (priv->path);
g_clear_object (&priv->repo_file);
- g_free (priv->head_ref_path);
+ g_clear_object (&priv->local_heads_dir);
g_free (priv->objects_path);
g_free (priv->config_path);
- g_free (priv->current_head);
if (priv->config)
g_key_file_free (priv->config);
@@ -141,8 +139,8 @@ ostree_repo_constructor (GType gtype,
g_assert (priv->path != NULL);
priv->repo_file = ot_util_new_file_for_path (priv->path);
+ priv->local_heads_dir = g_file_resolve_relative_path (priv->repo_file, "refs/heads");
- priv->head_ref_path = g_build_filename (priv->path, "HEAD", NULL);
priv->objects_path = g_build_filename (priv->path, "objects", NULL);
priv->config_path = g_build_filename (priv->path, "config", NULL);
@@ -182,17 +180,37 @@ ostree_repo_new (const char *path)
}
static gboolean
-parse_checksum_file (OstreeRepo *self,
- const char *path,
- char **sha256,
- GError **error)
+validate_checksum_string (const char *sha256,
+ GError **error)
{
+ if (strlen (sha256) != 64)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid rev '%s'", sha256);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+parse_rev_file (OstreeRepo *self,
+ const char *path,
+ char **sha256,
+ GError **error) G_GNUC_UNUSED;
+
+static gboolean
+parse_rev_file (OstreeRepo *self,
+ const char *path,
+ char **sha256,
+ GError **error)
+{
+ OstreeRepoPrivate *priv = GET_PRIVATE (self);
GError *temp_error = NULL;
gboolean ret = FALSE;
- char *ret_sha256 = NULL;
+ char *rev = NULL;
- ret_sha256 = ot_util_get_file_contents_utf8 (path, &temp_error);
- if (ret_sha256 == NULL)
+ rev = ot_util_get_file_contents_utf8 (path, &temp_error);
+ if (rev == NULL)
{
if (g_error_matches (temp_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
{
@@ -206,31 +224,136 @@ parse_checksum_file (OstreeRepo *self,
}
else
{
- g_strchomp (ret_sha256);
+ g_strchomp (rev);
+ }
+
+ if (g_str_has_prefix (rev, "ref: "))
+ {
+ GFile *ref;
+ char *ref_path;
+ char *ref_sha256;
+ gboolean subret;
+
+ ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5);
+ ref_path = g_file_get_path (ref);
+
+ subret = parse_rev_file (self, ref_path, &ref_sha256, error);
+ g_clear_object (&ref);
+ g_free (ref_path);
+
+ if (!subret)
+ {
+ g_free (ref_sha256);
+ goto out;
+ }
+
+ g_free (rev);
+ rev = ref_sha256;
+ }
+ else
+ {
+ if (!validate_checksum_string (rev, error))
+ goto out;
}
- *sha256 = ret_sha256;
+ *sha256 = rev;
+ rev = NULL;
ret = TRUE;
out:
+ g_free (rev);
return ret;
}
static gboolean
-write_checksum_file (const char *path,
+resolve_rev (OstreeRepo *self,
+ const char *rev,
+ gboolean allow_noent,
+ char **sha256,
+ GError **error)
+{
+ OstreeRepoPrivate *priv = GET_PRIVATE (self);
+ gboolean ret = FALSE;
+ char *ret_rev = NULL;
+ GFile *child = NULL;
+ char *child_path = NULL;
+ GError *temp_error = NULL;
+
+ if (strlen (rev) == 64)
+ {
+ ret_rev = g_strdup (rev);
+ }
+ else
+ {
+ child = g_file_get_child (priv->local_heads_dir, rev);
+ child_path = g_file_get_path (child);
+ if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error))
+ {
+ if (allow_noent && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+ {
+ g_free (ret_rev);
+ ret_rev = NULL;
+ }
+ else
+ {
+ g_propagate_error (error, temp_error);
+ g_prefix_error (error, "Couldn't open ref '%s': ", child_path);
+ goto out;
+ }
+ }
+ else
+ {
+ g_strchomp (ret_rev);
+
+ if (!validate_checksum_string (ret_rev, error))
+ goto out;
+ }
+ }
+
+ *sha256 = ret_rev;
+ ret_rev = NULL;
+ ret = TRUE;
+ out:
+ g_clear_object (&child);
+ g_free (child_path);
+ g_free (ret_rev);
+ return ret;
+}
+
+gboolean
+ostree_repo_resolve_rev (OstreeRepo *self,
+ const char *rev,
+ char **sha256,
+ GError **error)
+{
+ return resolve_rev (self, rev, FALSE, sha256, error);
+}
+
+static gboolean
+write_checksum_file (GFile *parentdir,
+ const char *name,
const char *sha256,
- GError **error)
+ GError **error)
{
gboolean ret = FALSE;
- char *buf = NULL;
+ GFile *child = NULL;
+ GOutputStream *out = NULL;
+ gsize bytes_written;
- buf = g_strconcat (sha256, "\n", NULL);
-
- if (!g_file_set_contents (path, buf, -1, error))
+ child = g_file_get_child (parentdir, name);
+
+ if ((out = (GOutputStream*)g_file_replace (child, NULL, FALSE, 0, NULL, error)) == NULL)
+ goto out;
+ if (!g_output_stream_write_all (out, sha256, strlen (sha256), &bytes_written, NULL, error))
+ goto out;
+ if (!g_output_stream_write_all (out, "\n", 1, &bytes_written, NULL, error))
+ goto out;
+ if (!g_output_stream_close (out, NULL, error))
goto out;
ret = TRUE;
out:
- g_free (buf);
+ g_clear_object (&child);
+ g_clear_object (&out);
return ret;
}
@@ -253,9 +376,6 @@ ostree_repo_check (OstreeRepo *self, GError **error)
goto out;
}
- if (!parse_checksum_file (self, priv->head_ref_path, &priv->current_head, error))
- goto out;
-
priv->config = g_key_file_new ();
if (!g_key_file_load_from_file (priv->config, priv->config_path, 0, error))
{
@@ -789,7 +909,6 @@ load_commit_and_trees (OstreeRepo *self,
ParsedDirectoryData **out_root_data,
GError **error)
{
- OstreeRepoPrivate *priv = GET_PRIVATE (self);
GVariant *ret_commit = NULL;
ParsedDirectoryData *ret_root_data = NULL;
ParsedTreeData *tree_data = NULL;
@@ -799,13 +918,6 @@ load_commit_and_trees (OstreeRepo *self,
const char *tree_contents_checksum;
const char *tree_meta_checksum;
- if (!priv->current_head)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Can't load current commit; no HEAD reference");
- goto out;
- }
-
if (!load_gvariant_object (self, OSTREE_SERIALIZED_COMMIT_VARIANT,
commit_sha256, &ret_commit, error))
goto out;
@@ -1256,6 +1368,8 @@ add_files_to_tree_and_import (OstreeRepo *self,
static gboolean
commit_parsed_tree (OstreeRepo *self,
+ const char *branch,
+ const char *parent,
const char *subject,
const char *body,
GVariant *metadata,
@@ -1270,6 +1384,9 @@ commit_parsed_tree (OstreeRepo *self,
GVariant *commit = NULL;
GDateTime *now = NULL;
+ g_assert (branch != NULL);
+ g_assert (subject != NULL);
+
if (!import_parsed_tree (self, root->tree_data, &root_checksum, error))
goto out;
@@ -1277,7 +1394,7 @@ commit_parsed_tree (OstreeRepo *self,
commit = g_variant_new ("(u a{sv}ssstss)",
OSTREE_COMMIT_VERSION,
create_empty_gvariant_dict (),
- priv->current_head ? priv->current_head : "",
+ parent ? parent : "",
subject, body ? body : "",
g_date_time_to_unix (now) / G_TIME_SPAN_SECOND,
g_checksum_get_string (root_checksum),
@@ -1286,12 +1403,9 @@ commit_parsed_tree (OstreeRepo *self,
commit, &ret_commit, error))
goto out;
- if (!write_checksum_file (priv->head_ref_path, g_checksum_get_string (ret_commit), error))
+ if (!write_checksum_file (priv->local_heads_dir, branch, g_checksum_get_string (ret_commit), error))
goto out;
- g_free (priv->current_head);
- priv->current_head = g_strdup (g_checksum_get_string (ret_commit));
-
ret = TRUE;
*out_commit = ret_commit;
out:
@@ -1305,8 +1419,8 @@ commit_parsed_tree (OstreeRepo *self,
}
static gboolean
-import_root (OstreeRepo *self,
- const char *base,
+import_root (OstreeRepo *self,
+ const char *base,
ParsedDirectoryData **out_root,
GError **error)
{
@@ -1338,6 +1452,7 @@ import_root (OstreeRepo *self,
gboolean
ostree_repo_commit (OstreeRepo *self,
+ const char *branch,
const char *subject,
const char *body,
GVariant *metadata,
@@ -1354,13 +1469,20 @@ ostree_repo_commit (OstreeRepo *self,
GChecksum *ret_commit_checksum = NULL;
GVariant *root_metadata = NULL;
GChecksum *root_meta_checksum = NULL;
+ char *current_head = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (priv->inited, FALSE);
- if (priv->current_head)
+ if (branch == NULL)
+ branch = "master";
+
+ if (!resolve_rev (self, branch, TRUE, ¤t_head, error))
+ goto out;
+
+ if (current_head)
{
- if (!load_commit_and_trees (self, priv->current_head, &previous_commit, &root, error))
+ if (!load_commit_and_trees (self, current_head, &previous_commit, &root, error))
goto out;
if (!import_directory_meta (self, base, &root_metadata, &root_meta_checksum, error))
goto out;
@@ -1382,21 +1504,18 @@ ostree_repo_commit (OstreeRepo *self,
if (!add_files_to_tree_and_import (self, base, modified_files, root->tree_data, error))
goto out;
- if (!commit_parsed_tree (self, subject, body, metadata, root,
+ if (!commit_parsed_tree (self, branch, current_head,
+ subject, body, metadata, root,
&ret_commit_checksum, error))
goto out;
ret = TRUE;
+ *out_commit = ret_commit_checksum;
+ ret_commit_checksum = NULL;
out:
- if (!ret)
- {
- if (ret_commit_checksum)
- g_checksum_free (ret_commit_checksum);
- }
- else
- {
- *out_commit = ret_commit_checksum;
- }
+ if (ret_commit_checksum)
+ g_checksum_free (ret_commit_checksum);
+ g_free (current_head);
if (previous_commit)
g_variant_unref (previous_commit);
parsed_directory_data_free (root);
@@ -1409,14 +1528,15 @@ ostree_repo_commit (OstreeRepo *self,
gboolean
ostree_repo_commit_from_filelist_fd (OstreeRepo *self,
- const char *subject,
- const char *body,
- GVariant *metadata,
- const char *base,
- int fd,
- char separator,
- GChecksum **out_commit,
- GError **error)
+ const char *branch,
+ const char *subject,
+ const char *body,
+ GVariant *metadata,
+ const char *base,
+ int fd,
+ char separator,
+ GChecksum **out_commit,
+ GError **error)
{
OstreeRepoPrivate *priv = GET_PRIVATE (self);
gboolean ret = FALSE;
@@ -1429,14 +1549,21 @@ ostree_repo_commit_from_filelist_fd (OstreeRepo *self,
GError *temp_error = NULL;
GVariant *root_metadata = NULL;
GChecksum *root_meta_checksum = NULL;
+ char *current_head = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (priv->inited, FALSE);
+ if (branch == NULL)
+ branch = "master";
+
/* We're overwriting the tree */
if (!import_root (self, base, &root, error))
goto out;
+ if (!resolve_rev (self, branch, TRUE, ¤t_head, error))
+ goto out;
+
in = (GUnixInputStream*)g_unix_input_stream_new (fd, FALSE);
datain = g_data_input_stream_new ((GInputStream*)in);
@@ -1461,21 +1588,17 @@ ostree_repo_commit_from_filelist_fd (OstreeRepo *self,
g_propagate_prefixed_error (error, temp_error, "%s", "While reading filelist: ");
goto out;
}
- if (!commit_parsed_tree (self, subject, body, metadata,
+ if (!commit_parsed_tree (self, branch, current_head, subject, body, metadata,
root, &ret_commit_checksum, error))
goto out;
ret = TRUE;
+ *out_commit = ret_commit_checksum;
+ ret_commit_checksum = NULL;
out:
- if (!ret)
- {
- if (ret_commit_checksum)
- g_checksum_free (ret_commit_checksum);
- }
- else
- {
- *out_commit = ret_commit_checksum;
- }
+ if (ret_commit_checksum)
+ g_checksum_free (ret_commit_checksum);
+ g_free (current_head);
if (root_metadata)
g_variant_unref (root_metadata);
if (root_meta_checksum)
@@ -1640,37 +1763,6 @@ ostree_repo_load_variant (OstreeRepo *repo,
return ret;
}
-const char *
-ostree_repo_get_head (OstreeRepo *self)
-{
- OstreeRepoPrivate *priv = GET_PRIVATE (self);
-
- g_return_val_if_fail (priv->inited, NULL);
-
- return priv->current_head;
-}
-
-static gboolean
-resolve_ref (OstreeRepo *self,
- const char *ref,
- char **resolved,
- GError **error)
-{
- if (strcmp (ref, "HEAD") == 0)
- {
- *resolved = g_strdup (ostree_repo_get_head (self));
- return TRUE;
- }
- else if (strlen (ref) == 64)
- {
- *resolved = g_strdup (ref);
- return TRUE;
- }
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid ref '%s' (must be SHA256 or HEAD)", ref);
- return FALSE;
-}
-
static gboolean
checkout_tree (OstreeRepo *self,
ParsedTreeData *tree,
@@ -1762,9 +1854,9 @@ checkout_tree (OstreeRepo *self,
gboolean
ostree_repo_checkout (OstreeRepo *self,
- const char *ref,
- const char *destination,
- GError **error)
+ const char *rev,
+ const char *destination,
+ GError **error)
{
gboolean ret = FALSE;
GVariant *commit = NULL;
@@ -1780,7 +1872,7 @@ ostree_repo_checkout (OstreeRepo *self,
goto out;
}
- if (!resolve_ref (self, ref, &resolved, error))
+ if (!resolve_rev (self, rev, FALSE, &resolved, error))
goto out;
if (!load_commit_and_trees (self, resolved, &commit, &root, error))
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index e2b9de3..2279109 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -59,7 +59,10 @@ gboolean ostree_repo_link_file (OstreeRepo *self,
gboolean force,
GError **error);
-const char * ostree_repo_get_head (OstreeRepo *self);
+gboolean ostree_repo_resolve_rev (OstreeRepo *self,
+ const char *rev,
+ char **out_resolved,
+ GError **error);
gboolean ostree_repo_load_variant (OstreeRepo *self,
const char *sha256,
@@ -68,24 +71,26 @@ gboolean ostree_repo_load_variant (OstreeRepo *self,
GError **error);
gboolean ostree_repo_commit (OstreeRepo *self,
- const char *subject,
- const char *body,
- GVariant *metadata,
- const char *base,
- GPtrArray *modified_files,
- GPtrArray *removed_files,
- GChecksum **out_commit,
- GError **error);
+ const char *branch,
+ const char *subject,
+ const char *body,
+ GVariant *metadata,
+ const char *base,
+ GPtrArray *modified_files,
+ GPtrArray *removed_files,
+ GChecksum **out_commit,
+ GError **error);
gboolean ostree_repo_commit_from_filelist_fd (OstreeRepo *self,
- const char *subject,
- const char *body,
- GVariant *metadata,
- const char *base,
- int fd,
- char separator,
- GChecksum **out_commit,
- GError **error);
+ const char *branch,
+ const char *subject,
+ const char *body,
+ GVariant *metadata,
+ const char *base,
+ int fd,
+ char separator,
+ GChecksum **out_commit,
+ GError **error);
gboolean ostree_repo_checkout (OstreeRepo *self,
const char *ref,
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index 7663d4d..ad172de 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -62,21 +62,56 @@ char *
ot_util_get_file_contents_utf8 (const char *path,
GError **error)
{
- char *contents;
+ GFile *file = NULL;
+ char *ret = NULL;
+
+ file = ot_util_new_file_for_path (path);
+ if (!ot_util_gfile_load_contents_utf8 (file, NULL, &ret, NULL, error))
+ goto out;
+
+ out:
+ g_clear_object (&file);
+ return ret;
+}
+
+gboolean
+ot_util_gfile_load_contents_utf8 (GFile *file,
+ GCancellable *cancellable,
+ char **contents_out,
+ char **etag_out,
+ GError **error)
+{
+ char *ret_contents = NULL;
+ char *ret_etag = NULL;
gsize len;
- if (!g_file_get_contents (path, &contents, &len, error))
- return NULL;
- if (!g_utf8_validate (contents, len, NULL))
+ gboolean ret = FALSE;
+
+ if (!g_file_load_contents (file, cancellable, &ret_contents, &len, &ret_etag, error))
+ goto out;
+ if (!g_utf8_validate (ret_contents, len, NULL))
{
- g_free (contents);
g_set_error (error,
G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "File %s contains invalid UTF-8",
- path);
- return NULL;
+ G_IO_ERROR_INVALID_DATA,
+ "Invalid UTF-8");
+ goto out;
}
- return contents;
+
+ if (contents_out)
+ *contents_out = ret_contents;
+ else
+ g_free (ret_contents);
+ ret_contents = NULL;
+ if (etag_out)
+ *etag_out = ret_etag;
+ else
+ g_free (ret_etag);
+ ret_etag = NULL;
+ ret = TRUE;
+ out:
+ g_free (ret_contents);
+ g_free (ret_etag);
+ return ret;
}
GInputStream *
diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h
index 722e00c..0acb4dc 100644
--- a/src/libotutil/ot-gio-utils.h
+++ b/src/libotutil/ot-gio-utils.h
@@ -32,6 +32,12 @@ gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GErr
char * ot_util_get_file_contents_utf8 (const char *path, GError **error);
+gboolean ot_util_gfile_load_contents_utf8 (GFile *file,
+ GCancellable *cancellable,
+ char **contents_out,
+ char **etag_out,
+ GError **error);
+
GInputStream *ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error);
G_END_DECLS
diff --git a/src/ot-builtin-commit.c b/src/ot-builtin-commit.c
index 241ba2b..339a026 100644
--- a/src/ot-builtin-commit.c
+++ b/src/ot-builtin-commit.c
@@ -33,13 +33,15 @@ static gboolean from_stdin;
static char *from_file;
static char *subject;
static char *body;
+static char *branch;
static char **additions;
static char **removals;
static GOptionEntry options[] = {
{ "repo", 0, 0, G_OPTION_ARG_FILENAME, &repo_path, "Repository path", "repo" },
{ "subject", 's', 0, G_OPTION_ARG_STRING, &subject, "One line subject", "subject" },
- { "body", 'b', 0, G_OPTION_ARG_STRING, &body, "Full description", "body" },
+ { "body", 'm', 0, G_OPTION_ARG_STRING, &body, "Full description", "body" },
+ { "branch", 'b', 0, G_OPTION_ARG_STRING, &branch, "Branch", "branch" },
{ "from-fd", 0, 0, G_OPTION_ARG_INT, &from_fd, "Read new tree files from fd", "file descriptor" },
{ "from-stdin", 0, 0, G_OPTION_ARG_NONE, &from_stdin, "Read new tree files from stdin", "file descriptor" },
{ "from-file", 0, 0, G_OPTION_ARG_FILENAME, &from_file, "Read new tree files from another file", "path" },
@@ -113,11 +115,11 @@ ostree_builtin_commit (int argc, char **argv, const char *prefix, GError **error
for (iter = removals; *iter; iter++)
g_ptr_array_add (removals_array, *iter);
- if (!ostree_repo_commit (repo, subject, body, NULL,
- prefix, additions_array,
- removals_array,
- &commit_checksum,
- error))
+ if (!ostree_repo_commit (repo, branch, subject, body, NULL,
+ prefix, additions_array,
+ removals_array,
+ &commit_checksum,
+ error))
goto out;
}
else if (using_filedescriptors)
@@ -137,9 +139,9 @@ ostree_builtin_commit (int argc, char **argv, const char *prefix, GError **error
}
from_fd = temp_fd;
}
- if (!ostree_repo_commit_from_filelist_fd (repo, subject, body, NULL,
- prefix, from_fd, separator,
- &commit_checksum, error))
+ if (!ostree_repo_commit_from_filelist_fd (repo, branch, subject, body, NULL,
+ prefix, from_fd, separator,
+ &commit_checksum, error))
{
if (temp_fd >= 0)
close (temp_fd);
diff --git a/src/ot-builtin-fsck.c b/src/ot-builtin-fsck.c
index e85c9f6..0ce3cc3 100644
--- a/src/ot-builtin-fsck.c
+++ b/src/ot-builtin-fsck.c
@@ -121,13 +121,6 @@ ostree_builtin_fsck (int argc, char **argv, const char *prefix, GError **error)
if (!ostree_repo_iter_objects (repo, object_iter_callback, &data, error))
goto out;
- head = ostree_repo_get_head (repo);
- if (!head)
- {
- if (!quiet)
- g_printerr ("No HEAD file\n");
- }
-
if (!quiet)
g_printerr ("Total Objects: %u\n", data.n_objects);
diff --git a/src/ot-builtin-log.c b/src/ot-builtin-log.c
index 47d5db5..0bf5f68 100644
--- a/src/ot-builtin-log.c
+++ b/src/ot-builtin-log.c
@@ -41,7 +41,8 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
OstreeRepo *repo = NULL;
GOutputStream *pager = NULL;
GVariant *commit = NULL;
- char *head;
+ const char *rev = "master";
+ char *resolved_rev;
context = g_option_context_new ("- Show revision log");
g_option_context_add_main_entries (context, options, NULL);
@@ -54,20 +55,19 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
if (prefix == NULL)
prefix = ".";
+ if (argc > 1)
+ rev = argv[1];
+
repo = ostree_repo_new (repo_path);
if (!ostree_repo_check (repo, error))
goto out;
- head = g_strdup (ostree_repo_get_head (repo));
- if (!head)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No HEAD exists");
- goto out;
- }
-
if (!ot_util_spawn_pager (&pager, error))
goto out;
+ if (!ostree_repo_resolve_rev (repo, rev, &resolved_rev, error))
+ goto out;
+
while (TRUE)
{
OstreeSerializedVariantType type;
@@ -88,7 +88,7 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
if (commit)
g_variant_unref (commit);
- if (!ostree_repo_load_variant (repo, head, &type, &commit, error))
+ if (!ostree_repo_load_variant (repo, resolved_rev, &type, &commit, error))
goto out;
/* Ignore commit metadata for now */
@@ -103,7 +103,7 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
formatted_metadata = g_variant_print (commit_metadata, TRUE);
g_variant_unref (commit_metadata);
formatted = g_strdup_printf ("commit %s\nSubject: %s\nDate: %s\nMetadata: %s\n\n",
- head, subject, formatted_date, formatted_metadata);
+ resolved_rev, subject, formatted_date, formatted_metadata);
g_free (formatted_metadata);
g_free (formatted_date);
formatted_date = NULL;
@@ -134,8 +134,8 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
if (strcmp (parent, "") == 0)
break;
- g_free (head);
- head = g_strdup (parent);
+ g_free (resolved_rev);
+ resolved_rev = g_strdup (parent);
}
if (!g_output_stream_close (pager, NULL, error))
@@ -143,6 +143,7 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
ret = TRUE;
out:
+ g_free (resolved_rev);
if (context)
g_option_context_free (context);
if (commit)
diff --git a/src/ot-builtin-show.c b/src/ot-builtin-show.c
index 82be89a..8985c56 100644
--- a/src/ot-builtin-show.c
+++ b/src/ot-builtin-show.c
@@ -39,7 +39,8 @@ ostree_builtin_show (int argc, char **argv, const char *prefix, GError **error)
GOptionContext *context;
gboolean ret = FALSE;
OstreeRepo *repo = NULL;
- const char *target;
+ const char *rev = "master";
+ char *resolved_rev = NULL;
OstreeSerializedVariantType type;
GVariant *variant = NULL;
char *formatted_variant = NULL;
@@ -57,28 +58,22 @@ ostree_builtin_show (int argc, char **argv, const char *prefix, GError **error)
if (!ostree_repo_check (repo, error))
goto out;
- if (argc < 2)
- {
- target = ostree_repo_get_head (repo);
- if (!target)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No arguments specified and no HEAD exists");
- goto out;
- }
- }
- else
- target = argv[1];
+ if (argc > 1)
+ rev = argv[1];
- if (!ostree_repo_load_variant (repo, target, &type, &variant, error))
+ if (!ostree_repo_resolve_rev (repo, rev, &resolved_rev, error))
goto out;
- g_print ("Object: %s\nType: %d\n", target, type);
+ if (!ostree_repo_load_variant (repo, resolved_rev, &type, &variant, error))
+ goto out;
+
+ g_print ("Object: %s\nType: %d\n", resolved_rev, type);
formatted_variant = g_variant_print (variant, TRUE);
g_print ("%s\n", formatted_variant);
ret = TRUE;
out:
+ g_free (resolved_rev);
if (context)
g_option_context_free (context);
g_clear_object (&repo);
diff --git a/tests/libtest.sh b/tests/libtest.sh
index 2cfebae..3429345 100644
--- a/tests/libtest.sh
+++ b/tests/libtest.sh
@@ -25,7 +25,7 @@ cd "$test_tmpdir"
touch "$test_tmpdir/.test$$"
die () {
- if test -z "$HT_TESTS_SAVE_TEMPS"; then
+ if test -z "$OT_TESTS_SAVE_TEMPS"; then
test -f "$test_tmpdir/.test$$" && rm -rf "$test_tmpdir"
else
echo "Temporary files saved in $test_tmpdir"
@@ -60,8 +60,8 @@ setup_test_repository1 () {
ot_repo="--repo=../repo"
export ot_repo
ostree init $ot_repo
- ostree commit $ot_repo -s "Test Commit 1" -b "Commit body first" --add=firstfile
- ostree commit $ot_repo -s "Test Commit 2" -b "Commit body second" --add=secondfile
+ ostree commit $ot_repo -s "Test Commit 1" -m "Commit body first" --add=firstfile
+ ostree commit $ot_repo -s "Test Commit 2" -m "Commit body second" --add=secondfile
ostree fsck -q $ot_repo
}
@@ -86,8 +86,8 @@ setup_test_repository2 () {
cd ../files
export ot_repo
ostree init $ot_repo
- ostree commit $ot_repo -s "Test Commit 1" -b "Commit body first" --add=firstfile
- ostree commit $ot_repo -s "Test Commit 2" -b "Commit body second" --add=baz/cow --add=baz/saucer --add=baz/deeper/ohyeah --add=baz/another/y
+ ostree commit $ot_repo -s "Test Commit 1" -m "Commit body first" --add=firstfile
+ ostree commit $ot_repo -s "Test Commit 2" -m "Commit body second" --add=baz/cow --add=baz/saucer --add=baz/deeper/ohyeah --add=baz/another/y
ostree fsck -q $ot_repo
}
diff --git a/tests/t0002-commit-one.sh b/tests/t0002-commit-one.sh
index b181a27..68c76bf 100755
--- a/tests/t0002-commit-one.sh
+++ b/tests/t0002-commit-one.sh
@@ -32,7 +32,7 @@ mkdir ../repo
repo="--repo=../repo"
ostree init $repo
echo 'ok init'
-ostree commit $repo -s "Test Commit" -b "Commit body" --add=yy
+ostree commit $repo -s "Test Commit" -m "Commit body" --add=yy
echo 'ok commit'
ostree fsck -q $repo
echo 'ok fsck'
diff --git a/tests/t0003-commit-multiple.sh b/tests/t0003-commit-multiple.sh
index 1ba31ec..b517d96 100755
--- a/tests/t0003-commit-multiple.sh
+++ b/tests/t0003-commit-multiple.sh
@@ -33,9 +33,9 @@ mkdir ../repo
repo="--repo=../repo"
ostree init $repo
echo 'ok init'
-ostree commit $repo -s "Test Commit 1" -b "Commit body first" --add=firstfile
+ostree commit $repo -s "Test Commit 1" -m "Commit body first" --add=firstfile
echo 'ok commit 1'
-ostree commit $repo -s "Test Commit 2" -b "Commit body first" --add=secondfile
+ostree commit $repo -s "Test Commit 2" -m "Commit body first" --add=secondfile
echo 'ok commit 2'
ostree fsck -q $repo
echo 'ok fsck'
diff --git a/tests/t0004-checkout-test1.sh b/tests/t0004-checkout-test1.sh
index 5b30b6f..2e00b1f 100755
--- a/tests/t0004-checkout-test1.sh
+++ b/tests/t0004-checkout-test1.sh
@@ -26,7 +26,7 @@ echo '1..3'
setup_test_repository1
echo 'ok setup'
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout1-head
+ostree checkout $ot_repo master $test_tmpdir/checkout1-head
echo 'ok checkout cmd'
cd $test_tmpdir/checkout1-head
assert_has_file firstfile
diff --git a/tests/t0005-nested-tree.sh b/tests/t0005-nested-tree.sh
index d577ce7..574e4c5 100755
--- a/tests/t0005-nested-tree.sh
+++ b/tests/t0005-nested-tree.sh
@@ -26,7 +26,7 @@ echo '1..5'
setup_test_repository2
echo 'ok setup'
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout2-head
+ostree checkout $ot_repo master $test_tmpdir/checkout2-head
echo 'ok checkout cmd'
cd $test_tmpdir/checkout2-head
assert_has_file firstfile
diff --git a/tests/t0006-removal.sh b/tests/t0006-removal.sh
index 926da72..65174e4 100755
--- a/tests/t0006-removal.sh
+++ b/tests/t0006-removal.sh
@@ -25,14 +25,14 @@ set -e
echo '1..4'
setup_test_repository2
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout2-head
+ostree checkout $ot_repo master $test_tmpdir/checkout2-head
echo 'ok setup'
cd $test_tmpdir/checkout2-head
ostree commit -s delete $ot_repo -r firstfile
echo 'ok rm firstfile'
assert_has_file firstfile # It should still exist in this checkout
cd $test_tmpdir
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout3-head
+ostree checkout $ot_repo master $test_tmpdir/checkout3-head
echo 'ok checkout 3'
cd $test_tmpdir/checkout3-head
assert_not_has_file firstfile
diff --git a/tests/t0007-commit-stdin.sh b/tests/t0007-commit-stdin.sh
index 16a6884..79f1551 100755
--- a/tests/t0007-commit-stdin.sh
+++ b/tests/t0007-commit-stdin.sh
@@ -25,7 +25,7 @@ set -e
echo "1..2"
setup_test_repository2
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout2-head
+ostree checkout $ot_repo master $test_tmpdir/checkout2-head
cd $test_tmpdir/checkout2-head
mkdir -p a/nested/tree
echo one > a/nested/tree/1
@@ -41,7 +41,7 @@ echo whee2 > another/whee
# FIXME - remove grep for .
find | grep -v '^\.$' | ostree commit $ot_repo --from-stdin -s "From find"
echo "ok commit stdin"
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout3-head
+ostree checkout $ot_repo master $test_tmpdir/checkout3-head
cd $test_tmpdir/checkout3-head
assert_has_file a/nested/2
assert_file_has_content a/nested/2 'two2'
diff --git a/tests/t0009-commit-symlink.sh b/tests/t0009-commit-symlink.sh
index 47e956d..ae725de 100755
--- a/tests/t0009-commit-symlink.sh
+++ b/tests/t0009-commit-symlink.sh
@@ -26,10 +26,10 @@ echo "1..2"
setup_test_repository2
-ostree checkout $ot_repo HEAD $test_tmpdir/checkout2-head
+ostree checkout $ot_repo master $test_tmpdir/checkout2-head
cd $ht_files
ln -s foo bar
-ostree commit $ot_repo -s "Add a symlink" -b "To test it" --add=bar
+ostree commit $ot_repo -s "Add a symlink" -m "To test it" --add=bar
echo "ok commit symlink"
ostree fsck $ot_repo
echo "ok fsck"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]