commit - 428649877ce32ed472c8f2981ed805ec682732fd
commit + f76670f06a0f4f426ea232a2dd02899fe3698cf2
blob - f978e93058d0e2a0ba0fc2fe42c3385a24fbf75c
blob + 725ee9de4a46977eca7fdd68eefd7e740dc2cf08
--- got/got.1
+++ got/got.1
.It * Ta work tree's base commit matches the branch tip
.It \(a~ Ta work tree's base commit is out-of-date
.El
+.It Fl t
+Sort listed branches by modification time (most recently modified first)
+instead of sorting by lexicographical order.
+Branches in the
+.Dq refs/heads/
+reference namespace are listed before branches in
+.Dq refs/remotes/
+regardless.
+Use of this option requires the
+.Fl l
+option to be used as well.
.It Fl d Ar name
Delete the branch with the specified
.Ar name
blob - 34fa60a650ef8a73873242635c42f9e8e2cc8806
blob + 2bf465ebc8c8f62842d7a3110a14e10d8220936f
--- got/got.c
+++ got/got.c
usage_branch(void)
{
fprintf(stderr,
- "usage: %s branch [-c commit] [-d] [-r repository] [-l] [-n] "
- "[name]\n", getprogname());
+ "usage: %s branch [-c commit] [-d] [-r repository] [-l] [-t] "
+ "[-n] [name]\n", getprogname());
exit(1);
}
}
static const struct got_error *
-list_branches(struct got_repository *repo, struct got_worktree *worktree)
+list_branches(struct got_repository *repo, struct got_worktree *worktree,
+ int sort_by_time)
{
static const struct got_error *err = NULL;
struct got_reflist_head refs;
}
}
- err = got_ref_list(&refs, repo, "refs/heads",
- got_ref_cmp_by_name, NULL);
+ err = got_ref_list(&refs, repo, "refs/heads", sort_by_time ?
+ got_ref_cmp_by_commit_timestamp_descending : got_ref_cmp_by_name,
+ repo);
if (err)
return err;
got_ref_list_free(&refs);
- err = got_ref_list(&refs, repo, "refs/remotes",
- got_ref_cmp_by_name, NULL);
+ err = got_ref_list(&refs, repo, "refs/remotes", sort_by_time ?
+ got_ref_cmp_by_commit_timestamp_descending : got_ref_cmp_by_name,
+ repo);
if (err)
return err;
struct got_repository *repo = NULL;
struct got_worktree *worktree = NULL;
char *cwd = NULL, *repo_path = NULL;
- int ch, do_list = 0, do_show = 0, do_update = 1;
+ int ch, do_list = 0, do_show = 0, do_update = 1, sort_by_time = 0;
const char *delref = NULL, *commit_id_arg = NULL;
struct got_reference *ref = NULL;
struct got_pathlist_head paths;
TAILQ_INIT(&paths);
- while ((ch = getopt(argc, argv, "c:d:r:ln")) != -1) {
+ while ((ch = getopt(argc, argv, "c:d:r:lnt")) != -1) {
switch (ch) {
case 'c':
commit_id_arg = optarg;
case 'n':
do_update = 0;
break;
+ case 't':
+ sort_by_time = 1;
+ break;
default:
usage_branch();
/* NOTREACHED */
if (do_list && delref)
option_conflict('l', 'd');
+ if (sort_by_time && !do_list)
+ errx(1, "-t option requires -l option");
argc -= optind;
argv += optind;
if (do_show)
error = show_current_branch(repo, worktree);
else if (do_list)
- error = list_branches(repo, worktree);
+ error = list_branches(repo, worktree, sort_by_time);
else if (delref)
error = delete_branch(repo, worktree, delref);
else {