mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
bin/refs: Sort listing
The output is much more readable sorted. I can't think of any reason you'd want it unsorted (which is essentially dentry order).
This commit is contained in:
parent
2b8707b010
commit
6b0f42ae37
@ -47,6 +47,16 @@ static GOptionEntry options[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int
|
||||
collection_ref_cmp (OstreeCollectionRef *a,
|
||||
OstreeCollectionRef *b)
|
||||
{
|
||||
int ret = g_strcmp0 (a->collection_id, b->collection_id);
|
||||
if (ret == 0)
|
||||
ret = g_strcmp0 (a->ref_name, b->ref_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_ref_with_collections (OstreeRepo *repo,
|
||||
const char *refspec_prefix,
|
||||
@ -66,10 +76,12 @@ do_ref_with_collections (OstreeRepo *repo,
|
||||
|
||||
if (!opt_delete && !opt_create)
|
||||
{
|
||||
g_hash_table_iter_init (&hashiter, refs);
|
||||
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
|
||||
g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs);
|
||||
ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) collection_ref_cmp);
|
||||
|
||||
for (GList *iter = ordered_keys; iter != NULL; iter = iter->next)
|
||||
{
|
||||
const OstreeCollectionRef *ref = hashkey;
|
||||
OstreeCollectionRef *ref = iter->data;
|
||||
g_print ("(%s, %s)\n", ref->collection_id, ref->ref_name);
|
||||
}
|
||||
}
|
||||
@ -179,12 +191,22 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
|
||||
|
||||
if (is_list)
|
||||
{
|
||||
GLNX_HASH_TABLE_FOREACH_KV (refs, const char *, ref, const char *, value)
|
||||
g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs);
|
||||
ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) g_strcmp0);
|
||||
|
||||
for (GList *iter = ordered_keys; iter != NULL; iter = iter->next)
|
||||
{
|
||||
const char *ref = iter->data;
|
||||
|
||||
if (opt_alias)
|
||||
g_print ("%s -> %s\n", ref, value);
|
||||
{
|
||||
const char *alias = g_hash_table_lookup (refs, ref);
|
||||
g_print ("%s -> %s\n", ref, alias);
|
||||
}
|
||||
else
|
||||
g_print ("%s\n", ref);
|
||||
{
|
||||
g_print ("%s\n", ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (opt_create)
|
||||
|
@ -42,6 +42,10 @@ done
|
||||
${CMD_PREFIX} ostree --repo=repo refs | wc -l > refscount
|
||||
assert_file_has_content refscount "^10$"
|
||||
|
||||
${CMD_PREFIX} ostree --repo=repo refs > refs
|
||||
sort refs > refs-sorted
|
||||
assert_files_equal refs refs-sorted
|
||||
|
||||
${CMD_PREFIX} ostree --repo=repo refs foo > refs
|
||||
assert_not_file_has_content refs foo
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user