commit 2183bbf63dd94765e293607b7dd98e3254cbbf60 from: Stefan Sperling via: Thomas Adam date: Sun Jan 23 22:14:22 2022 UTC show rebase and histedit backups in tog ref view ok naddy commit - e8f02263080ea8f6ff76ae63d06d6de4c4212c55 commit + 2183bbf63dd94765e293607b7dd98e3254cbbf60 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 - 6682116ce8b01263a346aa10379da1ca4959bc69 blob + 63aab9307dfe089eb2cccf7079df0413fbef4f80 --- tog/tog.c +++ tog/tog.c @@ -135,6 +135,29 @@ STAILQ_HEAD(tog_colors, tog_color); static struct got_reflist_head tog_refs = TAILQ_HEAD_INITIALIZER(tog_refs); 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) @@ -142,7 +165,7 @@ tog_load_refs(struct got_repository *repo, int sort_by 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; @@ -252,6 +275,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; } @@ -362,6 +387,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 */ @@ -1270,7 +1296,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; @@ -5772,7 +5799,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)); @@ -5835,6 +5865,12 @@ open_ref_view(struct tog_view *view, struct got_reposi err = add_color(&s->colors, "^refs/remotes/", TOG_COLOR_REFS_REMOTES, 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; } @@ -6245,7 +6281,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);