core: Add API to enumerate all refs
This commit is contained in:
parent
6ff07e0b3e
commit
d3a73225b0
|
|
@ -1375,6 +1375,86 @@ create_empty_gvariant_dict (void)
|
|||
return g_variant_builder_end (&builder);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
enumerate_refs_recurse (OstreeRepo *repo,
|
||||
GFile *base,
|
||||
GFile *dir,
|
||||
GHashTable *refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GFileInfo *file_info = NULL;
|
||||
GFileEnumerator *enumerator = NULL;
|
||||
GFile *child = NULL;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
if (!enumerator)
|
||||
goto out;
|
||||
|
||||
while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL)
|
||||
{
|
||||
g_clear_object (&child);
|
||||
child = g_file_get_child (dir, g_file_info_get_name (file_info));
|
||||
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
if (!enumerate_refs_recurse (repo, base, child, refs, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
char *contents;
|
||||
gsize len;
|
||||
|
||||
if (!g_file_load_contents (child, cancellable, &contents, &len, NULL, error))
|
||||
goto out;
|
||||
|
||||
g_strchomp (contents);
|
||||
|
||||
g_hash_table_insert (refs, g_file_get_relative_path (base, child), contents);
|
||||
}
|
||||
|
||||
g_clear_object (&file_info);
|
||||
}
|
||||
if (temp_error != NULL)
|
||||
{
|
||||
g_propagate_error (error, temp_error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_clear_object (&file_info);
|
||||
g_clear_object (&child);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_list_all_refs (OstreeRepo *repo,
|
||||
GHashTable **out_all_refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GHashTable *ret_all_refs = NULL;
|
||||
GFile *heads_dir = NULL;
|
||||
|
||||
ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
heads_dir = g_file_resolve_relative_path (ostree_repo_get_path (repo), "refs/heads");
|
||||
if (!enumerate_refs_recurse (repo, heads_dir, heads_dir, ret_all_refs, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value (out_all_refs, &ret_all_refs);
|
||||
out:
|
||||
g_clear_object (&heads_dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_write_ref (OstreeRepo *self,
|
||||
const char *remote,
|
||||
|
|
|
|||
|
|
@ -130,6 +130,11 @@ gboolean ostree_repo_write_ref (OstreeRepo *self,
|
|||
const char *rev,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_list_all_refs (OstreeRepo *repo,
|
||||
GHashTable **out_all_refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_load_variant (OstreeRepo *self,
|
||||
OstreeObjectType expected_type,
|
||||
const char *sha256,
|
||||
|
|
|
|||
|
|
@ -225,84 +225,6 @@ object_iter_callback (OstreeRepo *repo,
|
|||
g_free (key);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_refs_recurse (OstreeRepo *repo,
|
||||
GFile *base,
|
||||
GFile *dir,
|
||||
GHashTable *refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GFileInfo *file_info = NULL;
|
||||
GFileEnumerator *enumerator = NULL;
|
||||
GFile *child = NULL;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
if (!enumerator)
|
||||
goto out;
|
||||
|
||||
while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL)
|
||||
{
|
||||
g_clear_object (&child);
|
||||
child = g_file_get_child (dir, g_file_info_get_name (file_info));
|
||||
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
if (!add_refs_recurse (repo, base, child, refs, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
char *contents;
|
||||
gsize len;
|
||||
|
||||
if (!g_file_load_contents (child, cancellable, &contents, &len, NULL, error))
|
||||
goto out;
|
||||
|
||||
g_strchomp (contents);
|
||||
|
||||
g_hash_table_insert (refs, g_file_get_relative_path (base, child), contents);
|
||||
}
|
||||
|
||||
g_clear_object (&file_info);
|
||||
}
|
||||
if (temp_error != NULL)
|
||||
{
|
||||
g_propagate_error (error, temp_error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_clear_object (&file_info);
|
||||
g_clear_object (&child);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
list_all_refs (OstreeRepo *repo,
|
||||
GHashTable **out_all_refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GHashTable *ret_all_refs = NULL;
|
||||
GFile *heads_dir = NULL;
|
||||
|
||||
ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
heads_dir = g_file_resolve_relative_path (ostree_repo_get_path (repo), "refs/heads");
|
||||
if (!add_refs_recurse (repo, heads_dir, heads_dir, ret_all_refs, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value (out_all_refs, &ret_all_refs);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error)
|
||||
|
|
@ -333,7 +255,7 @@ ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error)
|
|||
data.n_reachable = 0;
|
||||
data.n_unreachable = 0;
|
||||
|
||||
if (!list_all_refs (repo, &all_refs, cancellable, error))
|
||||
if (!ostree_repo_list_all_refs (repo, &all_refs, cancellable, error))
|
||||
goto out;
|
||||
|
||||
g_hash_table_iter_init (&hash_iter, all_refs);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
set -e
|
||||
|
||||
echo "1..24"
|
||||
echo "1..25"
|
||||
|
||||
. libtest.sh
|
||||
|
||||
|
|
@ -181,3 +181,7 @@ EOF
|
|||
cd ${test_tmpdir}/checkout-test2-4
|
||||
$OSTREE commit -b test2 -s "with statoverride" --statoverride=../test-statoverride.txt
|
||||
echo "ok commit statoverridde"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
$OSTREE prune
|
||||
echo "ok prune didn't fail"
|
||||
|
|
|
|||
Loading…
Reference in New Issue