зеркало из https://github.com/microsoft/git.git
log: decorate HEAD with branch name under --decorate=full, too
The previous step to teach "log --decorate" to show "HEAD -> master" instead of "HEAD, master" when showing the commit at the tip of the 'master' branch, when the 'master' branch is checked out, did not work for "log --decorate=full". The commands in the "log" family prepare commit decorations for all refs upfront, and the actual string used in a decoration depends on how load_ref_decorations() is called very early in the process. By default, "git log --decorate" stores names with common prefixes such as "refs/heads" stripped; "git log --decorate=full" stores the full refnames. When the current_pointed_by_HEAD() function has to decide if "HEAD" points at the branch a decoration describes, however, what was passed to load_ref_decorations() to decide to strip (or keep) such a common prefix is long lost. This makes it impossible to reliably tell if a decoration that stores "refs/heads/master", for example, is the 'master' branch (under "--decorate" with prefix omitted) or 'refs/heads/master' branch (under "--decorate=full"). Keep what was passed to load_ref_decorations() in a global next to the global variable name_decoration, and use that to decide how to match what was read from "HEAD" and what is in a decoration. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
51ff0f27bc
Коммит
76c61fbdba
23
log-tree.c
23
log-tree.c
|
@ -13,6 +13,8 @@
|
||||||
#include "line-log.h"
|
#include "line-log.h"
|
||||||
|
|
||||||
static struct decoration name_decoration = { "object names" };
|
static struct decoration name_decoration = { "object names" };
|
||||||
|
static int decoration_loaded;
|
||||||
|
static int decoration_flags;
|
||||||
|
|
||||||
static char decoration_colors[][COLOR_MAXLEN] = {
|
static char decoration_colors[][COLOR_MAXLEN] = {
|
||||||
GIT_COLOR_RESET,
|
GIT_COLOR_RESET,
|
||||||
|
@ -146,9 +148,9 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
|
||||||
|
|
||||||
void load_ref_decorations(int flags)
|
void load_ref_decorations(int flags)
|
||||||
{
|
{
|
||||||
static int loaded;
|
if (!decoration_loaded) {
|
||||||
if (!loaded) {
|
decoration_loaded = 1;
|
||||||
loaded = 1;
|
decoration_flags = flags;
|
||||||
for_each_ref(add_ref_decoration, &flags);
|
for_each_ref(add_ref_decoration, &flags);
|
||||||
head_ref(add_ref_decoration, &flags);
|
head_ref(add_ref_decoration, &flags);
|
||||||
for_each_commit_graft(add_graft_decoration, NULL);
|
for_each_commit_graft(add_graft_decoration, NULL);
|
||||||
|
@ -196,8 +198,19 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
|
||||||
branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags);
|
branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags);
|
||||||
if (!(rru_flags & REF_ISSYMREF))
|
if (!(rru_flags & REF_ISSYMREF))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!skip_prefix(branch_name, "refs/heads/", &branch_name))
|
|
||||||
return NULL;
|
if ((decoration_flags == DECORATE_SHORT_REFS)) {
|
||||||
|
if (!skip_prefix(branch_name, "refs/heads/", &branch_name))
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Each decoration has a refname in full; keep
|
||||||
|
* branch_name also in full, but still make sure
|
||||||
|
* HEAD is a reasonable ref.
|
||||||
|
*/
|
||||||
|
if (!starts_with(branch_name, "refs/"))
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* OK, do we have that ref in the list? */
|
/* OK, do we have that ref in the list? */
|
||||||
for (list = decoration; list; list = list->next)
|
for (list = decoration; list; list = list->next)
|
||||||
|
|
|
@ -5,7 +5,7 @@ Date: Mon Jun 26 00:06:00 2006 +0000
|
||||||
|
|
||||||
Rearranged lines in dir/sub
|
Rearranged lines in dir/sub
|
||||||
|
|
||||||
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, refs/heads/master)
|
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master)
|
||||||
Merge: 9a6d494 c7a2ab9
|
Merge: 9a6d494 c7a2ab9
|
||||||
Author: A U Thor <author@example.com>
|
Author: A U Thor <author@example.com>
|
||||||
Date: Mon Jun 26 00:04:00 2006 +0000
|
Date: Mon Jun 26 00:04:00 2006 +0000
|
||||||
|
|
Загрузка…
Ссылка в новой задаче