mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-10-31 04:58:58 +00:00
Set current ref (from load arguments) as default selection in branches combo
This correctly parses the arguments supplied to fetch the revisions and gets the the branch name from it (using git rev-parse).
This commit is contained in:
parent
e26bb05e75
commit
c0b966fa76
2 changed files with 62 additions and 44 deletions
|
@ -42,7 +42,8 @@ G_DEFINE_TYPE_EXTENDED(GitgRepository, gitg_repository, G_TYPE_OBJECT, 0,
|
|||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL, gitg_repository_tree_model_iface_init));
|
||||
|
||||
/* Properties */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
||||
PROP_PATH,
|
||||
|
@ -870,17 +871,21 @@ reload_revisions(GitgRepository *repository, GError **error)
|
|||
return gitg_repository_run_commandv(repository, repository->priv->loader, error, "log", "--pretty=format:%H\x01%an\x01%s\x01%at", "-g", "refs/stash", NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
load_revisions(GitgRepository *self, gint argc, gchar const **av, GError **error)
|
||||
static void
|
||||
build_log_args(GitgRepository *self, gint argc, gchar const **av)
|
||||
{
|
||||
gchar **argv = g_new0(gchar *, 5 + (argc > 0 ? argc - 1 : 0));
|
||||
|
||||
argv[0] = g_strdup("log");
|
||||
|
||||
if (has_left_right(av, argc))
|
||||
{
|
||||
argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at\x01%m");
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at");
|
||||
}
|
||||
|
||||
gchar *head = NULL;
|
||||
|
||||
|
@ -889,7 +894,9 @@ load_revisions(GitgRepository *self, gint argc, gchar const **av, GError **error
|
|||
head = gitg_repository_parse_ref(self, "HEAD");
|
||||
|
||||
if (head)
|
||||
{
|
||||
argv[2] = g_strdup("HEAD");
|
||||
}
|
||||
|
||||
g_free(head);
|
||||
}
|
||||
|
@ -898,13 +905,13 @@ load_revisions(GitgRepository *self, gint argc, gchar const **av, GError **error
|
|||
int i;
|
||||
|
||||
for (i = 0; i < argc; ++i)
|
||||
{
|
||||
argv[2 + i] = g_strdup(av[i]);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(self->priv->last_args);
|
||||
self->priv->last_args = argv;
|
||||
|
||||
return reload_revisions(self, error);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
|
@ -912,18 +919,32 @@ load_current_ref(GitgRepository *self)
|
|||
{
|
||||
gchar **out;
|
||||
gchar *ret = NULL;
|
||||
gint i;
|
||||
gint numargs;
|
||||
|
||||
out = gitg_repository_command_with_outputv(self, NULL, "show-branch", "--sha1-name", "--current", NULL);
|
||||
numargs = g_strv_length(self->priv->last_args);
|
||||
|
||||
gchar const **argv = g_new0(gchar const *, numargs + 3);
|
||||
|
||||
argv[0] = "rev-parse";
|
||||
argv[1] = "--no-flags";
|
||||
argv[2] = "--symbolic-full-name";
|
||||
|
||||
for (i = 1; i < numargs; ++i)
|
||||
{
|
||||
argv[2 + i] = self->priv->last_args[i];
|
||||
}
|
||||
|
||||
out = gitg_repository_command_with_output(self, argv, NULL);
|
||||
|
||||
if (!out)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*out)
|
||||
{
|
||||
gchar *pos = g_utf8_strchr(*out, -1, ']');
|
||||
|
||||
if (pos)
|
||||
ret = g_strndup(*out + 1, (pos - *out) - 2);
|
||||
ret = g_strdup(*out);
|
||||
}
|
||||
|
||||
g_strfreev(out);
|
||||
|
@ -953,8 +974,10 @@ load_refs(GitgRepository *self)
|
|||
gchar const *obj = len == 3 && *components[2] ? components[2] : components[1];
|
||||
GitgRef *ref = add_ref(self, obj, components[0]);
|
||||
|
||||
if (current != NULL && strncmp(obj, current, strlen(current)) == 0)
|
||||
if (current != NULL && strcmp(gitg_ref_get_name(ref), current) == 0)
|
||||
{
|
||||
self->priv->current_ref = gitg_ref_copy(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -986,19 +1009,23 @@ gitg_repository_load(GitgRepository *self, int argc, gchar const **av, GError **
|
|||
if (self->priv->path == NULL)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
*error = g_error_new_literal(gitg_repository_error_quark(), GITG_REPOSITORY_ERROR_NOT_FOUND, _("Not a valid git repository"));
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gitg_runner_cancel(self->priv->loader);
|
||||
gitg_repository_clear(self);
|
||||
|
||||
build_log_args(self, argc, av);
|
||||
|
||||
/* first get the refs */
|
||||
load_refs(self);
|
||||
|
||||
/* request log (all the revision) */
|
||||
return load_revisions(self, argc, av, error);
|
||||
return reload_revisions(self, error);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -71,7 +71,6 @@ struct _GitgWindowPrivate
|
|||
GtkActionGroup *edit_group;
|
||||
GtkWidget *open_dialog;
|
||||
|
||||
GitgRef *current_branch;
|
||||
GitgCellRendererPath *renderer_path;
|
||||
|
||||
GTimer *load_timer;
|
||||
|
@ -96,8 +95,6 @@ gitg_window_finalize(GObject *object)
|
|||
{
|
||||
GitgWindow *self = GITG_WINDOW(object);
|
||||
|
||||
gitg_ref_free(self->priv->current_branch);
|
||||
|
||||
g_timer_destroy(self->priv->load_timer);
|
||||
gdk_cursor_unref(self->priv->hand);
|
||||
|
||||
|
@ -609,11 +606,13 @@ create_repository(GitgWindow *window, gchar const *path, gboolean usewd)
|
|||
|
||||
if (path)
|
||||
{
|
||||
gchar realp[PATH_MAX];
|
||||
GFile *file = g_file_new_for_commandline_arg(path);
|
||||
|
||||
if (realpath(path, realp))
|
||||
if (g_file_is_native(file) && g_file_query_exists(file, NULL))
|
||||
{
|
||||
window->priv->repository = gitg_repository_new(realp);
|
||||
gchar *p = g_file_get_path(file);
|
||||
window->priv->repository = gitg_repository_new(p);
|
||||
g_free(p);
|
||||
|
||||
if (!gitg_repository_get_path(window->priv->repository))
|
||||
{
|
||||
|
@ -630,6 +629,8 @@ create_repository(GitgWindow *window, gchar const *path, gboolean usewd)
|
|||
ret = FALSE;
|
||||
path = NULL;
|
||||
}
|
||||
|
||||
g_object_unref(file);
|
||||
}
|
||||
|
||||
if (!path && usewd)
|
||||
|
@ -667,26 +668,8 @@ sort_by_ref_type(GitgRef *a, GitgRef *b)
|
|||
}
|
||||
|
||||
static void
|
||||
clear_branches_combo(GitgWindow *window, gboolean keepselection)
|
||||
clear_branches_combo(GitgWindow *window)
|
||||
{
|
||||
if (keepselection)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(window->priv->combo_branches), &iter);
|
||||
|
||||
gitg_ref_free(window->priv->current_branch);
|
||||
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(window->priv->branches_store),
|
||||
&iter,
|
||||
COLUMN_BRANCHES_REF, &window->priv->current_branch,
|
||||
-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
gitg_ref_free(window->priv->current_branch);
|
||||
window->priv->current_branch = NULL;
|
||||
}
|
||||
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(window->priv->branches_store), &iter, NULL, 1))
|
||||
|
@ -719,7 +702,9 @@ fill_branches_combo(GitgWindow *window)
|
|||
GtkTreeIter parent;
|
||||
GitgRef *parentref = NULL;
|
||||
GtkTreeStore *store = window->priv->branches_store;
|
||||
|
||||
GitgRef *current_ref = gitg_repository_get_current_ref(window->priv->repository);
|
||||
gboolean refset = FALSE;
|
||||
|
||||
for (item = refs; item; item = item->next)
|
||||
{
|
||||
GitgRef *ref = (GitgRef *)item->data;
|
||||
|
@ -767,9 +752,10 @@ fill_branches_combo(GitgWindow *window)
|
|||
COLUMN_BRANCHES_REF, ref,
|
||||
-1);
|
||||
|
||||
if (window->priv->current_branch && gitg_ref_equal(window->priv->current_branch, ref) == 0)
|
||||
if (!refset && gitg_ref_equal(current_ref, ref))
|
||||
{
|
||||
gtk_combo_box_set_active_iter(window->priv->combo_branches, &iter);
|
||||
refset = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -786,8 +772,10 @@ fill_branches_combo(GitgWindow *window)
|
|||
COLUMN_BRANCHES_REF, NULL,
|
||||
-1);
|
||||
|
||||
if (!window->priv->current_branch)
|
||||
if (!refset)
|
||||
{
|
||||
gtk_combo_box_set_active(window->priv->combo_branches, 0);
|
||||
}
|
||||
|
||||
g_slist_foreach(refs, (GFunc)gitg_ref_free, NULL);
|
||||
g_slist_free(refs);
|
||||
|
@ -864,11 +852,14 @@ load_repository(GitgWindow *window, gchar const *path, gint argc, gchar const **
|
|||
}
|
||||
|
||||
g_signal_connect(window->priv->repository, "load", G_CALLBACK(on_repository_load), window);
|
||||
clear_branches_combo(window, FALSE);
|
||||
clear_branches_combo(window);
|
||||
|
||||
gitg_repository_load(window->priv->repository, argc, ar, NULL);
|
||||
|
||||
if (!haspath && argc)
|
||||
if (!haspath && path)
|
||||
{
|
||||
g_free(ar);
|
||||
}
|
||||
|
||||
gitg_commit_view_set_repository(window->priv->commit_view, window->priv->repository);
|
||||
gitg_revision_view_set_repository(window->priv->revision_view, window->priv->repository);
|
||||
|
@ -885,7 +876,7 @@ load_repository(GitgWindow *window, gchar const *path, gint argc, gchar const **
|
|||
}
|
||||
else
|
||||
{
|
||||
clear_branches_combo(window, FALSE);
|
||||
clear_branches_combo(window);
|
||||
gitg_commit_view_set_repository(window->priv->commit_view, window->priv->repository);
|
||||
gitg_revision_view_set_repository(window->priv->revision_view, window->priv->repository);
|
||||
|
||||
|
@ -995,7 +986,7 @@ on_view_refresh(GtkAction *action, GitgWindow *window)
|
|||
if (window->priv->repository && gitg_repository_get_path(window->priv->repository) != NULL)
|
||||
{
|
||||
g_signal_handlers_block_by_func(window->priv->combo_branches, on_branches_combo_changed, window);
|
||||
clear_branches_combo(window, TRUE);
|
||||
clear_branches_combo(window);
|
||||
g_signal_handlers_unblock_by_func(window->priv->combo_branches, on_branches_combo_changed, window);
|
||||
|
||||
gitg_repository_reload(window->priv->repository);
|
||||
|
|
Loading…
Reference in a new issue