2010-02-14 05:28:20 +08:00
|
|
|
/*
|
|
|
|
* Builtin "git notes"
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Johan Herland <johan@herland.net>
|
|
|
|
*
|
|
|
|
* Based on git-notes.sh by Johannes Schindelin,
|
2013-06-19 01:44:58 +08:00
|
|
|
* and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
|
2010-02-14 05:28:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "builtin.h"
|
2023-05-16 14:33:57 +08:00
|
|
|
#include "config.h"
|
2023-04-11 15:41:57 +08:00
|
|
|
#include "editor.h"
|
2023-06-07 03:48:43 +08:00
|
|
|
#include "environment.h"
|
2023-03-21 14:25:54 +08:00
|
|
|
#include "gettext.h"
|
2023-02-24 08:09:27 +08:00
|
|
|
#include "hex.h"
|
2010-02-14 05:28:20 +08:00
|
|
|
#include "notes.h"
|
2023-04-11 15:41:49 +08:00
|
|
|
#include "object-name.h"
|
2023-05-16 14:34:06 +08:00
|
|
|
#include "object-store-ll.h"
|
2023-05-16 14:33:59 +08:00
|
|
|
#include "path.h"
|
2018-06-29 09:21:58 +08:00
|
|
|
#include "repository.h"
|
2017-12-12 16:55:35 +08:00
|
|
|
#include "pretty.h"
|
2010-02-14 05:28:20 +08:00
|
|
|
#include "refs.h"
|
2018-04-11 05:26:18 +08:00
|
|
|
#include "exec-cmd.h"
|
2010-02-14 05:28:20 +08:00
|
|
|
#include "run-command.h"
|
|
|
|
#include "parse-options.h"
|
2010-03-13 01:04:32 +08:00
|
|
|
#include "string-list.h"
|
2010-11-10 05:49:46 +08:00
|
|
|
#include "notes-merge.h"
|
2013-06-12 08:13:00 +08:00
|
|
|
#include "notes-utils.h"
|
2015-10-02 19:55:31 +08:00
|
|
|
#include "worktree.h"
|
2023-03-21 14:26:07 +08:00
|
|
|
#include "write-or-die.h"
|
2012-09-16 04:56:07 +08:00
|
|
|
|
2023-05-27 15:57:54 +08:00
|
|
|
static const char *separator = "\n";
|
2010-02-14 05:28:20 +08:00
|
|
|
static const char * const git_notes_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] [list [<object>]]"),
|
2023-05-27 15:57:54 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"),
|
2023-05-27 15:57:54 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] show [<object>]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"),
|
2022-02-01 06:07:48 +08:00
|
|
|
"git notes merge --commit [-v | -q]",
|
|
|
|
"git notes merge --abort [-v | -q]",
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] remove [<object>...]"),
|
2017-11-22 03:17:21 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] prune [-n] [-v]"),
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes [--ref <notes-ref>] get-ref"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_list_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes [list [<object>]]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_add_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes add [<options>] [<object>]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_copy_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes copy [<options>] <from-object> <to-object>"),
|
|
|
|
N_("git notes copy --stdin [<from-object> <to-object>]..."),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_append_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes append [<options>] [<object>]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_edit_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes edit [<object>]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_show_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes show [<object>]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-11-10 05:49:46 +08:00
|
|
|
static const char * const git_notes_merge_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git notes merge [<options>] <notes-ref>"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes merge --commit [<options>]"),
|
|
|
|
N_("git notes merge --abort [<options>]"),
|
2010-11-10 05:49:46 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
static const char * const git_notes_remove_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes remove [<object>]"),
|
2010-02-27 16:59:22 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_prune_usage[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("git notes prune [<options>]"),
|
2010-02-14 05:28:20 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-11-10 05:49:57 +08:00
|
|
|
static const char * const git_notes_get_ref_usage[] = {
|
2022-02-01 06:07:48 +08:00
|
|
|
"git notes get-ref",
|
2010-11-10 05:49:57 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-02-14 05:28:20 +08:00
|
|
|
static const char note_template[] =
|
2016-07-28 19:26:15 +08:00
|
|
|
N_("Write/edit the notes for the following object:");
|
2010-02-14 05:28:20 +08:00
|
|
|
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
enum notes_stripspace {
|
|
|
|
UNSPECIFIED = -1,
|
|
|
|
NO_STRIPSPACE = 0,
|
|
|
|
STRIPSPACE = 1,
|
|
|
|
};
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct note_msg {
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
enum notes_stripspace stripspace;
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct strbuf buf;
|
|
|
|
};
|
|
|
|
|
2014-11-09 20:30:49 +08:00
|
|
|
struct note_data {
|
2010-02-14 05:28:35 +08:00
|
|
|
int given;
|
2010-02-14 05:28:36 +08:00
|
|
|
int use_editor;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
int stripspace;
|
2014-11-09 20:30:50 +08:00
|
|
|
char *edit_path;
|
2010-02-14 05:28:35 +08:00
|
|
|
struct strbuf buf;
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct note_msg **messages;
|
|
|
|
size_t msg_nr;
|
|
|
|
size_t msg_alloc;
|
2010-02-14 05:28:35 +08:00
|
|
|
};
|
|
|
|
|
2014-11-09 20:30:50 +08:00
|
|
|
static void free_note_data(struct note_data *d)
|
|
|
|
{
|
|
|
|
if (d->edit_path) {
|
|
|
|
unlink_or_warn(d->edit_path);
|
|
|
|
free(d->edit_path);
|
|
|
|
}
|
|
|
|
strbuf_release(&d->buf);
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
|
|
|
|
while (d->msg_nr--) {
|
|
|
|
strbuf_release(&d->messages[d->msg_nr]->buf);
|
|
|
|
free(d->messages[d->msg_nr]);
|
|
|
|
}
|
|
|
|
free(d->messages);
|
2014-11-09 20:30:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:39 +08:00
|
|
|
static int list_each_note(const struct object_id *object_oid,
|
2023-02-24 14:39:31 +08:00
|
|
|
const struct object_id *note_oid,
|
|
|
|
char *note_path UNUSED,
|
|
|
|
void *cb_data UNUSED)
|
2010-02-14 05:28:30 +08:00
|
|
|
{
|
2017-05-31 01:30:39 +08:00
|
|
|
printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid));
|
2010-02-14 05:28:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 10:27:48 +08:00
|
|
|
static void copy_obj_to_fd(int fd, const struct object_id *oid)
|
2010-02-14 05:28:20 +08:00
|
|
|
{
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
2023-03-28 21:58:50 +08:00
|
|
|
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
|
2010-02-14 05:28:20 +08:00
|
|
|
if (buf) {
|
|
|
|
if (size)
|
|
|
|
write_or_die(fd, buf, size);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:42 +08:00
|
|
|
static void write_commented_object(int fd, const struct object_id *object)
|
2010-02-14 05:28:20 +08:00
|
|
|
{
|
2014-08-20 03:09:35 +08:00
|
|
|
struct child_process show = CHILD_PROCESS_INIT;
|
2010-02-14 05:28:20 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2013-01-17 03:18:48 +08:00
|
|
|
struct strbuf cbuf = STRBUF_INIT;
|
2010-02-14 05:28:20 +08:00
|
|
|
|
|
|
|
/* Invoke "git show --stat --no-notes $object" */
|
2021-11-26 06:52:20 +08:00
|
|
|
strvec_pushl(&show.args, "show", "--stat", "--no-notes",
|
|
|
|
oid_to_hex(object), NULL);
|
2010-02-14 05:28:20 +08:00
|
|
|
show.no_stdin = 1;
|
|
|
|
show.out = -1;
|
|
|
|
show.err = 0;
|
|
|
|
show.git_cmd = 1;
|
|
|
|
if (start_command(&show))
|
2011-02-23 07:42:26 +08:00
|
|
|
die(_("unable to start 'show' for object '%s'"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(object));
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2013-01-17 03:18:48 +08:00
|
|
|
if (strbuf_read(&buf, show.out, 0) < 0)
|
|
|
|
die_errno(_("could not read 'show' output"));
|
2023-06-07 03:48:43 +08:00
|
|
|
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char);
|
2013-01-17 03:18:48 +08:00
|
|
|
write_or_die(fd, cbuf.buf, cbuf.len);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2013-01-17 03:18:48 +08:00
|
|
|
strbuf_release(&cbuf);
|
2010-02-14 05:28:20 +08:00
|
|
|
strbuf_release(&buf);
|
2013-01-17 03:18:48 +08:00
|
|
|
|
2010-02-14 05:28:20 +08:00
|
|
|
if (finish_command(&show))
|
2011-02-23 07:42:26 +08:00
|
|
|
die(_("failed to finish 'show' for object '%s'"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(object));
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:42 +08:00
|
|
|
static void prepare_note_data(const struct object_id *object, struct note_data *d,
|
2018-03-12 10:27:48 +08:00
|
|
|
const struct object_id *old_note)
|
2010-02-14 05:28:20 +08:00
|
|
|
{
|
2014-11-09 20:30:49 +08:00
|
|
|
if (d->use_editor || !d->given) {
|
2010-02-14 05:28:20 +08:00
|
|
|
int fd;
|
2013-01-17 03:18:48 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2010-02-14 05:28:20 +08:00
|
|
|
|
|
|
|
/* write the template message before editing: */
|
2014-11-09 20:30:50 +08:00
|
|
|
d->edit_path = git_pathdup("NOTES_EDITMSG");
|
2021-08-26 04:16:46 +08:00
|
|
|
fd = xopen(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2014-11-09 20:30:49 +08:00
|
|
|
if (d->given)
|
|
|
|
write_or_die(fd, d->buf.buf, d->buf.len);
|
2014-11-12 08:40:13 +08:00
|
|
|
else if (old_note)
|
|
|
|
copy_obj_to_fd(fd, old_note);
|
2013-01-17 03:18:48 +08:00
|
|
|
|
|
|
|
strbuf_addch(&buf, '\n');
|
2023-06-07 03:48:43 +08:00
|
|
|
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
|
|
|
|
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
|
|
|
|
comment_line_char);
|
|
|
|
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
|
2013-01-17 03:18:48 +08:00
|
|
|
write_or_die(fd, buf.buf, buf.len);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
|
|
|
write_commented_object(fd, object);
|
|
|
|
|
|
|
|
close(fd);
|
2013-01-17 03:18:48 +08:00
|
|
|
strbuf_release(&buf);
|
2014-11-09 20:30:49 +08:00
|
|
|
strbuf_reset(&d->buf);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2014-11-09 20:30:50 +08:00
|
|
|
if (launch_editor(d->edit_path, &d->buf, NULL)) {
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("please supply the note contents using either -m or -F option"));
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
if (d->stripspace)
|
2023-07-07 02:54:47 +08:00
|
|
|
strbuf_stripspace(&d->buf, comment_line_char);
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
2014-11-12 08:40:13 +08:00
|
|
|
}
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2018-01-28 08:13:19 +08:00
|
|
|
static void write_note_data(struct note_data *d, struct object_id *oid)
|
2014-11-12 08:40:13 +08:00
|
|
|
{
|
2022-02-05 07:48:26 +08:00
|
|
|
if (write_object_file(d->buf.buf, d->buf.len, OBJ_BLOB, oid)) {
|
2021-12-08 02:26:31 +08:00
|
|
|
int status = die_message(_("unable to write note object"));
|
|
|
|
|
2014-11-12 08:40:13 +08:00
|
|
|
if (d->edit_path)
|
2021-12-08 02:26:31 +08:00
|
|
|
die_message(_("the note contents have been left in %s"),
|
|
|
|
d->edit_path);
|
|
|
|
exit(status);
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
static void append_separator(struct strbuf *message)
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
{
|
2023-05-27 15:57:54 +08:00
|
|
|
size_t sep_len = 0;
|
|
|
|
|
|
|
|
if (!separator)
|
|
|
|
return;
|
|
|
|
else if ((sep_len = strlen(separator)) && separator[sep_len - 1] == '\n')
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
strbuf_addstr(message, separator);
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
else
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
strbuf_addf(message, "%s%s", separator, "\n");
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void concat_messages(struct note_data *d)
|
|
|
|
{
|
|
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
size_t i;
|
2023-05-27 15:57:54 +08:00
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
for (i = 0; i < d->msg_nr ; i++) {
|
|
|
|
if (d->buf.len)
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
append_separator(&d->buf);
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_add(&msg, d->messages[i]->buf.buf, d->messages[i]->buf.len);
|
|
|
|
strbuf_addbuf(&d->buf, &msg);
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
if ((d->stripspace == UNSPECIFIED &&
|
|
|
|
d->messages[i]->stripspace == STRIPSPACE) ||
|
|
|
|
d->stripspace == STRIPSPACE)
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_stripspace(&d->buf, 0);
|
|
|
|
strbuf_reset(&msg);
|
|
|
|
}
|
|
|
|
strbuf_release(&msg);
|
|
|
|
}
|
|
|
|
|
2010-02-14 05:28:20 +08:00
|
|
|
static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 20:30:49 +08:00
|
|
|
struct note_data *d = opt->value;
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct note_msg *msg = xmalloc(sizeof(*msg));
|
2010-02-14 05:28:20 +08:00
|
|
|
|
assert NOARG/NONEG behavior of parse-options callbacks
When we define a parse-options callback, the flags we put in the option
struct must match what the callback expects. For example, a callback
which does not handle the "unset" parameter should only be used with
PARSE_OPT_NONEG. But since the callback and the option struct are not
defined next to each other, it's easy to get this wrong (as earlier
patches in this series show).
Fortunately, the compiler can help us here: compiling with
-Wunused-parameters can show us which callbacks ignore their "unset"
parameters (and likewise, ones that ignore "arg" expect to be triggered
with PARSE_OPT_NOARG).
But after we've inspected a callback and determined that all of its
callers use the right flags, what do we do next? We'd like to silence
the compiler warning, but do so in a way that will catch any wrong calls
in the future.
We can do that by actually checking those variables and asserting that
they match our expectations. Because this is such a common pattern,
we'll introduce some helper macros. The resulting messages aren't
as descriptive as we could make them, but the file/line information from
BUG() is enough to identify the problem (and anyway, the point is that
these should never be seen).
Each of the annotated callbacks in this patch triggers
-Wunused-parameters, and was manually inspected to make sure all callers
use the correct options (so none of these BUGs should be triggerable).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-11-05 14:45:42 +08:00
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_init(&msg->buf, strlen(arg));
|
|
|
|
strbuf_addstr(&msg->buf, arg);
|
|
|
|
ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
|
|
|
|
d->messages[d->msg_nr - 1] = msg;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
msg->stripspace = STRIPSPACE;
|
2010-02-14 05:28:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_file_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 20:30:49 +08:00
|
|
|
struct note_data *d = opt->value;
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct note_msg *msg = xmalloc(sizeof(*msg));
|
2010-02-14 05:28:35 +08:00
|
|
|
|
assert NOARG/NONEG behavior of parse-options callbacks
When we define a parse-options callback, the flags we put in the option
struct must match what the callback expects. For example, a callback
which does not handle the "unset" parameter should only be used with
PARSE_OPT_NONEG. But since the callback and the option struct are not
defined next to each other, it's easy to get this wrong (as earlier
patches in this series show).
Fortunately, the compiler can help us here: compiling with
-Wunused-parameters can show us which callbacks ignore their "unset"
parameters (and likewise, ones that ignore "arg" expect to be triggered
with PARSE_OPT_NOARG).
But after we've inspected a callback and determined that all of its
callers use the right flags, what do we do next? We'd like to silence
the compiler warning, but do so in a way that will catch any wrong calls
in the future.
We can do that by actually checking those variables and asserting that
they match our expectations. Because this is such a common pattern,
we'll introduce some helper macros. The resulting messages aren't
as descriptive as we could make them, but the file/line information from
BUG() is enough to identify the problem (and anyway, the point is that
these should never be seen).
Each of the annotated callbacks in this patch triggers
-Wunused-parameters, and was manually inspected to make sure all callers
use the correct options (so none of these BUGs should be triggerable).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-11-05 14:45:42 +08:00
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_init(&msg->buf , 0);
|
2010-02-14 05:28:35 +08:00
|
|
|
if (!strcmp(arg, "-")) {
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
if (strbuf_read(&msg->buf, 0, 1024) < 0)
|
2011-02-23 07:42:26 +08:00
|
|
|
die_errno(_("cannot read '%s'"), arg);
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
} else if (strbuf_read_file(&msg->buf, arg, 1024) < 0)
|
2011-02-23 07:42:26 +08:00
|
|
|
die_errno(_("could not open or read '%s'"), arg);
|
2010-02-14 05:28:35 +08:00
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
|
|
|
|
d->messages[d->msg_nr - 1] = msg;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
msg->stripspace = STRIPSPACE;
|
2010-02-14 05:28:20 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-14 05:28:36 +08:00
|
|
|
static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 20:30:49 +08:00
|
|
|
struct note_data *d = opt->value;
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
struct note_msg *msg = xmalloc(sizeof(*msg));
|
|
|
|
char *value;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object;
|
2010-02-14 05:28:36 +08:00
|
|
|
enum object_type type;
|
|
|
|
unsigned long len;
|
|
|
|
|
assert NOARG/NONEG behavior of parse-options callbacks
When we define a parse-options callback, the flags we put in the option
struct must match what the callback expects. For example, a callback
which does not handle the "unset" parameter should only be used with
PARSE_OPT_NONEG. But since the callback and the option struct are not
defined next to each other, it's easy to get this wrong (as earlier
patches in this series show).
Fortunately, the compiler can help us here: compiling with
-Wunused-parameters can show us which callbacks ignore their "unset"
parameters (and likewise, ones that ignore "arg" expect to be triggered
with PARSE_OPT_NOARG).
But after we've inspected a callback and determined that all of its
callers use the right flags, what do we do next? We'd like to silence
the compiler warning, but do so in a way that will catch any wrong calls
in the future.
We can do that by actually checking those variables and asserting that
they match our expectations. Because this is such a common pattern,
we'll introduce some helper macros. The resulting messages aren't
as descriptive as we could make them, but the file/line information from
BUG() is enough to identify the problem (and anyway, the point is that
these should never be seen).
Each of the annotated callbacks in this patch triggers
-Wunused-parameters, and was manually inspected to make sure all callers
use the correct options (so none of these BUGs should be triggerable).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-11-05 14:45:42 +08:00
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_init(&msg->buf, 0);
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, arg, &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), arg);
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to read object '%s'."), arg);
|
2014-02-12 17:54:16 +08:00
|
|
|
if (type != OBJ_BLOB) {
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_release(&msg->buf);
|
|
|
|
free(value);
|
|
|
|
free(msg);
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("cannot read note data from non-blob object '%s'."), arg);
|
2010-02-14 05:28:36 +08:00
|
|
|
}
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
strbuf_add(&msg->buf, value, len);
|
|
|
|
free(value);
|
|
|
|
|
|
|
|
msg->buf.len = len;
|
|
|
|
ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
|
|
|
|
d->messages[d->msg_nr - 1] = msg;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
msg->stripspace = NO_STRIPSPACE;
|
2010-02-14 05:28:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 20:30:49 +08:00
|
|
|
struct note_data *d = opt->value;
|
assert NOARG/NONEG behavior of parse-options callbacks
When we define a parse-options callback, the flags we put in the option
struct must match what the callback expects. For example, a callback
which does not handle the "unset" parameter should only be used with
PARSE_OPT_NONEG. But since the callback and the option struct are not
defined next to each other, it's easy to get this wrong (as earlier
patches in this series show).
Fortunately, the compiler can help us here: compiling with
-Wunused-parameters can show us which callbacks ignore their "unset"
parameters (and likewise, ones that ignore "arg" expect to be triggered
with PARSE_OPT_NOARG).
But after we've inspected a callback and determined that all of its
callers use the right flags, what do we do next? We'd like to silence
the compiler warning, but do so in a way that will catch any wrong calls
in the future.
We can do that by actually checking those variables and asserting that
they match our expectations. Because this is such a common pattern,
we'll introduce some helper macros. The resulting messages aren't
as descriptive as we could make them, but the file/line information from
BUG() is enough to identify the problem (and anyway, the point is that
these should never be seen).
Each of the annotated callbacks in this patch triggers
-Wunused-parameters, and was manually inspected to make sure all callers
use the correct options (so none of these BUGs should be triggerable).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-11-05 14:45:42 +08:00
|
|
|
BUG_ON_OPT_NEG(unset);
|
2014-11-09 20:30:49 +08:00
|
|
|
d->use_editor = 1;
|
2010-02-14 05:28:36 +08:00
|
|
|
return parse_reuse_arg(opt, arg, unset);
|
|
|
|
}
|
|
|
|
|
2023-05-27 15:57:54 +08:00
|
|
|
static int parse_separator_arg(const struct option *opt, const char *arg,
|
|
|
|
int unset)
|
|
|
|
{
|
|
|
|
if (unset)
|
|
|
|
*(const char **)opt->value = NULL;
|
|
|
|
else
|
|
|
|
*(const char **)opt->value = arg ? arg : "\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 15:51:05 +08:00
|
|
|
static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
|
2010-03-13 01:04:31 +08:00
|
|
|
{
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2010-03-13 01:04:32 +08:00
|
|
|
struct notes_rewrite_cfg *c = NULL;
|
2010-06-15 07:40:05 +08:00
|
|
|
struct notes_tree *t = NULL;
|
2010-03-13 01:04:31 +08:00
|
|
|
int ret = 0;
|
2013-06-12 08:12:59 +08:00
|
|
|
const char *msg = "Notes added by 'git notes copy'";
|
2010-03-13 01:04:31 +08:00
|
|
|
|
2010-03-13 01:04:32 +08:00
|
|
|
if (rewrite_cmd) {
|
|
|
|
c = init_copy_notes_for_rewrite(rewrite_cmd);
|
|
|
|
if (!c)
|
|
|
|
return 0;
|
|
|
|
} else {
|
2015-10-08 10:54:43 +08:00
|
|
|
init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
|
2010-03-13 01:04:32 +08:00
|
|
|
t = &default_notes_tree;
|
|
|
|
}
|
2010-03-13 01:04:31 +08:00
|
|
|
|
2016-01-14 07:31:17 +08:00
|
|
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id from_obj, to_obj;
|
2010-03-13 01:04:31 +08:00
|
|
|
struct strbuf **split;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
split = strbuf_split(&buf, ' ');
|
|
|
|
if (!split[0] || !split[1])
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("malformed input line: '%s'."), buf.buf);
|
2010-03-13 01:04:31 +08:00
|
|
|
strbuf_rtrim(split[0]);
|
|
|
|
strbuf_rtrim(split[1]);
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, split[0]->buf, &from_obj))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), split[0]->buf);
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, split[1]->buf, &to_obj))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), split[1]->buf);
|
2010-03-13 01:04:31 +08:00
|
|
|
|
2010-03-13 01:04:32 +08:00
|
|
|
if (rewrite_cmd)
|
2017-05-31 01:30:42 +08:00
|
|
|
err = copy_note_for_rewrite(c, &from_obj, &to_obj);
|
2010-03-13 01:04:32 +08:00
|
|
|
else
|
2017-05-31 01:30:43 +08:00
|
|
|
err = copy_note(t, &from_obj, &to_obj, force,
|
2010-03-13 01:04:32 +08:00
|
|
|
combine_notes_overwrite);
|
2010-03-13 01:04:31 +08:00
|
|
|
|
|
|
|
if (err) {
|
2016-09-15 22:59:04 +08:00
|
|
|
error(_("failed to copy notes from '%s' to '%s'"),
|
2010-03-13 01:04:31 +08:00
|
|
|
split[0]->buf, split[1]->buf);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_list_free(split);
|
|
|
|
}
|
|
|
|
|
2010-03-13 01:04:32 +08:00
|
|
|
if (!rewrite_cmd) {
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t, msg);
|
2010-03-13 01:04:32 +08:00
|
|
|
free_notes(t);
|
|
|
|
} else {
|
2019-01-12 10:13:23 +08:00
|
|
|
finish_copy_notes_for_rewrite(the_repository, c, msg);
|
2010-03-13 01:04:32 +08:00
|
|
|
}
|
2017-08-31 01:57:30 +08:00
|
|
|
strbuf_release(&buf);
|
2010-03-13 01:04:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
static struct notes_tree *init_notes_check(const char *subcommand,
|
|
|
|
int flags)
|
2010-02-14 05:28:20 +08:00
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2015-10-08 10:54:43 +08:00
|
|
|
const char *ref;
|
|
|
|
init_notes(NULL, NULL, NULL, flags);
|
2010-02-27 16:59:22 +08:00
|
|
|
t = &default_notes_tree;
|
2010-02-14 05:28:24 +08:00
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
|
|
|
|
if (!starts_with(ref, "refs/notes/"))
|
C style: use standard style for "TRANSLATORS" comments
Change all the "TRANSLATORS: [...]" comments in the C code to use the
regular Git coding style, and amend the style guide so that the
example there uses that style.
This custom style was necessary back in 2010 when the gettext support
was initially added, and was subsequently documented in commit
cbcfd4e3ea ("i18n: mention "TRANSLATORS:" marker in
Documentation/CodingGuidelines", 2014-04-18).
GNU xgettext hasn't had the parsing limitation that necessitated this
exception for almost 3 years. Since its 0.19 release on 2014-06-02
it's been able to recognize TRANSLATOR comments in the standard Git
comment syntax[1].
Usually we'd like to keep compatibility with software that's that
young, but in this case literally the only person who needs to be
using a gettext newer than 3 years old is Jiang Xin (the only person
who runs & commits "make pot" results), so I think in this case we can
make an exception.
This xgettext parsing feature was added after a thread on the Git
mailing list[2] which continued on the bug-gettext[3] list, but we
never subsequently changed our style & styleguide, do so.
There are already longstanding changes in git that use the standard
comment style & have their TRANSLATORS comments extracted properly
without getting the literal "*"'s mixed up in the text, as would
happen before xgettext 0.19.
Commit 7ff2683253 ("builtin-am: implement -i/--interactive",
2015-08-04) added one such comment, which in commit df0617bfa7 ("l10n:
git.pot: v2.6.0 round 1 (123 new, 41 removed)", 2015-09-05) got picked
up in the po/git.pot file with the right format, showing that Jiang
already runs a modern xgettext.
The xgettext parser does not handle the sort of non-standard comment
style that I'm amending here in sequencer.c, but that isn't standard
Git comment syntax anyway. With this change to sequencer.c & "make
pot" the comment in the pot file is now correct:
#. TRANSLATORS: %s will be "revert", "cherry-pick" or
-#. * "rebase -i".
+#. "rebase -i".
1. http://git.savannah.gnu.org/cgit/gettext.git/commit/?id=10af7fe6bd
2. <2ce9ec406501d112e032c8208417f8100bed04c6.1397712142.git.worldhello.net@gmail.com>
(https://public-inbox.org/git/2ce9ec406501d112e032c8208417f8100bed04c6.1397712142.git.worldhello.net@gmail.com/)
3. https://lists.gnu.org/archive/html/bug-gettext/2014-04/msg00016.html
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-12 05:20:12 +08:00
|
|
|
/*
|
|
|
|
* TRANSLATORS: the first %s will be replaced by a git
|
|
|
|
* notes command: 'add', 'merge', 'remove', etc.
|
|
|
|
*/
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("refusing to %s notes in %s (outside of refs/notes/)"),
|
2015-10-08 10:54:43 +08:00
|
|
|
subcommand, ref);
|
2010-02-27 16:59:22 +08:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int list(int argc, const char **argv, const char *prefix)
|
2010-02-14 05:28:20 +08:00
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object;
|
2017-05-31 01:30:40 +08:00
|
|
|
const struct object_id *note;
|
2010-02-27 16:59:22 +08:00
|
|
|
int retval = -1;
|
2010-02-14 05:28:20 +08:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (argc)
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_list_usage, 0);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (1 < argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_list_usage, options);
|
2010-03-13 01:04:35 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("list", 0);
|
2010-02-27 16:59:22 +08:00
|
|
|
if (argc) {
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, argv[0], &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
|
2017-05-31 01:30:43 +08:00
|
|
|
note = get_note(t, &object);
|
2010-02-27 16:59:22 +08:00
|
|
|
if (note) {
|
2017-05-31 01:30:40 +08:00
|
|
|
puts(oid_to_hex(note));
|
2010-02-27 16:59:22 +08:00
|
|
|
retval = 0;
|
|
|
|
} else
|
2016-09-15 22:59:04 +08:00
|
|
|
retval = error(_("no note found for object %s."),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2010-02-27 16:59:22 +08:00
|
|
|
} else
|
|
|
|
retval = for_each_note(t, 0, list_each_note, NULL);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
free_notes(t);
|
|
|
|
return retval;
|
|
|
|
}
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2011-03-30 08:02:55 +08:00
|
|
|
static int append_edit(int argc, const char **argv, const char *prefix);
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
static int add(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2014-11-12 08:40:14 +08:00
|
|
|
int force = 0, allow_empty = 0;
|
2010-02-14 05:28:25 +08:00
|
|
|
const char *object_ref;
|
2010-02-27 16:59:22 +08:00
|
|
|
struct notes_tree *t;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object, new_note;
|
2017-05-31 01:30:40 +08:00
|
|
|
const struct object_id *note;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
struct note_data d = { .buf = STRBUF_INIT, .stripspace = UNSPECIFIED };
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
|
2010-02-14 05:28:20 +08:00
|
|
|
struct option options[] = {
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
OPT_CALLBACK_F('m', "message", &d, N_("message"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("note contents as a string"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_msg_arg),
|
|
|
|
OPT_CALLBACK_F('F', "file", &d, N_("file"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("note contents in a file"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_file_arg),
|
|
|
|
OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_reedit_arg),
|
|
|
|
OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("reuse specified note object"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_reuse_arg),
|
2014-11-12 08:40:14 +08:00
|
|
|
OPT_BOOL(0, "allow-empty", &allow_empty,
|
|
|
|
N_("allow storing empty note")),
|
2018-02-09 19:02:08 +08:00
|
|
|
OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE),
|
2023-05-27 15:57:54 +08:00
|
|
|
OPT_CALLBACK_F(0, "separator", &separator,
|
|
|
|
N_("<paragraph-break>"),
|
|
|
|
N_("insert <paragraph-break> between paragraphs"),
|
|
|
|
PARSE_OPT_OPTARG, parse_separator_arg),
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
OPT_BOOL(0, "stripspace", &d.stripspace,
|
|
|
|
N_("remove unnecessary whitespace")),
|
2010-02-14 05:28:20 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_add_usage,
|
2011-03-30 08:02:55 +08:00
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2011-03-30 08:02:55 +08:00
|
|
|
if (2 < argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_add_usage, options);
|
2010-03-13 01:04:35 +08:00
|
|
|
}
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
if (d.msg_nr)
|
|
|
|
concat_messages(&d);
|
|
|
|
d.given = !!d.buf.len;
|
|
|
|
|
2011-03-30 08:02:55 +08:00
|
|
|
object_ref = argc > 1 ? argv[1] : "HEAD";
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, object_ref, &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("add", NOTES_INIT_WRITABLE);
|
2017-05-31 01:30:43 +08:00
|
|
|
note = get_note(t, &object);
|
2010-02-14 05:28:25 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (note) {
|
|
|
|
if (!force) {
|
2014-11-12 08:40:12 +08:00
|
|
|
free_notes(t);
|
|
|
|
if (d.given) {
|
2014-11-09 20:30:50 +08:00
|
|
|
free_note_data(&d);
|
2014-11-12 08:40:12 +08:00
|
|
|
return error(_("Cannot add notes. "
|
|
|
|
"Found existing notes for object %s. "
|
|
|
|
"Use '-f' to overwrite existing notes"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2011-03-30 08:02:55 +08:00
|
|
|
}
|
2014-11-12 08:40:12 +08:00
|
|
|
/*
|
|
|
|
* Redirect to "edit" subcommand.
|
|
|
|
*
|
|
|
|
* We only end up here if none of -m/-F/-c/-C or -f are
|
|
|
|
* given. The original args are therefore still in
|
|
|
|
* argv[0-1].
|
|
|
|
*/
|
|
|
|
argv[0] = "edit";
|
|
|
|
return append_edit(argc, argv, prefix);
|
2010-02-27 16:59:22 +08:00
|
|
|
}
|
2011-02-23 07:42:26 +08:00
|
|
|
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2010-02-14 05:28:34 +08:00
|
|
|
}
|
|
|
|
|
2018-03-12 10:27:48 +08:00
|
|
|
prepare_note_data(&object, &d, note);
|
2014-11-12 08:40:14 +08:00
|
|
|
if (d.buf.len || allow_empty) {
|
2018-01-28 08:13:19 +08:00
|
|
|
write_note_data(&d, &new_note);
|
2017-05-31 01:30:43 +08:00
|
|
|
if (add_note(t, &object, &new_note, combine_notes_overwrite))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("combine_notes_overwrite failed");
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t,
|
|
|
|
"Notes added by 'git notes add'");
|
2014-11-12 08:40:13 +08:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
|
|
|
remove_note(t, object.hash);
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t,
|
|
|
|
"Notes removed by 'git notes add'");
|
2014-11-12 08:40:13 +08:00
|
|
|
}
|
2010-03-13 01:04:31 +08:00
|
|
|
|
2014-11-12 08:40:13 +08:00
|
|
|
free_note_data(&d);
|
2010-02-27 16:59:22 +08:00
|
|
|
free_notes(t);
|
2014-11-12 08:40:12 +08:00
|
|
|
return 0;
|
2010-02-27 16:59:22 +08:00
|
|
|
}
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
static int copy(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int retval = 0, force = 0, from_stdin = 0;
|
2017-05-31 01:30:40 +08:00
|
|
|
const struct object_id *from_note, *note;
|
2010-02-27 16:59:22 +08:00
|
|
|
const char *object_ref;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object, from_obj;
|
2010-02-27 16:59:22 +08:00
|
|
|
struct notes_tree *t;
|
|
|
|
const char *rewrite_cmd = NULL;
|
|
|
|
struct option options[] = {
|
2018-02-09 19:02:08 +08:00
|
|
|
OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")),
|
2012-08-20 20:32:28 +08:00
|
|
|
OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"),
|
|
|
|
N_("load rewriting config for <command> (implies "
|
|
|
|
"--stdin)")),
|
2010-02-27 16:59:22 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_copy_usage,
|
|
|
|
0);
|
2010-02-14 05:28:30 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (from_stdin || rewrite_cmd) {
|
|
|
|
if (argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
2010-02-14 05:28:37 +08:00
|
|
|
} else {
|
2010-02-27 16:59:22 +08:00
|
|
|
return notes_copy_from_stdin(force, rewrite_cmd);
|
2010-02-14 05:28:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 13:18:41 +08:00
|
|
|
if (argc < 1) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too few arguments"));
|
2010-06-28 16:59:07 +08:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
|
|
|
}
|
2010-02-27 16:59:22 +08:00
|
|
|
if (2 < argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, argv[0], &from_obj))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), argv[0]);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
object_ref = 1 < argc ? argv[1] : "HEAD";
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, object_ref, &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("copy", NOTES_INIT_WRITABLE);
|
2017-05-31 01:30:43 +08:00
|
|
|
note = get_note(t, &object);
|
2010-02-14 05:28:20 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (note) {
|
2010-02-14 05:28:37 +08:00
|
|
|
if (!force) {
|
2011-02-23 07:42:26 +08:00
|
|
|
retval = error(_("Cannot copy notes. Found existing "
|
2010-02-27 16:59:22 +08:00
|
|
|
"notes for object %s. Use '-f' to "
|
2011-02-23 07:42:26 +08:00
|
|
|
"overwrite existing notes"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2010-02-27 16:59:22 +08:00
|
|
|
goto out;
|
2010-02-14 05:28:37 +08:00
|
|
|
}
|
2011-02-23 07:42:26 +08:00
|
|
|
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2010-02-14 05:28:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:43 +08:00
|
|
|
from_note = get_note(t, &from_obj);
|
2010-02-27 16:59:22 +08:00
|
|
|
if (!from_note) {
|
2016-09-15 22:59:04 +08:00
|
|
|
retval = error(_("missing notes on source object %s. Cannot "
|
2017-05-31 01:30:42 +08:00
|
|
|
"copy."), oid_to_hex(&from_obj));
|
2010-02-27 16:59:22 +08:00
|
|
|
goto out;
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
|
|
|
|
2017-05-31 01:30:43 +08:00
|
|
|
if (add_note(t, &object, from_note, combine_notes_overwrite))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("combine_notes_overwrite failed");
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t,
|
|
|
|
"Notes added by 'git notes copy'");
|
2010-02-27 16:59:22 +08:00
|
|
|
out:
|
|
|
|
free_notes(t);
|
|
|
|
return retval;
|
|
|
|
}
|
2010-02-14 05:28:32 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
static int append_edit(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2014-11-12 08:40:14 +08:00
|
|
|
int allow_empty = 0;
|
2010-02-27 16:59:22 +08:00
|
|
|
const char *object_ref;
|
|
|
|
struct notes_tree *t;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object, new_note;
|
2017-05-31 01:30:40 +08:00
|
|
|
const struct object_id *note;
|
2017-03-29 03:46:50 +08:00
|
|
|
char *logmsg;
|
2010-02-27 16:59:22 +08:00
|
|
|
const char * const *usage;
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
struct note_data d = { .buf = STRBUF_INIT, .stripspace = UNSPECIFIED };
|
2010-02-27 16:59:22 +08:00
|
|
|
struct option options[] = {
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
OPT_CALLBACK_F('m', "message", &d, N_("message"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("note contents as a string"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_msg_arg),
|
|
|
|
OPT_CALLBACK_F('F', "file", &d, N_("file"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("note contents in a file"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_file_arg),
|
|
|
|
OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_reedit_arg),
|
|
|
|
OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("reuse specified note object"), PARSE_OPT_NONEG,
|
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a
plain ol' struct definition. However, we have the OPT_CALLBACK and
OPT_CALLBACK_F macros which are meant to abstract these plain struct
definitions away. These macros are useful as they semantically signal to
developers that these are just normal callback option with nothing fancy
happening.
Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or
OPT_CALLBACK_F where applicable. The heavy lifting was done using the
following (disgusting) shell script:
#!/bin/sh
do_replacement () {
tr '\n' '\r' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' |
sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' |
tr '\r' '\n'
}
for f in $(git ls-files \*.c)
do
do_replacement <"$f" >"$f.tmp"
mv "$f.tmp" "$f"
done
The result was manually inspected and then reformatted to match the
style of the surrounding code. Finally, using
`git grep OPTION_CALLBACK \*.c`, leftover results which were not handled
by the script were manually transformed.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-28 16:36:28 +08:00
|
|
|
parse_reuse_arg),
|
2014-11-12 08:40:14 +08:00
|
|
|
OPT_BOOL(0, "allow-empty", &allow_empty,
|
|
|
|
N_("allow storing empty note")),
|
2023-05-27 15:57:54 +08:00
|
|
|
OPT_CALLBACK_F(0, "separator", &separator,
|
|
|
|
N_("<paragraph-break>"),
|
|
|
|
N_("insert <paragraph-break> between paragraphs"),
|
|
|
|
PARSE_OPT_OPTARG, parse_separator_arg),
|
notes.c: introduce "--[no-]stripspace" option
This commit introduces a new option "--[no-]stripspace" to git notes
append, git notes edit, and git notes add. This option allows users to
control whether the note message need to stripped out.
For the consideration of backward compatibility, let's look at the
behavior about "stripspace" in "git notes" command:
1. "Edit Message" case: using the default editor to edit the note
message.
In "edit" case, the edited message will always be stripped out, the
implementation which can be found in the "prepare_note_data()". In
addition, the "-c" option supports to reuse an existing blob as a
note message, then open the editor to make a further edition on it,
the edited message will be stripped.
This commit doesn't change the default behavior of "edit" case by
using an enum "notes_stripspace", only when "--no-stripspace" option
is specified, the note message will not be stripped out. If you do
not specify the option or you specify "--stripspace", clearly, the
note message will be stripped out.
2. "Assign Message" case: using the "-m"/"-F"/"-C" option to specify the
note message.
In "assign" case, when specify message by "-m" or "-F", the message
will be stripped out by default, but when specify message by "-C",
the message will be copied verbatim, in other word, the message will
not be stripped out. One more thing need to note is "the order of
the options matter", that is, if you specify "-C" before "-m" or
"-F", the reused message by "-C" will be stripped out together,
because everytime concat "-m" or "-F" message, the concated message
will be stripped together. Oppositely, if you specify "-m" or "-F"
before "-C", the reused message by "-C" will not be stripped out.
This commit doesn't change the default behavior of "assign" case by
extending the "stripspace" field in "struct note_msg", so we can
distinguish the different behavior of "-m"/"-F" and "-C" options
when we need to parse and concat the message.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:53 +08:00
|
|
|
OPT_BOOL(0, "stripspace", &d.stripspace,
|
|
|
|
N_("remove unnecessary whitespace")),
|
2010-02-27 16:59:22 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
int edit = !strcmp(argv[0], "edit");
|
|
|
|
|
|
|
|
usage = edit ? git_notes_edit_usage : git_notes_append_usage;
|
|
|
|
argc = parse_options(argc, argv, prefix, options, usage,
|
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
2010-02-14 05:28:25 +08:00
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
if (2 < argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(usage, options);
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
|
|
|
|
notes.c: introduce '--separator=<paragraph-break>' option
When adding new notes or appending to an existing notes, we will
insert a blank line between the paragraphs, like:
$ git notes add -m foo -m bar
$ git notes show HEAD
foo
bar
The default behavour sometimes is not enough, the user may want
to use a custom delimiter between paragraphs, like when
specifying '-m', '-F', '-C', '-c' options. So this commit
introduce a new '--separator' option for 'git notes add' and
'git notes append', for example when executing:
$ git notes add -m foo -m bar --separator="-"
$ git notes show HEAD
foo
-
bar
a newline is added to the value given to --separator if it
does not end with one already. So when executing:
$ git notes add -m foo -m bar --separator="-"
and
$ export LF="
"
$ git notes add -m foo -m bar --separator="-$LF"
Both the two exections produce the same result.
The reason we use a "strbuf" array to concat but not "string_list", is
that the binary file content may contain '\0' in the middle, this will
cause the corrupt result if using a string to save.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:51 +08:00
|
|
|
if (d.msg_nr)
|
|
|
|
concat_messages(&d);
|
|
|
|
d.given = !!d.buf.len;
|
|
|
|
|
2014-11-09 20:30:49 +08:00
|
|
|
if (d.given && edit)
|
2011-02-23 07:42:26 +08:00
|
|
|
fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated "
|
2010-02-27 16:59:22 +08:00
|
|
|
"for the 'edit' subcommand.\n"
|
2011-02-23 07:42:26 +08:00
|
|
|
"Please use 'git notes add -f -m/-F/-c/-C' instead.\n"));
|
2010-02-27 16:59:22 +08:00
|
|
|
|
|
|
|
object_ref = 1 < argc ? argv[1] : "HEAD";
|
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, object_ref, &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
|
2017-05-31 01:30:43 +08:00
|
|
|
note = get_note(t, &object);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
2018-03-12 10:27:48 +08:00
|
|
|
prepare_note_data(&object, &d, edit && note ? note : NULL);
|
2010-02-14 05:28:37 +08:00
|
|
|
|
2014-11-12 08:40:13 +08:00
|
|
|
if (note && !edit) {
|
|
|
|
/* Append buf to previous note contents */
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
|
2014-11-12 08:40:13 +08:00
|
|
|
|
2024-02-05 22:35:53 +08:00
|
|
|
if (!prev_buf)
|
|
|
|
die(_("unable to read %s"), oid_to_hex(note));
|
|
|
|
if (size)
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
strbuf_add(&buf, prev_buf, size);
|
2024-02-05 22:35:53 +08:00
|
|
|
if (d.buf.len && size)
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
append_separator(&buf);
|
|
|
|
strbuf_insert(&d.buf, 0, buf.buf, buf.len);
|
|
|
|
|
2014-11-12 08:40:13 +08:00
|
|
|
free(prev_buf);
|
notes.c: append separator instead of insert by pos
Rename "insert_separator" to "append_separator" and also remove the
"postion" argument, this serves two purpose:
The first is that when specifying more than one "-m" ( like "-F", etc)
to "git notes add" or "git notes append", the order of them matters,
which means we need to append the each separator and message in turn,
so we don't have to make the caller specify the position, the "append"
operation is enough and clear.
The second is that when we execute the "git notes append" subcommand,
we need to combine the "prev_note" and "current_note" to get the
final result. Before, we inserted a newline character at the beginning
of "current_note". Now, we will append a newline to the end of
"prev_note" instead, this will give the consisitent results.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-27 15:57:52 +08:00
|
|
|
strbuf_release(&buf);
|
2014-11-12 08:40:13 +08:00
|
|
|
}
|
2010-02-14 05:28:37 +08:00
|
|
|
|
2014-11-12 08:40:14 +08:00
|
|
|
if (d.buf.len || allow_empty) {
|
2018-01-28 08:13:19 +08:00
|
|
|
write_note_data(&d, &new_note);
|
2017-05-31 01:30:43 +08:00
|
|
|
if (add_note(t, &object, &new_note, combine_notes_overwrite))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("combine_notes_overwrite failed");
|
2017-03-29 03:46:50 +08:00
|
|
|
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);
|
2014-11-12 08:40:13 +08:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
|
|
|
remove_note(t, object.hash);
|
2017-03-29 03:46:50 +08:00
|
|
|
logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
|
2014-11-12 08:40:13 +08:00
|
|
|
}
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t, logmsg);
|
2014-11-12 08:40:13 +08:00
|
|
|
|
2017-03-29 03:46:50 +08:00
|
|
|
free(logmsg);
|
2014-11-12 08:40:13 +08:00
|
|
|
free_note_data(&d);
|
2010-02-14 05:28:20 +08:00
|
|
|
free_notes(t);
|
2010-02-27 16:59:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
const char *object_ref;
|
|
|
|
struct notes_tree *t;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id object;
|
2017-05-31 01:30:40 +08:00
|
|
|
const struct object_id *note;
|
2010-02-27 16:59:22 +08:00
|
|
|
int retval;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_show_usage,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (1 < argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_show_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ref = argc ? argv[0] : "HEAD";
|
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, object_ref, &object))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("show", 0);
|
2017-05-31 01:30:43 +08:00
|
|
|
note = get_note(t, &object);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
|
|
|
if (!note)
|
2016-09-15 22:59:04 +08:00
|
|
|
retval = error(_("no note found for object %s."),
|
2017-05-31 01:30:42 +08:00
|
|
|
oid_to_hex(&object));
|
2010-02-27 16:59:22 +08:00
|
|
|
else {
|
2017-05-31 01:30:40 +08:00
|
|
|
const char *show_args[3] = {"show", oid_to_hex(note), NULL};
|
2010-02-27 16:59:22 +08:00
|
|
|
retval = execv_git_cmd(show_args);
|
|
|
|
}
|
|
|
|
free_notes(t);
|
2010-02-14 05:28:37 +08:00
|
|
|
return retval;
|
2010-02-14 05:28:20 +08:00
|
|
|
}
|
2010-02-27 16:59:22 +08:00
|
|
|
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
static int merge_abort(struct notes_merge_options *o)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove .git/NOTES_MERGE_PARTIAL and .git/NOTES_MERGE_REF, and call
|
|
|
|
* notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
|
|
|
|
*/
|
|
|
|
|
2017-02-21 09:10:32 +08:00
|
|
|
if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
|
2016-09-15 22:59:04 +08:00
|
|
|
ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
|
2017-11-05 16:42:06 +08:00
|
|
|
if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NO_DEREF))
|
2016-09-15 22:59:04 +08:00
|
|
|
ret += error(_("failed to delete ref NOTES_MERGE_REF"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
if (notes_merge_abort(o))
|
2016-09-15 22:59:04 +08:00
|
|
|
ret += error(_("failed to remove 'git notes merge' worktree"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int merge_commit(struct notes_merge_options *o)
|
|
|
|
{
|
|
|
|
struct strbuf msg = STRBUF_INIT;
|
2017-02-22 07:47:29 +08:00
|
|
|
struct object_id oid, parent_oid;
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
struct notes_tree *t;
|
|
|
|
struct commit *partial;
|
|
|
|
struct pretty_print_context pretty_ctx;
|
2011-12-13 22:17:48 +08:00
|
|
|
void *local_ref_to_free;
|
2011-11-13 18:22:15 +08:00
|
|
|
int ret;
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read partial merge result from .git/NOTES_MERGE_PARTIAL,
|
|
|
|
* and target notes ref from .git/NOTES_MERGE_REF.
|
|
|
|
*/
|
|
|
|
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, "NOTES_MERGE_PARTIAL", &oid))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
|
2018-06-29 09:21:58 +08:00
|
|
|
else if (!(partial = lookup_commit_reference(the_repository, &oid)))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
|
2023-03-28 21:58:48 +08:00
|
|
|
else if (repo_parse_commit(the_repository, partial))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
|
2010-11-10 05:49:54 +08:00
|
|
|
if (partial->parents)
|
2017-02-22 07:47:29 +08:00
|
|
|
oidcpy(&parent_oid, &partial->parents->item->object.oid);
|
2010-11-10 05:49:54 +08:00
|
|
|
else
|
2017-02-22 07:47:29 +08:00
|
|
|
oidclr(&parent_oid);
|
2010-11-10 05:49:54 +08:00
|
|
|
|
2021-03-14 00:17:22 +08:00
|
|
|
CALLOC_ARRAY(t, 1);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
|
|
|
|
|
2011-12-13 22:17:48 +08:00
|
|
|
o->local_ref = local_ref_to_free =
|
refs: convert resolve_refdup and refs_resolve_refdup to struct object_id
All of the callers already pass the hash member of struct object_id, so
update them to pass a pointer to the struct directly,
This transformation was done with an update to declaration and
definition and the following semantic patch:
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3.hash, E4)
+ resolve_refdup(E1, E2, &E3, E4)
@@
expression E1, E2, E3, E4;
@@
- resolve_refdup(E1, E2, E3->hash, E4)
+ resolve_refdup(E1, E2, E3, E4)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-16 06:06:55 +08:00
|
|
|
resolve_refdup("NOTES_MERGE_REF", 0, &oid, NULL);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
if (!o->local_ref)
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to resolve NOTES_MERGE_REF"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
|
2017-05-31 01:30:58 +08:00
|
|
|
if (notes_merge_commit(o, t, partial, &oid))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to finalize notes merge"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
|
|
|
|
/* Reuse existing commit message in reflog message */
|
|
|
|
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
|
2023-03-28 21:58:51 +08:00
|
|
|
repo_format_commit_message(the_repository, partial, "%s", &msg,
|
|
|
|
&pretty_ctx);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
strbuf_trim(&msg);
|
2020-02-09 21:44:23 +08:00
|
|
|
strbuf_insertstr(&msg, 0, "notes: ");
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref(msg.buf, o->local_ref, &oid,
|
|
|
|
is_null_oid(&parent_oid) ? NULL : &parent_oid,
|
2014-04-07 21:47:56 +08:00
|
|
|
0, UPDATE_REFS_DIE_ON_ERR);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
|
|
|
|
free_notes(t);
|
|
|
|
strbuf_release(&msg);
|
2011-11-13 18:22:15 +08:00
|
|
|
ret = merge_abort(o);
|
2011-12-13 22:17:48 +08:00
|
|
|
free(local_ref_to_free);
|
2011-11-13 18:22:15 +08:00
|
|
|
return ret;
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
}
|
|
|
|
|
2015-08-18 05:33:33 +08:00
|
|
|
static int git_config_get_notes_strategy(const char *key,
|
|
|
|
enum notes_merge_strategy *strategy)
|
|
|
|
{
|
2016-04-01 08:35:43 +08:00
|
|
|
char *value;
|
2015-08-18 05:33:33 +08:00
|
|
|
|
2016-04-01 08:35:43 +08:00
|
|
|
if (git_config_get_string(key, &value))
|
2015-08-18 05:33:33 +08:00
|
|
|
return 1;
|
|
|
|
if (parse_notes_merge_strategy(value, strategy))
|
2016-06-18 04:21:14 +08:00
|
|
|
git_die_config(key, _("unknown notes merge strategy %s"), value);
|
2015-08-18 05:33:33 +08:00
|
|
|
|
2016-04-01 08:35:43 +08:00
|
|
|
free(value);
|
2015-08-18 05:33:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-10 05:49:46 +08:00
|
|
|
static int merge(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id result_oid;
|
git notes merge: Handle real, non-conflicting notes merges
This continuation of the 'git notes merge' implementation teaches notes-merge
to properly do real merges between notes trees: Two diffs are performed, one
from $base to $remote, and another from $base to $local. The paths in each
diff are normalized to SHA1 object names. The two diffs are then consolidated
into a single list of change pairs to be evaluated. Each change pair consist
of:
- The annotated object's SHA1
- The $base SHA1 (i.e. the common ancestor notes for this object)
- The $local SHA1 (i.e. the current notes for this object)
- The $remote SHA1 (i.e. the to-be-merged notes for this object)
From the pair ($base -> $local, $base -> $remote), we can determine the merge
result using regular 3-way rules. If conflicts are encountered in this
process, we fail loudly and exit (conflict handling to be added in a future
patch), If we can complete the merge without conflicts, the resulting
notes tree is committed, and the current notes ref updated.
The patch includes added testcases verifying that we can successfully do real
conflict-less merges.
This patch has been improved by the following contributions:
- Jonathan Nieder: Future-proof by always checking add_note() return value
- Stephen Boyd: Use test_commit
- Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
- Junio C Hamano: fixup minor style issues
Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
Thanks-to: Stephen Boyd <bebarino@gmail.com>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 07:54:11 +08:00
|
|
|
struct notes_tree *t;
|
2010-11-10 05:49:46 +08:00
|
|
|
struct notes_merge_options o;
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
int do_merge = 0, do_commit = 0, do_abort = 0;
|
2010-11-10 05:49:46 +08:00
|
|
|
int verbosity = 0, result;
|
2010-11-15 07:55:12 +08:00
|
|
|
const char *strategy = NULL;
|
2010-11-10 05:49:46 +08:00
|
|
|
struct option options[] = {
|
2012-08-20 20:32:28 +08:00
|
|
|
OPT_GROUP(N_("General options")),
|
2010-11-10 05:49:46 +08:00
|
|
|
OPT__VERBOSITY(&verbosity),
|
2012-08-20 20:32:28 +08:00
|
|
|
OPT_GROUP(N_("Merge options")),
|
|
|
|
OPT_STRING('s', "strategy", &strategy, N_("strategy"),
|
|
|
|
N_("resolve notes conflicts using the given strategy "
|
|
|
|
"(manual/ours/theirs/union/cat_sort_uniq)")),
|
|
|
|
OPT_GROUP(N_("Committing unmerged notes")),
|
2018-05-20 23:42:58 +08:00
|
|
|
OPT_SET_INT_F(0, "commit", &do_commit,
|
|
|
|
N_("finalize notes merge by committing unmerged notes"),
|
|
|
|
1, PARSE_OPT_NONEG),
|
2012-08-20 20:32:28 +08:00
|
|
|
OPT_GROUP(N_("Aborting notes merge resolution")),
|
2018-05-20 23:42:58 +08:00
|
|
|
OPT_SET_INT_F(0, "abort", &do_abort,
|
|
|
|
N_("abort notes merge"),
|
|
|
|
1, PARSE_OPT_NONEG),
|
2010-11-10 05:49:46 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_merge_usage, 0);
|
|
|
|
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
if (strategy || do_commit + do_abort == 0)
|
|
|
|
do_merge = 1;
|
|
|
|
if (do_merge + do_commit + do_abort != 1) {
|
2016-06-18 04:21:14 +08:00
|
|
|
error(_("cannot mix --commit, --abort or -s/--strategy"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_merge && argc != 1) {
|
2016-09-15 22:59:04 +08:00
|
|
|
error(_("must specify a notes ref to merge"));
|
2010-11-10 05:49:46 +08:00
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
} else if (!do_merge && argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
2010-11-10 05:49:46 +08:00
|
|
|
}
|
|
|
|
|
2018-11-10 13:48:53 +08:00
|
|
|
init_notes_merge_options(the_repository, &o);
|
2010-11-10 05:49:46 +08:00
|
|
|
o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
|
|
|
|
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
if (do_abort)
|
|
|
|
return merge_abort(&o);
|
|
|
|
if (do_commit)
|
|
|
|
return merge_commit(&o);
|
|
|
|
|
2010-11-10 05:49:46 +08:00
|
|
|
o.local_ref = default_notes_ref();
|
|
|
|
strbuf_addstr(&remote_ref, argv[0]);
|
2015-12-30 06:40:28 +08:00
|
|
|
expand_loose_notes_ref(&remote_ref);
|
2010-11-10 05:49:46 +08:00
|
|
|
o.remote_ref = remote_ref.buf;
|
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("merge", NOTES_INIT_WRITABLE);
|
2015-08-18 05:33:33 +08:00
|
|
|
|
2010-11-15 07:55:12 +08:00
|
|
|
if (strategy) {
|
2015-08-18 05:33:31 +08:00
|
|
|
if (parse_notes_merge_strategy(strategy, &o.strategy)) {
|
2016-09-15 22:59:04 +08:00
|
|
|
error(_("unknown -s/--strategy: %s"), strategy);
|
2010-11-15 07:55:12 +08:00
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
|
|
|
}
|
2015-08-18 05:33:33 +08:00
|
|
|
} else {
|
2015-08-18 05:33:34 +08:00
|
|
|
struct strbuf merge_key = STRBUF_INIT;
|
|
|
|
const char *short_ref = NULL;
|
2010-11-15 07:55:12 +08:00
|
|
|
|
2015-08-18 05:33:34 +08:00
|
|
|
if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref))
|
2018-05-02 17:38:39 +08:00
|
|
|
BUG("local ref %s is outside of refs/notes/",
|
2015-08-18 05:33:34 +08:00
|
|
|
o.local_ref);
|
|
|
|
|
|
|
|
strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref);
|
|
|
|
|
|
|
|
if (git_config_get_notes_strategy(merge_key.buf, &o.strategy))
|
|
|
|
git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy);
|
|
|
|
|
|
|
|
strbuf_release(&merge_key);
|
2010-11-15 07:55:12 +08:00
|
|
|
}
|
2010-11-10 05:49:46 +08:00
|
|
|
|
|
|
|
strbuf_addf(&msg, "notes: Merged notes from %s into %s",
|
|
|
|
remote_ref.buf, default_notes_ref());
|
2010-11-10 05:49:53 +08:00
|
|
|
strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
|
git notes merge: Handle real, non-conflicting notes merges
This continuation of the 'git notes merge' implementation teaches notes-merge
to properly do real merges between notes trees: Two diffs are performed, one
from $base to $remote, and another from $base to $local. The paths in each
diff are normalized to SHA1 object names. The two diffs are then consolidated
into a single list of change pairs to be evaluated. Each change pair consist
of:
- The annotated object's SHA1
- The $base SHA1 (i.e. the common ancestor notes for this object)
- The $local SHA1 (i.e. the current notes for this object)
- The $remote SHA1 (i.e. the to-be-merged notes for this object)
From the pair ($base -> $local, $base -> $remote), we can determine the merge
result using regular 3-way rules. If conflicts are encountered in this
process, we fail loudly and exit (conflict handling to be added in a future
patch), If we can complete the merge without conflicts, the resulting
notes tree is committed, and the current notes ref updated.
The patch includes added testcases verifying that we can successfully do real
conflict-less merges.
This patch has been improved by the following contributions:
- Jonathan Nieder: Future-proof by always checking add_note() return value
- Stephen Boyd: Use test_commit
- Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
- Junio C Hamano: fixup minor style issues
Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
Thanks-to: Stephen Boyd <bebarino@gmail.com>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 07:54:11 +08:00
|
|
|
|
2017-05-31 01:30:58 +08:00
|
|
|
result = notes_merge(&o, t, &result_oid);
|
git notes merge: Handle real, non-conflicting notes merges
This continuation of the 'git notes merge' implementation teaches notes-merge
to properly do real merges between notes trees: Two diffs are performed, one
from $base to $remote, and another from $base to $local. The paths in each
diff are normalized to SHA1 object names. The two diffs are then consolidated
into a single list of change pairs to be evaluated. Each change pair consist
of:
- The annotated object's SHA1
- The $base SHA1 (i.e. the common ancestor notes for this object)
- The $local SHA1 (i.e. the current notes for this object)
- The $remote SHA1 (i.e. the to-be-merged notes for this object)
From the pair ($base -> $local, $base -> $remote), we can determine the merge
result using regular 3-way rules. If conflicts are encountered in this
process, we fail loudly and exit (conflict handling to be added in a future
patch), If we can complete the merge without conflicts, the resulting
notes tree is committed, and the current notes ref updated.
The patch includes added testcases verifying that we can successfully do real
conflict-less merges.
This patch has been improved by the following contributions:
- Jonathan Nieder: Future-proof by always checking add_note() return value
- Stephen Boyd: Use test_commit
- Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
- Junio C Hamano: fixup minor style issues
Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
Thanks-to: Stephen Boyd <bebarino@gmail.com>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 07:54:11 +08:00
|
|
|
|
2017-05-31 01:30:58 +08:00
|
|
|
if (result >= 0) /* Merge resulted (trivially) in result_oid */
|
2010-11-10 05:49:46 +08:00
|
|
|
/* Update default notes ref with new commit */
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref(msg.buf, default_notes_ref(), &result_oid, NULL, 0,
|
|
|
|
UPDATE_REFS_DIE_ON_ERR);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
else { /* Merge has unresolved conflicts */
|
2021-12-02 06:15:43 +08:00
|
|
|
struct worktree **worktrees;
|
2016-04-22 21:01:27 +08:00
|
|
|
const struct worktree *wt;
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
|
2017-10-16 06:06:51 +08:00
|
|
|
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL,
|
2014-04-07 21:47:56 +08:00
|
|
|
0, UPDATE_REFS_DIE_ON_ERR);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
|
2021-12-02 06:15:43 +08:00
|
|
|
worktrees = get_worktrees();
|
|
|
|
wt = find_shared_symref(worktrees, "NOTES_MERGE_REF",
|
|
|
|
default_notes_ref());
|
2016-04-22 21:01:27 +08:00
|
|
|
if (wt)
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("a notes merge into %s is already in-progress at %s"),
|
2016-04-22 21:01:27 +08:00
|
|
|
default_notes_ref(), wt->path);
|
2021-12-02 06:15:43 +08:00
|
|
|
free_worktrees(worktrees);
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
|
2016-09-15 22:59:04 +08:00
|
|
|
die(_("failed to store link to current notes ref (%s)"),
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
default_notes_ref());
|
2017-11-15 00:17:52 +08:00
|
|
|
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
|
|
|
|
"and commit the result with 'git notes merge --commit', "
|
|
|
|
"or abort the merge with 'git notes merge --abort'.\n"),
|
|
|
|
git_path(NOTES_MERGE_WORKTREE));
|
git notes merge: Manual conflict resolution, part 2/2
When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been
resolved, we need to record a new notes commit on the appropriate notes
ref with the resolved notes.
This patch implements 'git notes merge --commit' which the user should
run after resolving conflicts in the notes merge worktree. This command
finalizes the notes merge by recombining the partial notes tree from
part 1 with the now-resolved conflicts in the notes merge worktree in a
merge commit, and updating the appropriate ref to this merge commit.
In order to correctly finalize the merge, we need to keep track of three
things:
- The partial merge result from part 1, containing the auto-merged notes.
This is now stored into a ref called .git/NOTES_MERGE_PARTIAL.
- The unmerged notes. These are already stored in
.git/NOTES_MERGE_WORKTREE, thanks to part 1.
- The notes ref to be updated by the finalized merge result. This is now
stored in a symref called .git/NOTES_MERGE_REF.
In addition to "git notes merge --commit", which uses the above details
to create the finalized notes merge commit, this patch also implements
"git notes merge --reset", which aborts the ongoing notes merge by simply
removing the files/directory described above.
FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove
the information described above (.git/NOTES_MERGE_*) after the notes merge
have been successfully finalized.
The patch also contains documentation and testcases for the two new options.
This patch has been improved by the following contributions:
- Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description
- Sverre Rabbelier: Rename --reset to --abort
Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Thanks-to: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10 05:49:52 +08:00
|
|
|
}
|
2010-11-10 05:49:46 +08:00
|
|
|
|
git notes merge: Handle real, non-conflicting notes merges
This continuation of the 'git notes merge' implementation teaches notes-merge
to properly do real merges between notes trees: Two diffs are performed, one
from $base to $remote, and another from $base to $local. The paths in each
diff are normalized to SHA1 object names. The two diffs are then consolidated
into a single list of change pairs to be evaluated. Each change pair consist
of:
- The annotated object's SHA1
- The $base SHA1 (i.e. the common ancestor notes for this object)
- The $local SHA1 (i.e. the current notes for this object)
- The $remote SHA1 (i.e. the to-be-merged notes for this object)
From the pair ($base -> $local, $base -> $remote), we can determine the merge
result using regular 3-way rules. If conflicts are encountered in this
process, we fail loudly and exit (conflict handling to be added in a future
patch), If we can complete the merge without conflicts, the resulting
notes tree is committed, and the current notes ref updated.
The patch includes added testcases verifying that we can successfully do real
conflict-less merges.
This patch has been improved by the following contributions:
- Jonathan Nieder: Future-proof by always checking add_note() return value
- Stephen Boyd: Use test_commit
- Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...)
- Junio C Hamano: fixup minor style issues
Thanks-to: Jonathan Nieder <jrnieder@gmail.com>
Thanks-to: Stephen Boyd <bebarino@gmail.com>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 07:54:11 +08:00
|
|
|
free_notes(t);
|
2010-11-10 05:49:46 +08:00
|
|
|
strbuf_release(&remote_ref);
|
|
|
|
strbuf_release(&msg);
|
2010-11-10 05:49:51 +08:00
|
|
|
return result < 0; /* return non-zero on conflicts */
|
2010-11-10 05:49:46 +08:00
|
|
|
}
|
|
|
|
|
2011-05-19 07:44:30 +08:00
|
|
|
#define IGNORE_MISSING 1
|
2011-05-19 07:02:58 +08:00
|
|
|
|
|
|
|
static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
|
2011-05-19 06:44:37 +08:00
|
|
|
{
|
|
|
|
int status;
|
2017-05-31 01:30:42 +08:00
|
|
|
struct object_id oid;
|
2023-03-28 21:58:46 +08:00
|
|
|
if (repo_get_oid(the_repository, name, &oid))
|
2011-05-19 06:44:37 +08:00
|
|
|
return error(_("Failed to resolve '%s' as a valid ref."), name);
|
2017-05-31 01:30:42 +08:00
|
|
|
status = remove_note(t, oid.hash);
|
2011-05-19 06:44:37 +08:00
|
|
|
if (status)
|
|
|
|
fprintf(stderr, _("Object %s has no note\n"), name);
|
|
|
|
else
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"), name);
|
2011-05-19 07:44:30 +08:00
|
|
|
return (flag & IGNORE_MISSING) ? 0 : status;
|
2011-05-19 06:44:37 +08:00
|
|
|
}
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
static int remove_cmd(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2011-05-19 07:02:58 +08:00
|
|
|
unsigned flag = 0;
|
2011-05-19 07:44:30 +08:00
|
|
|
int from_stdin = 0;
|
2010-02-27 16:59:22 +08:00
|
|
|
struct option options[] = {
|
2011-05-19 07:02:58 +08:00
|
|
|
OPT_BIT(0, "ignore-missing", &flag,
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("attempt to remove non-existent note is not an error"),
|
2011-05-19 07:44:30 +08:00
|
|
|
IGNORE_MISSING),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "stdin", &from_stdin,
|
2012-08-20 20:32:28 +08:00
|
|
|
N_("read object names from the standard input")),
|
2010-02-27 16:59:22 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
struct notes_tree *t;
|
2011-05-19 06:44:37 +08:00
|
|
|
int retval = 0;
|
2010-02-27 16:59:22 +08:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_remove_usage, 0);
|
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("remove", NOTES_INIT_WRITABLE);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
2011-05-19 07:44:30 +08:00
|
|
|
if (!argc && !from_stdin) {
|
2011-05-19 07:02:58 +08:00
|
|
|
retval = remove_one_note(t, "HEAD", flag);
|
2011-05-19 06:44:37 +08:00
|
|
|
} else {
|
|
|
|
while (*argv) {
|
2011-05-19 07:02:58 +08:00
|
|
|
retval |= remove_one_note(t, *argv, flag);
|
2011-05-19 06:44:37 +08:00
|
|
|
argv++;
|
|
|
|
}
|
2010-08-31 23:56:50 +08:00
|
|
|
}
|
2011-05-19 07:44:30 +08:00
|
|
|
if (from_stdin) {
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
|
|
|
|
strbuf_rtrim(&sb);
|
|
|
|
retval |= remove_one_note(t, sb.buf, flag);
|
|
|
|
}
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
2011-05-19 06:44:37 +08:00
|
|
|
if (!retval)
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t,
|
|
|
|
"Notes removed by 'git notes remove'");
|
2010-02-27 16:59:22 +08:00
|
|
|
free_notes(t);
|
2010-08-31 23:56:50 +08:00
|
|
|
return retval;
|
2010-02-27 16:59:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int prune(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2010-05-15 05:42:07 +08:00
|
|
|
int show_only = 0, verbose = 0;
|
2010-02-27 16:59:22 +08:00
|
|
|
struct option options[] = {
|
2016-06-18 04:21:15 +08:00
|
|
|
OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
|
|
|
|
OPT__VERBOSE(&verbose, N_("report pruned notes")),
|
2010-02-27 16:59:22 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_prune_usage,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-02-27 16:59:22 +08:00
|
|
|
usage_with_options(git_notes_prune_usage, options);
|
|
|
|
}
|
|
|
|
|
2015-10-08 10:54:43 +08:00
|
|
|
t = init_notes_check("prune", NOTES_INIT_WRITABLE);
|
2010-02-27 16:59:22 +08:00
|
|
|
|
2010-05-15 05:42:07 +08:00
|
|
|
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
|
|
|
|
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
|
|
|
|
if (!show_only)
|
2019-01-12 10:13:23 +08:00
|
|
|
commit_notes(the_repository, t,
|
|
|
|
"Notes removed by 'git notes prune'");
|
2010-02-27 16:59:22 +08:00
|
|
|
free_notes(t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-10 05:49:57 +08:00
|
|
|
static int get_ref(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct option options[] = { OPT_END() };
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_get_ref_usage, 0);
|
|
|
|
|
|
|
|
if (argc) {
|
2021-02-24 05:11:32 +08:00
|
|
|
error(_("too many arguments"));
|
2010-11-10 05:49:57 +08:00
|
|
|
usage_with_options(git_notes_get_ref_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
puts(default_notes_ref());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-27 16:59:22 +08:00
|
|
|
int cmd_notes(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
const char *override_notes_ref = NULL;
|
2022-09-06 02:50:06 +08:00
|
|
|
parse_opt_subcommand_fn *fn = NULL;
|
2010-02-27 16:59:22 +08:00
|
|
|
struct option options[] = {
|
2014-03-24 06:58:12 +08:00
|
|
|
OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("use notes from <notes-ref>")),
|
2022-08-20 00:04:06 +08:00
|
|
|
OPT_SUBCOMMAND("list", &fn, list),
|
|
|
|
OPT_SUBCOMMAND("add", &fn, add),
|
|
|
|
OPT_SUBCOMMAND("copy", &fn, copy),
|
|
|
|
OPT_SUBCOMMAND("append", &fn, append_edit),
|
|
|
|
OPT_SUBCOMMAND("edit", &fn, append_edit),
|
|
|
|
OPT_SUBCOMMAND("show", &fn, show),
|
|
|
|
OPT_SUBCOMMAND("merge", &fn, merge),
|
|
|
|
OPT_SUBCOMMAND("remove", &fn, remove_cmd),
|
|
|
|
OPT_SUBCOMMAND("prune", &fn, prune),
|
|
|
|
OPT_SUBCOMMAND("get-ref", &fn, get_ref),
|
2010-02-27 16:59:22 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_usage,
|
2022-08-20 00:04:06 +08:00
|
|
|
PARSE_OPT_SUBCOMMAND_OPTIONAL);
|
2022-09-06 02:50:06 +08:00
|
|
|
if (!fn) {
|
|
|
|
if (argc) {
|
2022-09-06 02:50:07 +08:00
|
|
|
error(_("unknown subcommand: `%s'"), argv[0]);
|
2022-09-06 02:50:06 +08:00
|
|
|
usage_with_options(git_notes_usage, options);
|
|
|
|
}
|
|
|
|
fn = list;
|
2022-08-20 00:04:06 +08:00
|
|
|
}
|
2010-02-27 16:59:22 +08:00
|
|
|
|
|
|
|
if (override_notes_ref) {
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
strbuf_addstr(&sb, override_notes_ref);
|
2010-11-10 05:49:45 +08:00
|
|
|
expand_notes_ref(&sb);
|
2010-02-27 16:59:22 +08:00
|
|
|
setenv("GIT_NOTES_REF", sb.buf, 1);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
2022-08-20 00:04:06 +08:00
|
|
|
return !!fn(argc, argv, prefix);
|
2010-02-27 16:59:22 +08:00
|
|
|
}
|