Code

Update the current branch information when reloading all references
authorJonas Fonseca <fonseca@diku.dk>
Thu, 19 Feb 2009 01:21:39 +0000 (02:21 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 19 Feb 2009 01:21:39 +0000 (02:21 +0100)
Fixes problem of improper highlighting of current branch after switching
branch and reloading.

tig.c

diff --git a/tig.c b/tig.c
index 5acb3988098720a0748b39380e778e61202bed4e..85fe9811d46f8625f84439330e8647bc2530b858 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -6658,6 +6658,9 @@ read_ref(char *id, size_t idlen, char *name, size_t namelen)
 static int
 load_refs(void)
 {
+       const char *head_argv[] = {
+               "git", "symbolic-ref", "HEAD", NULL
+       };
        static const char *ls_remote_argv[SIZEOF_ARG] = {
                "git", "ls-remote", opt_git_dir, NULL
        };
@@ -6671,6 +6674,15 @@ load_refs(void)
        if (!*opt_git_dir)
                return OK;
 
+       if (run_io_buf(head_argv, opt_head, sizeof(opt_head))) {
+               chomp_string(opt_head);
+               if (!prefixcmp(opt_head, "refs/heads/")) {
+                       char *offset = opt_head + STRING_SIZE("refs/heads/");
+
+                       memmove(opt_head, offset, strlen(offset) + 1);
+               }
+       }
+
        while (refs_size > 0)
                free(refs[--refs_size].name);
        while (id_refs_size > 0)
@@ -6813,23 +6825,11 @@ read_repo_info(char *name, size_t namelen, char *value, size_t valuelen)
 static int
 load_repo_info(void)
 {
-       const char *head_argv[] = {
-               "git", "symbolic-ref", "HEAD", NULL
-       };
        const char *rev_parse_argv[] = {
                "git", "rev-parse", "--git-dir", "--is-inside-work-tree",
                        "--show-cdup", "--show-prefix", NULL
        };
 
-       if (run_io_buf(head_argv, opt_head, sizeof(opt_head))) {
-               chomp_string(opt_head);
-               if (!prefixcmp(opt_head, "refs/heads/")) {
-                       char *offset = opt_head + STRING_SIZE("refs/heads/");
-
-                       memmove(opt_head, offset, strlen(offset) + 1);
-               }
-       }
-
        return run_io_load(rev_parse_argv, "=", read_repo_info);
 }