forked from Mirrors/flatpak-builder
ls-remote: Support showing remote commit ids
parent
f9b9f70fad
commit
80c6a8b66c
|
@ -53,9 +53,12 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
gpointer key;
|
gpointer key;
|
||||||
gpointer value;
|
gpointer value;
|
||||||
g_autoptr(GPtrArray) names = NULL;
|
g_autoptr(GHashTable) names = NULL;
|
||||||
|
guint n_keys;
|
||||||
|
g_autofree const char **keys = NULL;
|
||||||
int i;
|
int i;
|
||||||
const char *repository;
|
const char *repository;
|
||||||
|
const char *arch;
|
||||||
|
|
||||||
context = g_option_context_new (" REMOTE - Show available runtimes and applications");
|
context = g_option_context_new (" REMOTE - Show available runtimes and applications");
|
||||||
|
|
||||||
|
@ -74,15 +77,24 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
names = g_ptr_array_new_with_free_func (g_free);
|
names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
|
|
||||||
|
arch = xdg_app_get_arch ();
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, refs);
|
g_hash_table_iter_init (&iter, refs);
|
||||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||||
{
|
{
|
||||||
const char *ref = key;
|
const char *ref = key;
|
||||||
const char *checksum = value;
|
const char *checksum = value;
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
char *p;
|
g_auto(GStrv) parts = NULL;
|
||||||
|
|
||||||
|
parts = xdg_app_decompose_ref (ref, NULL);
|
||||||
|
if (parts == NULL)
|
||||||
|
{
|
||||||
|
g_debug ("Invalid remote ref %s\n", ref);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (opt_only_updates)
|
if (opt_only_updates)
|
||||||
{
|
{
|
||||||
|
@ -96,58 +108,37 @@ xdg_app_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_str_has_prefix (ref, "runtime/") && !opt_only_apps)
|
if (!opt_show_details)
|
||||||
{
|
{
|
||||||
if (!opt_show_details)
|
if (strcmp (arch, parts[2]) != 0)
|
||||||
{
|
continue;
|
||||||
name = g_strdup (ref + strlen ("runtime/"));
|
|
||||||
p = strchr (name, '/');
|
|
||||||
if (p)
|
|
||||||
*p = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name = g_strdup (ref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_str_has_prefix (ref, "app/") && !opt_only_runtimes)
|
if (strcmp (parts[0], "runtime") == 0 && opt_only_apps)
|
||||||
{
|
continue;
|
||||||
if (!opt_show_details)
|
|
||||||
{
|
|
||||||
name = g_strdup (ref + strlen ("app/"));
|
|
||||||
p = strchr (name, '/');
|
|
||||||
if (p)
|
|
||||||
*p = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name = g_strdup (ref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name)
|
if (strcmp (parts[0], "app") == 0 && opt_only_runtimes)
|
||||||
{
|
continue;
|
||||||
gboolean found = FALSE;
|
|
||||||
|
|
||||||
for (i = 0; i < names->len; i++)
|
if (!opt_show_details)
|
||||||
{
|
name = parts[1];
|
||||||
if (strcmp (name, g_ptr_array_index (names, i)) == 0)
|
else
|
||||||
found = TRUE;
|
name = ref;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
if (g_hash_table_lookup (names, name) == NULL)
|
||||||
g_ptr_array_add (names, name);
|
g_hash_table_insert (names, g_strdup (name), g_strdup (checksum));
|
||||||
else
|
|
||||||
g_free (name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ptr_array_sort (names, (GCompareFunc)xdg_app_strcmp0_ptr);
|
keys = (const char **)g_hash_table_get_keys_as_array (names, &n_keys);
|
||||||
|
g_qsort_with_data (keys, n_keys, sizeof(char *), (GCompareDataFunc)xdg_app_strcmp0_ptr, NULL);
|
||||||
|
|
||||||
for (i = 0; i < names->len; i++)
|
for (i = 0; i < n_keys; i++)
|
||||||
g_print ("%s\n", (char *)g_ptr_array_index (names, i));
|
{
|
||||||
|
if (opt_show_details)
|
||||||
|
g_print ("%s\t%s\n", keys[i], (char *)g_hash_table_lookup (names, keys[i]));
|
||||||
|
else
|
||||||
|
g_print ("%s\n", keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,10 +83,11 @@
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
<term><option>-d</option></term>
|
||||||
<term><option>--show-details</option></term>
|
<term><option>--show-details</option></term>
|
||||||
|
|
||||||
<listitem><para>
|
<listitem><para>
|
||||||
Show arches and branches, in addition to the names.
|
Show arches, branches and commit ids, in addition to the names.
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue