mirror of
https://github.com/git/git
synced 2024-08-24 10:15:51 +00:00
Merge branch 'jk/warn-author-committer-after-commit'
* jk/warn-author-committer-after-commit: user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere commit.c::print_summary: do not release the format string too early commit: allow suppression of implicit identity advice commit: show interesting ident information in summary strbuf: add strbuf_addbuf_percentquote strbuf_expand: convert "%%" to "%" Conflicts: builtin-commit.c ident.c
This commit is contained in:
commit
0877510ad4
|
@ -130,6 +130,10 @@ advice.*::
|
||||||
Advice shown when linkgit:git-merge[1] refuses to
|
Advice shown when linkgit:git-merge[1] refuses to
|
||||||
merge to avoid overwritting local changes.
|
merge to avoid overwritting local changes.
|
||||||
Default: true.
|
Default: true.
|
||||||
|
implicitIdentity::
|
||||||
|
Advice on how to set your identity configuration when
|
||||||
|
your information is guessed from the system username and
|
||||||
|
domain name. Default: true.
|
||||||
--
|
--
|
||||||
|
|
||||||
core.fileMode::
|
core.fileMode::
|
||||||
|
|
|
@ -134,6 +134,7 @@ The placeholders are:
|
||||||
- '%C(...)': color specification, as described in color.branch.* config option
|
- '%C(...)': color specification, as described in color.branch.* config option
|
||||||
- '%m': left, right or boundary mark
|
- '%m': left, right or boundary mark
|
||||||
- '%n': newline
|
- '%n': newline
|
||||||
|
- '%%': a raw '%'
|
||||||
- '%x00': print a byte from a hex code
|
- '%x00': print a byte from a hex code
|
||||||
- '%w([<w>[,<i1>[,<i2>]]])': switch line wrapping, like the -w option of
|
- '%w([<w>[,<i1>[,<i2>]]])': switch line wrapping, like the -w option of
|
||||||
linkgit:git-shortlog[1].
|
linkgit:git-shortlog[1].
|
||||||
|
|
|
@ -199,6 +199,10 @@ character if the letter `n` appears after a `%`. The function returns
|
||||||
the length of the placeholder recognized and `strbuf_expand()` skips
|
the length of the placeholder recognized and `strbuf_expand()` skips
|
||||||
over it.
|
over it.
|
||||||
+
|
+
|
||||||
|
The format `%%` is automatically expanded to a single `%` as a quoting
|
||||||
|
mechanism; callers do not need to handle the `%` placeholder themselves,
|
||||||
|
and the callback function will not be invoked for this placeholder.
|
||||||
|
+
|
||||||
All other characters (non-percent and not skipped ones) are copied
|
All other characters (non-percent and not skipped ones) are copied
|
||||||
verbatim to the strbuf. If the callback returned zero, meaning that the
|
verbatim to the strbuf. If the callback returned zero, meaning that the
|
||||||
placeholder is unknown, then the percent sign is copied, too.
|
placeholder is unknown, then the percent sign is copied, too.
|
||||||
|
@ -214,6 +218,13 @@ which can be used by the programmer of the callback as she sees fit.
|
||||||
placeholder and replacement string. The array needs to be
|
placeholder and replacement string. The array needs to be
|
||||||
terminated by an entry with placeholder set to NULL.
|
terminated by an entry with placeholder set to NULL.
|
||||||
|
|
||||||
|
`strbuf_addbuf_percentquote`::
|
||||||
|
|
||||||
|
Append the contents of one strbuf to another, quoting any
|
||||||
|
percent signs ("%") into double-percents ("%%") in the
|
||||||
|
destination. This is useful for literal data to be fed to either
|
||||||
|
strbuf_expand or to the *printf family of functions.
|
||||||
|
|
||||||
`strbuf_addf`::
|
`strbuf_addf`::
|
||||||
|
|
||||||
Add a formatted string to the buffer.
|
Add a formatted string to the buffer.
|
||||||
|
|
2
advice.c
2
advice.c
|
@ -3,6 +3,7 @@
|
||||||
int advice_push_nonfastforward = 1;
|
int advice_push_nonfastforward = 1;
|
||||||
int advice_status_hints = 1;
|
int advice_status_hints = 1;
|
||||||
int advice_commit_before_merge = 1;
|
int advice_commit_before_merge = 1;
|
||||||
|
int advice_implicit_identity = 1;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -11,6 +12,7 @@ static struct {
|
||||||
{ "pushnonfastforward", &advice_push_nonfastforward },
|
{ "pushnonfastforward", &advice_push_nonfastforward },
|
||||||
{ "statushints", &advice_status_hints },
|
{ "statushints", &advice_status_hints },
|
||||||
{ "commitbeforemerge", &advice_commit_before_merge },
|
{ "commitbeforemerge", &advice_commit_before_merge },
|
||||||
|
{ "implicitidentity", &advice_implicit_identity },
|
||||||
};
|
};
|
||||||
|
|
||||||
int git_default_advice_config(const char *var, const char *value)
|
int git_default_advice_config(const char *var, const char *value)
|
||||||
|
|
1
advice.h
1
advice.h
|
@ -4,6 +4,7 @@
|
||||||
extern int advice_push_nonfastforward;
|
extern int advice_push_nonfastforward;
|
||||||
extern int advice_status_hints;
|
extern int advice_status_hints;
|
||||||
extern int advice_commit_before_merge;
|
extern int advice_commit_before_merge;
|
||||||
|
extern int advice_implicit_identity;
|
||||||
|
|
||||||
int git_default_advice_config(const char *var, const char *value);
|
int git_default_advice_config(const char *var, const char *value);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,20 @@ static const char * const builtin_status_usage[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char implicit_ident_advice[] =
|
||||||
|
"Your name and email address were configured automatically based\n"
|
||||||
|
"on your username and hostname. Please check that they are accurate.\n"
|
||||||
|
"You can suppress this message by setting them explicitly:\n"
|
||||||
|
"\n"
|
||||||
|
" git config --global user.name Your Name\n"
|
||||||
|
" git config --global user.email you@example.com\n"
|
||||||
|
"\n"
|
||||||
|
"If the identity used for this commit is wrong, you can fix it with:\n"
|
||||||
|
"\n"
|
||||||
|
" git commit --amend --author='Your Name <you@example.com>'\n";
|
||||||
|
|
||||||
static unsigned char head_sha1[20];
|
static unsigned char head_sha1[20];
|
||||||
|
|
||||||
static char *use_message_buffer;
|
static char *use_message_buffer;
|
||||||
static const char commit_editmsg[] = "COMMIT_EDITMSG";
|
static const char commit_editmsg[] = "COMMIT_EDITMSG";
|
||||||
static struct lock_file index_lock; /* real index */
|
static struct lock_file index_lock; /* real index */
|
||||||
|
@ -1055,9 +1068,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
static const char *format = "format:%h] %s";
|
struct strbuf format = STRBUF_INIT;
|
||||||
unsigned char junk_sha1[20];
|
unsigned char junk_sha1[20];
|
||||||
const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
|
const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
|
||||||
|
struct pretty_print_context pctx = {0};
|
||||||
|
struct strbuf author_ident = STRBUF_INIT;
|
||||||
|
struct strbuf committer_ident = STRBUF_INIT;
|
||||||
|
|
||||||
commit = lookup_commit(sha1);
|
commit = lookup_commit(sha1);
|
||||||
if (!commit)
|
if (!commit)
|
||||||
|
@ -1065,6 +1081,25 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
||||||
if (!commit || parse_commit(commit))
|
if (!commit || parse_commit(commit))
|
||||||
die("could not parse newly created commit");
|
die("could not parse newly created commit");
|
||||||
|
|
||||||
|
strbuf_addstr(&format, "format:%h] %s");
|
||||||
|
|
||||||
|
format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
|
||||||
|
format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
|
||||||
|
if (strbuf_cmp(&author_ident, &committer_ident)) {
|
||||||
|
strbuf_addstr(&format, "\n Author: ");
|
||||||
|
strbuf_addbuf_percentquote(&format, &author_ident);
|
||||||
|
}
|
||||||
|
if (!user_ident_sufficiently_given()) {
|
||||||
|
strbuf_addstr(&format, "\n Committer: ");
|
||||||
|
strbuf_addbuf_percentquote(&format, &committer_ident);
|
||||||
|
if (advice_implicit_identity) {
|
||||||
|
strbuf_addch(&format, '\n');
|
||||||
|
strbuf_addstr(&format, implicit_ident_advice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strbuf_release(&author_ident);
|
||||||
|
strbuf_release(&committer_ident);
|
||||||
|
|
||||||
init_revisions(&rev, prefix);
|
init_revisions(&rev, prefix);
|
||||||
setup_revisions(0, NULL, &rev, NULL);
|
setup_revisions(0, NULL, &rev, NULL);
|
||||||
|
|
||||||
|
@ -1075,7 +1110,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
||||||
|
|
||||||
rev.verbose_header = 1;
|
rev.verbose_header = 1;
|
||||||
rev.show_root_diff = 1;
|
rev.show_root_diff = 1;
|
||||||
get_commit_format(format, &rev);
|
get_commit_format(format.buf, &rev);
|
||||||
rev.always_show_header = 0;
|
rev.always_show_header = 0;
|
||||||
rev.diffopt.detect_rename = 1;
|
rev.diffopt.detect_rename = 1;
|
||||||
rev.diffopt.rename_limit = 100;
|
rev.diffopt.rename_limit = 100;
|
||||||
|
@ -1094,10 +1129,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
||||||
struct pretty_print_context ctx = {0};
|
struct pretty_print_context ctx = {0};
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
ctx.date_mode = DATE_NORMAL;
|
ctx.date_mode = DATE_NORMAL;
|
||||||
format_commit_message(commit, format + 7, &buf, &ctx);
|
format_commit_message(commit, format.buf + 7, &buf, &ctx);
|
||||||
printf("%s\n", buf.buf);
|
printf("%s\n", buf.buf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
|
strbuf_release(&format);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_commit_config(const char *k, const char *v, void *cb)
|
static int git_commit_config(const char *k, const char *v, void *cb)
|
||||||
|
|
1
daemon.c
1
daemon.c
|
@ -147,7 +147,6 @@ static char *path_ok(char *directory)
|
||||||
{ "IP", ip_address },
|
{ "IP", ip_address },
|
||||||
{ "P", tcp_port },
|
{ "P", tcp_port },
|
||||||
{ "D", directory },
|
{ "D", directory },
|
||||||
{ "%", "%" },
|
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
17
strbuf.c
17
strbuf.c
|
@ -220,6 +220,12 @@ void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
|
||||||
break;
|
break;
|
||||||
format = percent + 1;
|
format = percent + 1;
|
||||||
|
|
||||||
|
if (*format == '%') {
|
||||||
|
strbuf_addch(sb, '%');
|
||||||
|
format++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
consumed = fn(sb, format, context);
|
consumed = fn(sb, format, context);
|
||||||
if (consumed)
|
if (consumed)
|
||||||
format += consumed;
|
format += consumed;
|
||||||
|
@ -244,6 +250,17 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
|
||||||
|
{
|
||||||
|
int i, len = src->len;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (src->buf[i] == '%')
|
||||||
|
strbuf_addch(dst, '%');
|
||||||
|
strbuf_addch(dst, src->buf[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
|
size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
|
||||||
{
|
{
|
||||||
size_t res;
|
size_t res;
|
||||||
|
|
1
strbuf.h
1
strbuf.h
|
@ -115,6 +115,7 @@ struct strbuf_expand_dict_entry {
|
||||||
const char *value;
|
const char *value;
|
||||||
};
|
};
|
||||||
extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context);
|
extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context);
|
||||||
|
extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src);
|
||||||
|
|
||||||
__attribute__((format (printf,2,3)))
|
__attribute__((format (printf,2,3)))
|
||||||
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
|
extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
|
||||||
|
|
|
@ -19,6 +19,13 @@ test_cmp expect.$1 output.$1
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_format percent %%h <<'EOF'
|
||||||
|
commit 131a310eb913d107dd3c09a65d1651175898735d
|
||||||
|
%h
|
||||||
|
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
|
||||||
|
%h
|
||||||
|
EOF
|
||||||
|
|
||||||
test_format hash %H%n%h <<'EOF'
|
test_format hash %H%n%h <<'EOF'
|
||||||
commit 131a310eb913d107dd3c09a65d1651175898735d
|
commit 131a310eb913d107dd3c09a65d1651175898735d
|
||||||
131a310eb913d107dd3c09a65d1651175898735d
|
131a310eb913d107dd3c09a65d1651175898735d
|
||||||
|
|
|
@ -117,7 +117,11 @@ test_expect_success \
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
"overriding author from command line" \
|
"overriding author from command line" \
|
||||||
"echo 'gak' >file && \
|
"echo 'gak' >file && \
|
||||||
git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
|
git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
|
||||||
|
|
||||||
|
test_expect_success \
|
||||||
|
"commit --author output mentions author" \
|
||||||
|
"grep Rubber.Duck output"
|
||||||
|
|
||||||
test_expect_success PERL \
|
test_expect_success PERL \
|
||||||
"interactive add" \
|
"interactive add" \
|
||||||
|
|
Loading…
Reference in a new issue