Download raw body.
show rebase and histedit backups in tog ref view
This patch allows for browing rebase/histedit backups with tog, as an an interactive alternative to 'got rebase -l' and 'got histedit -l'. With refs sorted by name, backups appear towards the end up the list, which prevents backups from cluttering up the ref view by default. With refs sorted by date, backups appear interleaved with other refs, which is useful for browsing through recent backups. Backups will usually appear just after their corresponding branch in refs/heads/. For people who use colors, backups are highlighted differently from other refs by default to make it easier to tell them apart. ok? diff b1f2dff2aa4394b54e7cef2f36c8df8c8fc86549 539d7f50c3f9cd3c4e5b39cf69858c90d9b10ea3 blob - aa7df3d3b754778dbe00fa95a687598e151f1566 blob + 7891dc0361f6c50d00493676ef0e020ff215b8b2 --- tog/tog.1 +++ tog/tog.1 @@ -577,6 +577,13 @@ namespace. If not set, the default value .Dq yellow is used. +.It Ev TOG_COLOR_REFS_BACKUP +The color used to mark up references in the +.Dq refs/got/backup/ +namespace. +If not set, the default value +.Dq cyan +is used. .El .Sh EXIT STATUS .Ex -std tog blob - 4416f593bba3dbb60a7843b0b4a2dba74aa17ba2 blob + 982154f8af09a3beb7bda5bd21732225bfbeeade --- tog/tog.c +++ tog/tog.c @@ -129,12 +129,35 @@ static struct got_reflist_head tog_refs = TAILQ_HEAD_I static struct got_reflist_object_id_map *tog_refs_idmap; static const struct got_error * +tog_ref_cmp_by_name(void *arg, int *cmp, struct got_reference *re1, + struct got_reference* re2) +{ + const char *name1 = got_ref_get_name(re1); + const char *name2 = got_ref_get_name(re2); + int isbackup1, isbackup2; + + /* Sort backup refs towards the bottom of the list. */ + isbackup1 = strncmp(name1, "refs/got/backup/", 16) == 0; + isbackup2 = strncmp(name2, "refs/got/backup/", 16) == 0; + if (!isbackup1 && isbackup2) { + *cmp = -1; + return NULL; + } else if (isbackup1 && !isbackup2) { + *cmp = 1; + return NULL; + } + + *cmp = got_path_cmp(name1, name2, strlen(name1), strlen(name2)); + return NULL; +} + +static const struct got_error * tog_load_refs(struct got_repository *repo, int sort_by_date) { const struct got_error *err; err = got_ref_list(&tog_refs, repo, NULL, sort_by_date ? - got_ref_cmp_by_commit_timestamp_descending : got_ref_cmp_by_name, + got_ref_cmp_by_commit_timestamp_descending : tog_ref_cmp_by_name, repo); if (err) return err; @@ -244,6 +267,8 @@ default_color_value(const char *envvar) return COLOR_MAGENTA; if (strcmp(envvar, "TOG_COLOR_REFS_REMOTES") == 0) return COLOR_YELLOW; + if (strcmp(envvar, "TOG_COLOR_REFS_BACKUP") == 0) + return COLOR_CYAN; return -1; } @@ -354,6 +379,7 @@ struct tog_log_view_state { #define TOG_COLOR_REFS_HEADS 12 #define TOG_COLOR_REFS_TAGS 13 #define TOG_COLOR_REFS_REMOTES 14 +#define TOG_COLOR_REFS_BACKUP 15 struct tog_blame_cb_args { struct tog_blame_line *lines; /* one per line */ @@ -1262,7 +1288,8 @@ build_refs_str(char **refs_str, struct got_reflist_hea continue; if (strncmp(name, "refs/", 5) == 0) name += 5; - if (strncmp(name, "got/", 4) == 0) + if (strncmp(name, "got/", 4) == 0 && + strncmp(name, "got/backup/", 11) != 0) continue; if (strncmp(name, "heads/", 6) == 0) name += 6; @@ -5762,7 +5789,10 @@ ref_view_load_refs(struct tog_ref_view_state *s) s->nrefs = 0; TAILQ_FOREACH(sre, &tog_refs, entry) { - if (strncmp(got_ref_get_name(sre->ref), "refs/got/", 9) == 0) + if (strncmp(got_ref_get_name(sre->ref), + "refs/got/", 9) == 0 && + strncmp(got_ref_get_name(sre->ref), + "refs/got/backup/", 16) != 0) continue; re = malloc(sizeof(*re)); @@ -5827,6 +5857,12 @@ open_ref_view(struct tog_view *view, struct got_reposi get_color_value("TOG_COLOR_REFS_REMOTES")); if (err) goto done; + + err = add_color(&s->colors, "^refs/got/backup/", + TOG_COLOR_REFS_BACKUP, + get_color_value("TOG_COLOR_REFS_BACKUP")); + if (err) + goto done; } view->show = show_ref_view; @@ -6235,7 +6271,7 @@ input_ref_view(struct tog_view **new_view, struct tog_ s->sort_by_date = !s->sort_by_date; err = got_reflist_sort(&tog_refs, s->sort_by_date ? got_ref_cmp_by_commit_timestamp_descending : - got_ref_cmp_by_name, s->repo); + tog_ref_cmp_by_name, s->repo); if (err) break; got_reflist_object_id_map_free(tog_refs_idmap);
show rebase and histedit backups in tog ref view