提交 a1e3c2c1 编写于 作者: J Junio C Hamano

Merge branch 'rs/decorate'

* rs/decorate:
  add '%d' pretty format specifier to show decoration
  move load_ref_decorations() to log-tree.c and export it
  log: add load_ref_decorations()
......@@ -116,6 +116,7 @@ The placeholders are:
- '%cr': committer date, relative
- '%ct': committer date, UNIX timestamp
- '%ci': committer date, ISO 8601 format
- '%d': ref names, like the --decorate option of linkgit:git-log[1]
- '%e': encoding
- '%s': subject
- '%b': body
......
......@@ -14,7 +14,6 @@
#include "tag.h"
#include "reflog-walk.h"
#include "patch-ids.h"
#include "refs.h"
#include "run-command.h"
#include "shortlog.h"
......@@ -25,31 +24,6 @@ static int default_show_root = 1;
static const char *fmt_patch_subject_prefix = "PATCH";
static const char *fmt_pretty;
static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
{
int plen = strlen(prefix);
int nlen = strlen(name);
struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
memcpy(res->name, prefix, plen);
memcpy(res->name + plen, name, nlen + 1);
res->next = add_decoration(&name_decoration, obj, res);
}
static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
struct object *obj = parse_object(sha1);
if (!obj)
return 0;
add_name_decoration("", refname, obj);
while (obj->type == OBJ_TAG) {
obj = ((struct tag *)obj)->tagged;
if (!obj)
break;
add_name_decoration("tag: ", refname, obj);
}
return 0;
}
static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev)
{
......@@ -80,8 +54,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "--decorate")) {
if (!decorate)
for_each_ref(add_ref_decoration, NULL);
load_ref_decorations();
decorate = 1;
} else
die("unrecognized argument: %s", arg);
......
#include "cache.h"
#include "diff.h"
#include "commit.h"
#include "tag.h"
#include "graph.h"
#include "log-tree.h"
#include "reflog-walk.h"
#include "refs.h"
struct decoration name_decoration = { "object names" };
static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
{
int plen = strlen(prefix);
int nlen = strlen(name);
struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
memcpy(res->name, prefix, plen);
memcpy(res->name + plen, name, nlen + 1);
res->next = add_decoration(&name_decoration, obj, res);
}
static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
struct object *obj = parse_object(sha1);
if (!obj)
return 0;
add_name_decoration("", refname, obj);
while (obj->type == OBJ_TAG) {
obj = ((struct tag *)obj)->tagged;
if (!obj)
break;
add_name_decoration("tag: ", refname, obj);
}
return 0;
}
void load_ref_decorations(void)
{
static int loaded;
if (!loaded) {
loaded = 1;
for_each_ref(add_ref_decoration, NULL);
}
}
static void show_parents(struct commit *commit, int abbrev)
{
struct commit_list *p;
......
......@@ -17,5 +17,6 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
const char **subject_p,
const char **extra_headers_p,
int *need_8bit_cte_p);
void load_ref_decorations(void);
#endif
......@@ -5,6 +5,7 @@
#include "revision.h"
#include "string-list.h"
#include "mailmap.h"
#include "log-tree.h"
static char *user_format;
......@@ -481,6 +482,23 @@ static void parse_commit_header(struct format_commit_context *context)
context->commit_header_parsed = 1;
}
static void format_decoration(struct strbuf *sb, const struct commit *commit)
{
struct name_decoration *d;
const char *prefix = " (";
load_ref_decorations();
d = lookup_decoration(&name_decoration, &commit->object);
while (d) {
strbuf_addstr(sb, prefix);
prefix = ", ";
strbuf_addstr(sb, d->name);
d = d->next;
}
if (prefix[0] == ',')
strbuf_addch(sb, ')');
}
static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
void *context)
{
......@@ -573,6 +591,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
? '<'
: '>');
return 1;
case 'd':
format_decoration(sb, commit);
return 1;
}
/* For the rest we have to parse the commit header. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册