Code

Branch view: add %(branch) variable tracking currently selected branch
authorjipey <jipeye@gmail.com>
Mon, 29 Mar 2010 02:49:08 +0000 (22:49 -0400)
committerJonas Fonseca <fonseca@diku.dk>
Tue, 30 Mar 2010 11:29:30 +0000 (07:29 -0400)
This makes it possible to easily change branches from the branch view.

[ jf: updated docs, added NEWS entry, added checkout run request ]

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
NEWS
manual.txt
tig.c
tigrc.5.txt

diff --git a/NEWS b/NEWS
index 07198d3a3452a3faec38a23487def126f9219258..bce72ebf7fd085e3523290c6c8502ba471d8e17a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ Improvements:
 
  - Status view: update the file variable when a line is selected so
    %(file) works as expected.
+ - Branch view: add %(branch) symbol providing access to the selected
+   branch.
  - Branch view: add entry to browse all branches (uses git-log's --all
    flag).
  - Abbreviation of author names can now be configured and toggled.
index 5fd9c510723e905c99e87705c4ed4e3f7e933ae9..cfc26c67840b68d5054767f2b12a11375a228cb3 100644 (file)
@@ -153,6 +153,7 @@ following variables.
 |%(head)               |The currently viewed 'head' ID. Defaults to HEAD
 |%(commit)             |The currently selected commit ID.
 |%(blob)               |The currently selected blob ID.
+|%(branch)             |The currently selected branch name.
 |%(directory)          |The current directory path in the tree view;
                         empty for the root directory.
 |%(file)               |The currently selected file.
diff --git a/tig.c b/tig.c
index 826c3f9be45a5d907f0d5e26a7fd89c94c89de6a..c8ab944dd804192c6f37344fc24d4f19726d7d05 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1730,6 +1730,7 @@ static void
 add_builtin_run_requests(void)
 {
        const char *cherry_pick[] = { "git", "cherry-pick", "%(commit)", NULL };
+       const char *checkout[] = { "git", "checkout", "%(branch)", NULL };
        const char *commit[] = { "git", "commit", NULL };
        const char *gc[] = { "git", "gc", NULL };
        struct {
@@ -1740,6 +1741,7 @@ add_builtin_run_requests(void)
        } reqs[] = {
                { KEYMAP_MAIN,    'C', ARRAY_SIZE(cherry_pick) - 1, cherry_pick },
                { KEYMAP_STATUS,  'C', ARRAY_SIZE(commit) - 1, commit },
+               { KEYMAP_BRANCH,  'C', ARRAY_SIZE(checkout) - 1, checkout },
                { KEYMAP_GENERIC, 'G', ARRAY_SIZE(gc) - 1, gc },
        };
        int i;
@@ -2157,6 +2159,7 @@ static unsigned int current_view;
 static char ref_blob[SIZEOF_REF]       = "";
 static char ref_commit[SIZEOF_REF]     = "HEAD";
 static char ref_head[SIZEOF_REF]       = "HEAD";
+static char ref_branch[SIZEOF_REF]     = "";
 
 struct view {
        const char *name;       /* View name */
@@ -3112,6 +3115,7 @@ format_arg(const char *name)
                FORMAT_VAR("%(head)",           ref_head,       ""),
                FORMAT_VAR("%(commit)",         ref_commit,     ""),
                FORMAT_VAR("%(blob)",           ref_blob,       ""),
+               FORMAT_VAR("%(branch)",         ref_branch,     ""),
        };
        int i;
 
@@ -5440,6 +5444,7 @@ branch_select(struct view *view, struct line *line)
        string_copy_rev(view->ref, branch->ref->id);
        string_copy_rev(ref_commit, branch->ref->id);
        string_copy_rev(ref_head, branch->ref->id);
+       string_copy_rev(ref_branch, branch->ref->name);
 }
 
 static struct view_ops branch_ops = {
index d33056a4f52013efd88a69413de534873a96faef..575164e96065515259b817026d12d45c984f5614 100644 (file)
@@ -222,6 +222,7 @@ are:
 |%(head)               |The currently viewed 'head' ID. Defaults to HEAD
 |%(commit)             |The currently selected commit ID.
 |%(blob)               |The currently selected blob ID.
+|%(branch)             |The currently selected branch name.
 |%(directory)          |The current directory path in the tree view;
                         empty for the root directory.
 |%(file)               |The currently selected file.