2010-02-13 21:28:20 +00:00
|
|
|
/*
|
|
|
|
* Builtin "git notes"
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Johan Herland <johan@herland.net>
|
|
|
|
*
|
|
|
|
* Based on git-notes.sh by Johannes Schindelin,
|
2013-06-18 17:44:58 +00:00
|
|
|
* and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
|
2010-02-13 21:28:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cache.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "notes.h"
|
|
|
|
#include "blob.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "refs.h"
|
|
|
|
#include "exec_cmd.h"
|
|
|
|
#include "run-command.h"
|
|
|
|
#include "parse-options.h"
|
2010-03-12 17:04:32 +00:00
|
|
|
#include "string-list.h"
|
2010-11-09 21:49:46 +00:00
|
|
|
#include "notes-merge.h"
|
2013-06-12 00:13:00 +00:00
|
|
|
#include "notes-utils.h"
|
2015-10-02 11:55:31 +00:00
|
|
|
#include "worktree.h"
|
2012-09-15 20:56:07 +00:00
|
|
|
|
2010-02-13 21:28:20 +00:00
|
|
|
static const char * const git_notes_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git notes [--ref <notes-ref>] [list [<object>]]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"),
|
|
|
|
N_("git notes [--ref <notes-ref>] append [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
|
|
|
|
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>"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes merge --commit [-v | -q]"),
|
|
|
|
N_("git notes merge --abort [-v | -q]"),
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git notes [--ref <notes-ref>] remove [<object>...]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] prune [-n | -v]"),
|
|
|
|
N_("git notes [--ref <notes-ref>] get-ref"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_list_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes [list [<object>]]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_add_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes add [<options>] [<object>]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_copy_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes copy [<options>] <from-object> <to-object>"),
|
|
|
|
N_("git notes copy --stdin [<from-object> <to-object>]..."),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_append_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes append [<options>] [<object>]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_edit_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes edit [<object>]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_show_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes show [<object>]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-11-09 21:49:46 +00:00
|
|
|
static const char * const git_notes_merge_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git notes merge [<options>] <notes-ref>"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes merge --commit [<options>]"),
|
|
|
|
N_("git notes merge --abort [<options>]"),
|
2010-11-09 21:49:46 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
static const char * const git_notes_remove_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes remove [<object>]"),
|
2010-02-27 08:59:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const git_notes_prune_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes prune [<options>]"),
|
2010-02-13 21:28:20 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-11-09 21:49:57 +00:00
|
|
|
static const char * const git_notes_get_ref_usage[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("git notes get-ref"),
|
2010-11-09 21:49:57 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-02-13 21:28:20 +00:00
|
|
|
static const char note_template[] =
|
2013-01-16 19:18:48 +00:00
|
|
|
"\nWrite/edit the notes for the following object:\n";
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
struct note_data {
|
2010-02-13 21:28:35 +00:00
|
|
|
int given;
|
2010-02-13 21:28:36 +00:00
|
|
|
int use_editor;
|
2014-11-09 12:30:50 +00:00
|
|
|
char *edit_path;
|
2010-02-13 21:28:35 +00:00
|
|
|
struct strbuf buf;
|
|
|
|
};
|
|
|
|
|
2014-11-09 12:30:50 +00: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);
|
|
|
|
}
|
|
|
|
|
2010-02-13 21:28:30 +00:00
|
|
|
static int list_each_note(const unsigned char *object_sha1,
|
|
|
|
const unsigned char *note_sha1, char *note_path,
|
|
|
|
void *cb_data)
|
|
|
|
{
|
|
|
|
printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
static void copy_obj_to_fd(int fd, const unsigned char *sha1)
|
2010-02-13 21:28:20 +00:00
|
|
|
{
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
|
|
|
char *buf = read_sha1_file(sha1, &type, &size);
|
|
|
|
if (buf) {
|
|
|
|
if (size)
|
|
|
|
write_or_die(fd, buf, size);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_commented_object(int fd, const unsigned char *object)
|
|
|
|
{
|
|
|
|
const char *show_args[5] =
|
|
|
|
{"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
|
2014-08-19 19:09:35 +00:00
|
|
|
struct child_process show = CHILD_PROCESS_INIT;
|
2010-02-13 21:28:20 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2013-01-16 19:18:48 +00:00
|
|
|
struct strbuf cbuf = STRBUF_INIT;
|
2010-02-13 21:28:20 +00:00
|
|
|
|
|
|
|
/* Invoke "git show --stat --no-notes $object" */
|
|
|
|
show.argv = show_args;
|
|
|
|
show.no_stdin = 1;
|
|
|
|
show.out = -1;
|
|
|
|
show.err = 0;
|
|
|
|
show.git_cmd = 1;
|
|
|
|
if (start_command(&show))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("unable to start 'show' for object '%s'"),
|
2010-02-13 21:28:20 +00:00
|
|
|
sha1_to_hex(object));
|
|
|
|
|
2013-01-16 19:18:48 +00:00
|
|
|
if (strbuf_read(&buf, show.out, 0) < 0)
|
|
|
|
die_errno(_("could not read 'show' output"));
|
|
|
|
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len);
|
|
|
|
write_or_die(fd, cbuf.buf, cbuf.len);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2013-01-16 19:18:48 +00:00
|
|
|
strbuf_release(&cbuf);
|
2010-02-13 21:28:20 +00:00
|
|
|
strbuf_release(&buf);
|
2013-01-16 19:18:48 +00:00
|
|
|
|
2010-02-13 21:28:20 +00:00
|
|
|
if (finish_command(&show))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("failed to finish 'show' for object '%s'"),
|
2010-02-13 21:28:20 +00:00
|
|
|
sha1_to_hex(object));
|
|
|
|
}
|
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
static void prepare_note_data(const unsigned char *object, struct note_data *d,
|
|
|
|
const unsigned char *old_note)
|
2010-02-13 21:28:20 +00:00
|
|
|
{
|
2014-11-09 12:30:49 +00:00
|
|
|
if (d->use_editor || !d->given) {
|
2010-02-13 21:28:20 +00:00
|
|
|
int fd;
|
2013-01-16 19:18:48 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2010-02-13 21:28:20 +00:00
|
|
|
|
|
|
|
/* write the template message before editing: */
|
2014-11-09 12:30:50 +00:00
|
|
|
d->edit_path = git_pathdup("NOTES_EDITMSG");
|
|
|
|
fd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
|
2010-02-13 21:28:20 +00:00
|
|
|
if (fd < 0)
|
2014-11-09 12:30:50 +00:00
|
|
|
die_errno(_("could not create file '%s'"), d->edit_path);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
if (d->given)
|
|
|
|
write_or_die(fd, d->buf.buf, d->buf.len);
|
2014-11-12 00:40:13 +00:00
|
|
|
else if (old_note)
|
|
|
|
copy_obj_to_fd(fd, old_note);
|
2013-01-16 19:18:48 +00:00
|
|
|
|
|
|
|
strbuf_addch(&buf, '\n');
|
|
|
|
strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
|
|
|
|
strbuf_addch(&buf, '\n');
|
|
|
|
write_or_die(fd, buf.buf, buf.len);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
|
|
|
write_commented_object(fd, object);
|
|
|
|
|
|
|
|
close(fd);
|
2013-01-16 19:18:48 +00:00
|
|
|
strbuf_release(&buf);
|
2014-11-09 12:30:49 +00:00
|
|
|
strbuf_reset(&d->buf);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2014-11-09 12:30:50 +00:00
|
|
|
if (launch_editor(d->edit_path, &d->buf, NULL)) {
|
2014-11-09 12:30:49 +00:00
|
|
|
die(_("Please supply the note contents using either -m or -F option"));
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&d->buf, 1);
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
2014-11-12 00:40:13 +00:00
|
|
|
}
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
static void write_note_data(struct note_data *d, unsigned char *sha1)
|
|
|
|
{
|
|
|
|
if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, sha1)) {
|
|
|
|
error(_("unable to write note object"));
|
|
|
|
if (d->edit_path)
|
|
|
|
error(_("The note contents have been left in %s"),
|
|
|
|
d->edit_path);
|
|
|
|
exit(128);
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 12:30:49 +00:00
|
|
|
struct note_data *d = opt->value;
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
strbuf_grow(&d->buf, strlen(arg) + 2);
|
|
|
|
if (d->buf.len)
|
|
|
|
strbuf_addch(&d->buf, '\n');
|
|
|
|
strbuf_addstr(&d->buf, arg);
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&d->buf, 0);
|
2010-02-13 21:28:35 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
d->given = 1;
|
2010-02-13 21:28:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_file_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 12:30:49 +00:00
|
|
|
struct note_data *d = opt->value;
|
2010-02-13 21:28:35 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
if (d->buf.len)
|
|
|
|
strbuf_addch(&d->buf, '\n');
|
2010-02-13 21:28:35 +00:00
|
|
|
if (!strcmp(arg, "-")) {
|
2014-11-09 12:30:49 +00:00
|
|
|
if (strbuf_read(&d->buf, 0, 1024) < 0)
|
2011-02-22 23:42:26 +00:00
|
|
|
die_errno(_("cannot read '%s'"), arg);
|
2014-11-09 12:30:49 +00:00
|
|
|
} else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
|
2011-02-22 23:42:26 +00:00
|
|
|
die_errno(_("could not open or read '%s'"), arg);
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&d->buf, 0);
|
2010-02-13 21:28:35 +00:00
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
d->given = 1;
|
2010-02-13 21:28:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-13 21:28:36 +00:00
|
|
|
static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 12:30:49 +00:00
|
|
|
struct note_data *d = opt->value;
|
2010-02-13 21:28:36 +00:00
|
|
|
char *buf;
|
|
|
|
unsigned char object[20];
|
|
|
|
enum object_type type;
|
|
|
|
unsigned long len;
|
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
if (d->buf.len)
|
|
|
|
strbuf_addch(&d->buf, '\n');
|
2010-02-13 21:28:36 +00:00
|
|
|
|
|
|
|
if (get_sha1(arg, object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), arg);
|
2014-11-09 12:30:47 +00:00
|
|
|
if (!(buf = read_sha1_file(object, &type, &len))) {
|
2010-02-13 21:28:36 +00:00
|
|
|
free(buf);
|
2014-02-12 09:54:16 +00:00
|
|
|
die(_("Failed to read object '%s'."), arg);
|
|
|
|
}
|
|
|
|
if (type != OBJ_BLOB) {
|
|
|
|
free(buf);
|
|
|
|
die(_("Cannot read note data from non-blob object '%s'."), arg);
|
2010-02-13 21:28:36 +00:00
|
|
|
}
|
2014-11-09 12:30:49 +00:00
|
|
|
strbuf_add(&d->buf, buf, len);
|
2010-02-13 21:28:36 +00:00
|
|
|
free(buf);
|
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
d->given = 1;
|
2010-02-13 21:28:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
2014-11-09 12:30:49 +00:00
|
|
|
struct note_data *d = opt->value;
|
|
|
|
d->use_editor = 1;
|
2010-02-13 21:28:36 +00:00
|
|
|
return parse_reuse_arg(opt, arg, unset);
|
|
|
|
}
|
|
|
|
|
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 07:51:05 +00:00
|
|
|
static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
|
2010-03-12 17:04:31 +00:00
|
|
|
{
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2010-03-12 17:04:32 +00:00
|
|
|
struct notes_rewrite_cfg *c = NULL;
|
2010-06-14 23:40:05 +00:00
|
|
|
struct notes_tree *t = NULL;
|
2010-03-12 17:04:31 +00:00
|
|
|
int ret = 0;
|
2013-06-12 00:12:59 +00:00
|
|
|
const char *msg = "Notes added by 'git notes copy'";
|
2010-03-12 17:04:31 +00:00
|
|
|
|
2010-03-12 17:04:32 +00:00
|
|
|
if (rewrite_cmd) {
|
|
|
|
c = init_copy_notes_for_rewrite(rewrite_cmd);
|
|
|
|
if (!c)
|
|
|
|
return 0;
|
|
|
|
} else {
|
2015-10-08 02:54:43 +00:00
|
|
|
init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
|
2010-03-12 17:04:32 +00:00
|
|
|
t = &default_notes_tree;
|
|
|
|
}
|
2010-03-12 17:04:31 +00:00
|
|
|
|
2016-01-13 23:31:17 +00:00
|
|
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
2010-03-12 17:04:31 +00:00
|
|
|
unsigned char from_obj[20], to_obj[20];
|
|
|
|
struct strbuf **split;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
split = strbuf_split(&buf, ' ');
|
|
|
|
if (!split[0] || !split[1])
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Malformed input line: '%s'."), buf.buf);
|
2010-03-12 17:04:31 +00:00
|
|
|
strbuf_rtrim(split[0]);
|
|
|
|
strbuf_rtrim(split[1]);
|
|
|
|
if (get_sha1(split[0]->buf, from_obj))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), split[0]->buf);
|
2010-03-12 17:04:31 +00:00
|
|
|
if (get_sha1(split[1]->buf, to_obj))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), split[1]->buf);
|
2010-03-12 17:04:31 +00:00
|
|
|
|
2010-03-12 17:04:32 +00:00
|
|
|
if (rewrite_cmd)
|
|
|
|
err = copy_note_for_rewrite(c, from_obj, to_obj);
|
|
|
|
else
|
|
|
|
err = copy_note(t, from_obj, to_obj, force,
|
|
|
|
combine_notes_overwrite);
|
2010-03-12 17:04:31 +00:00
|
|
|
|
|
|
|
if (err) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("Failed to copy notes from '%s' to '%s'"),
|
2010-03-12 17:04:31 +00:00
|
|
|
split[0]->buf, split[1]->buf);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_list_free(split);
|
|
|
|
}
|
|
|
|
|
2010-03-12 17:04:32 +00:00
|
|
|
if (!rewrite_cmd) {
|
2013-06-12 00:12:59 +00:00
|
|
|
commit_notes(t, msg);
|
2010-03-12 17:04:32 +00:00
|
|
|
free_notes(t);
|
|
|
|
} else {
|
2013-06-12 00:12:59 +00:00
|
|
|
finish_copy_notes_for_rewrite(c, msg);
|
2010-03-12 17:04:32 +00:00
|
|
|
}
|
2010-03-12 17:04:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
static struct notes_tree *init_notes_check(const char *subcommand,
|
|
|
|
int flags)
|
2010-02-13 21:28:20 +00:00
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2015-10-08 02:54:43 +00:00
|
|
|
const char *ref;
|
|
|
|
init_notes(NULL, NULL, NULL, flags);
|
2010-02-27 08:59:22 +00:00
|
|
|
t = &default_notes_tree;
|
2010-02-13 21:28:24 +00:00
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
|
|
|
|
if (!starts_with(ref, "refs/notes/"))
|
2010-02-27 08:59:22 +00:00
|
|
|
die("Refusing to %s notes in %s (outside of refs/notes/)",
|
2015-10-08 02:54:43 +00:00
|
|
|
subcommand, ref);
|
2010-02-27 08:59:22 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int list(int argc, const char **argv, const char *prefix)
|
2010-02-13 21:28:20 +00:00
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2010-02-27 08:59:22 +00:00
|
|
|
unsigned char object[20];
|
2010-02-13 21:28:20 +00:00
|
|
|
const unsigned char *note;
|
2010-02-27 08:59:22 +00:00
|
|
|
int retval = -1;
|
2010-02-13 21:28:20 +00:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (argc)
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_list_usage, 0);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (1 < argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_list_usage, options);
|
2010-03-12 17:04:35 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("list", 0);
|
2010-02-27 08:59:22 +00:00
|
|
|
if (argc) {
|
|
|
|
if (get_sha1(argv[0], object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), argv[0]);
|
2010-02-27 08:59:22 +00:00
|
|
|
note = get_note(t, object);
|
|
|
|
if (note) {
|
|
|
|
puts(sha1_to_hex(note));
|
|
|
|
retval = 0;
|
|
|
|
} else
|
2011-02-22 23:42:26 +00:00
|
|
|
retval = error(_("No note found for object %s."),
|
2010-02-27 08:59:22 +00:00
|
|
|
sha1_to_hex(object));
|
|
|
|
} else
|
|
|
|
retval = for_each_note(t, 0, list_each_note, NULL);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
free_notes(t);
|
|
|
|
return retval;
|
|
|
|
}
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2011-03-30 00:02:55 +00:00
|
|
|
static int append_edit(int argc, const char **argv, const char *prefix);
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
static int add(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2014-11-12 00:40:14 +00:00
|
|
|
int force = 0, allow_empty = 0;
|
2010-02-13 21:28:25 +00:00
|
|
|
const char *object_ref;
|
2010-02-27 08:59:22 +00:00
|
|
|
struct notes_tree *t;
|
|
|
|
unsigned char object[20], new_note[20];
|
|
|
|
const unsigned char *note;
|
2014-11-09 12:30:50 +00:00
|
|
|
struct note_data d = { 0, 0, NULL, STRBUF_INIT };
|
2010-02-13 21:28:20 +00:00
|
|
|
struct option options[] = {
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("note contents as a string"), PARSE_OPT_NONEG,
|
2010-02-25 00:48:11 +00:00
|
|
|
parse_msg_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'F', "file", &d, N_("file"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("note contents in a file"), PARSE_OPT_NONEG,
|
2010-02-25 00:48:11 +00:00
|
|
|
parse_file_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
|
2010-02-25 00:48:11 +00:00
|
|
|
parse_reedit_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("reuse specified note object"), PARSE_OPT_NONEG,
|
2010-02-25 00:48:11 +00:00
|
|
|
parse_reuse_arg},
|
2014-11-12 00:40:14 +00:00
|
|
|
OPT_BOOL(0, "allow-empty", &allow_empty,
|
|
|
|
N_("allow storing empty note")),
|
2012-08-20 12:32:28 +00:00
|
|
|
OPT__FORCE(&force, N_("replace existing notes")),
|
2010-02-13 21:28:20 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_add_usage,
|
2011-03-30 00:02:55 +00:00
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2011-03-30 00:02:55 +00:00
|
|
|
if (2 < argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_add_usage, options);
|
2010-03-12 17:04:35 +00:00
|
|
|
}
|
|
|
|
|
2011-03-30 00:02:55 +00:00
|
|
|
object_ref = argc > 1 ? argv[1] : "HEAD";
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (get_sha1(object_ref, object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("add", NOTES_INIT_WRITABLE);
|
2010-02-27 08:59:22 +00:00
|
|
|
note = get_note(t, object);
|
2010-02-13 21:28:25 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (note) {
|
|
|
|
if (!force) {
|
2014-11-12 00:40:12 +00:00
|
|
|
free_notes(t);
|
|
|
|
if (d.given) {
|
2014-11-09 12:30:50 +00:00
|
|
|
free_note_data(&d);
|
2014-11-12 00:40:12 +00:00
|
|
|
return error(_("Cannot add notes. "
|
|
|
|
"Found existing notes for object %s. "
|
|
|
|
"Use '-f' to overwrite existing notes"),
|
|
|
|
sha1_to_hex(object));
|
2011-03-30 00:02:55 +00:00
|
|
|
}
|
2014-11-12 00:40:12 +00: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 08:59:22 +00:00
|
|
|
}
|
2011-02-22 23:42:26 +00:00
|
|
|
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
|
2010-02-27 08:59:22 +00:00
|
|
|
sha1_to_hex(object));
|
2010-02-13 21:28:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
prepare_note_data(object, &d, note);
|
2014-11-12 00:40:14 +00:00
|
|
|
if (d.buf.len || allow_empty) {
|
2014-11-12 00:40:13 +00:00
|
|
|
write_note_data(&d, new_note);
|
|
|
|
if (add_note(t, object, new_note, combine_notes_overwrite))
|
|
|
|
die("BUG: combine_notes_overwrite failed");
|
|
|
|
commit_notes(t, "Notes added by 'git notes add'");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"),
|
|
|
|
sha1_to_hex(object));
|
2010-02-27 08:59:22 +00:00
|
|
|
remove_note(t, object);
|
2014-11-12 00:40:13 +00:00
|
|
|
commit_notes(t, "Notes removed by 'git notes add'");
|
|
|
|
}
|
2010-03-12 17:04:31 +00:00
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
free_note_data(&d);
|
2010-02-27 08:59:22 +00:00
|
|
|
free_notes(t);
|
2014-11-12 00:40:12 +00:00
|
|
|
return 0;
|
2010-02-27 08:59:22 +00:00
|
|
|
}
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
static int copy(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int retval = 0, force = 0, from_stdin = 0;
|
|
|
|
const unsigned char *from_note, *note;
|
|
|
|
const char *object_ref;
|
|
|
|
unsigned char object[20], from_obj[20];
|
|
|
|
struct notes_tree *t;
|
|
|
|
const char *rewrite_cmd = NULL;
|
|
|
|
struct option options[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
OPT__FORCE(&force, N_("replace existing notes")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")),
|
2012-08-20 12:32:28 +00:00
|
|
|
OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"),
|
|
|
|
N_("load rewriting config for <command> (implies "
|
|
|
|
"--stdin)")),
|
2010-02-27 08:59:22 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_copy_usage,
|
|
|
|
0);
|
2010-02-13 21:28:30 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (from_stdin || rewrite_cmd) {
|
|
|
|
if (argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
2010-02-13 21:28:37 +00:00
|
|
|
} else {
|
2010-02-27 08:59:22 +00:00
|
|
|
return notes_copy_from_stdin(force, rewrite_cmd);
|
2010-02-13 21:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 08:59:07 +00:00
|
|
|
if (argc < 2) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too few parameters"));
|
2010-06-28 08:59:07 +00:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
|
|
|
}
|
2010-02-27 08:59:22 +00:00
|
|
|
if (2 < argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_copy_usage, options);
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (get_sha1(argv[0], from_obj))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), argv[0]);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
object_ref = 1 < argc ? argv[1] : "HEAD";
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (get_sha1(object_ref, object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-13 21:28:20 +00:00
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("copy", NOTES_INIT_WRITABLE);
|
2010-02-13 21:28:20 +00:00
|
|
|
note = get_note(t, object);
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (note) {
|
2010-02-13 21:28:37 +00:00
|
|
|
if (!force) {
|
2011-02-22 23:42:26 +00:00
|
|
|
retval = error(_("Cannot copy notes. Found existing "
|
2010-02-27 08:59:22 +00:00
|
|
|
"notes for object %s. Use '-f' to "
|
2011-02-22 23:42:26 +00:00
|
|
|
"overwrite existing notes"),
|
2010-02-27 08:59:22 +00:00
|
|
|
sha1_to_hex(object));
|
|
|
|
goto out;
|
2010-02-13 21:28:37 +00:00
|
|
|
}
|
2011-02-22 23:42:26 +00:00
|
|
|
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
|
2010-02-13 21:28:37 +00:00
|
|
|
sha1_to_hex(object));
|
2010-02-13 21:28:30 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
from_note = get_note(t, from_obj);
|
|
|
|
if (!from_note) {
|
2011-02-22 23:42:26 +00:00
|
|
|
retval = error(_("Missing notes on source object %s. Cannot "
|
|
|
|
"copy."), sha1_to_hex(from_obj));
|
2010-02-27 08:59:22 +00:00
|
|
|
goto out;
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 23:52:26 +00:00
|
|
|
if (add_note(t, object, from_note, combine_notes_overwrite))
|
|
|
|
die("BUG: combine_notes_overwrite failed");
|
2010-02-27 08:59:22 +00:00
|
|
|
commit_notes(t, "Notes added by 'git notes copy'");
|
|
|
|
out:
|
|
|
|
free_notes(t);
|
|
|
|
return retval;
|
|
|
|
}
|
2010-02-13 21:28:32 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
static int append_edit(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2014-11-12 00:40:14 +00:00
|
|
|
int allow_empty = 0;
|
2010-02-27 08:59:22 +00:00
|
|
|
const char *object_ref;
|
|
|
|
struct notes_tree *t;
|
|
|
|
unsigned char object[20], new_note[20];
|
|
|
|
const unsigned char *note;
|
|
|
|
char logmsg[100];
|
|
|
|
const char * const *usage;
|
2014-11-09 12:30:50 +00:00
|
|
|
struct note_data d = { 0, 0, NULL, STRBUF_INIT };
|
2010-02-27 08:59:22 +00:00
|
|
|
struct option options[] = {
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'm', "message", &d, N_("message"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("note contents as a string"), PARSE_OPT_NONEG,
|
2010-02-27 08:59:22 +00:00
|
|
|
parse_msg_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'F', "file", &d, N_("file"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("note contents in a file"), PARSE_OPT_NONEG,
|
2010-02-27 08:59:22 +00:00
|
|
|
parse_file_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
|
2010-02-27 08:59:22 +00:00
|
|
|
parse_reedit_arg},
|
2014-11-09 12:30:49 +00:00
|
|
|
{ OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("reuse specified note object"), PARSE_OPT_NONEG,
|
2010-02-27 08:59:22 +00:00
|
|
|
parse_reuse_arg},
|
2014-11-12 00:40:14 +00:00
|
|
|
OPT_BOOL(0, "allow-empty", &allow_empty,
|
|
|
|
N_("allow storing empty note")),
|
2010-02-27 08:59:22 +00: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-13 21:28:25 +00:00
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
if (2 < argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(usage, options);
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 12:30:49 +00:00
|
|
|
if (d.given && edit)
|
2011-02-22 23:42:26 +00:00
|
|
|
fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated "
|
2010-02-27 08:59:22 +00:00
|
|
|
"for the 'edit' subcommand.\n"
|
2011-02-22 23:42:26 +00:00
|
|
|
"Please use 'git notes add -f -m/-F/-c/-C' instead.\n"));
|
2010-02-27 08:59:22 +00:00
|
|
|
|
|
|
|
object_ref = 1 < argc ? argv[1] : "HEAD";
|
|
|
|
|
|
|
|
if (get_sha1(object_ref, object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-27 08:59:22 +00:00
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
|
2010-02-27 08:59:22 +00:00
|
|
|
note = get_note(t, object);
|
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
prepare_note_data(object, &d, edit ? note : NULL);
|
2010-02-13 21:28:37 +00:00
|
|
|
|
2014-11-12 00:40:13 +00:00
|
|
|
if (note && !edit) {
|
|
|
|
/* Append buf to previous note contents */
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
|
|
|
char *prev_buf = read_sha1_file(note, &type, &size);
|
|
|
|
|
|
|
|
strbuf_grow(&d.buf, size + 1);
|
|
|
|
if (d.buf.len && prev_buf && size)
|
|
|
|
strbuf_insert(&d.buf, 0, "\n", 1);
|
|
|
|
if (prev_buf && size)
|
|
|
|
strbuf_insert(&d.buf, 0, prev_buf, size);
|
|
|
|
free(prev_buf);
|
|
|
|
}
|
2010-02-13 21:28:37 +00:00
|
|
|
|
2014-11-12 00:40:14 +00:00
|
|
|
if (d.buf.len || allow_empty) {
|
2014-11-12 00:40:13 +00:00
|
|
|
write_note_data(&d, new_note);
|
|
|
|
if (add_note(t, object, new_note, combine_notes_overwrite))
|
|
|
|
die("BUG: combine_notes_overwrite failed");
|
|
|
|
snprintf(logmsg, sizeof(logmsg), "Notes added by 'git notes %s'",
|
|
|
|
argv[0]);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"),
|
|
|
|
sha1_to_hex(object));
|
|
|
|
remove_note(t, object);
|
|
|
|
snprintf(logmsg, sizeof(logmsg), "Notes removed by 'git notes %s'",
|
|
|
|
argv[0]);
|
|
|
|
}
|
2010-02-13 21:28:24 +00:00
|
|
|
commit_notes(t, logmsg);
|
2014-11-12 00:40:13 +00:00
|
|
|
|
|
|
|
free_note_data(&d);
|
2010-02-13 21:28:20 +00:00
|
|
|
free_notes(t);
|
2010-02-27 08:59:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
const char *object_ref;
|
|
|
|
struct notes_tree *t;
|
|
|
|
unsigned char object[20];
|
|
|
|
const unsigned char *note;
|
|
|
|
int retval;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_show_usage,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (1 < argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_show_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ref = argc ? argv[0] : "HEAD";
|
|
|
|
|
|
|
|
if (get_sha1(object_ref, object))
|
2011-02-22 23:42:26 +00:00
|
|
|
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
2010-02-27 08:59:22 +00:00
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("show", 0);
|
2010-02-27 08:59:22 +00:00
|
|
|
note = get_note(t, object);
|
|
|
|
|
|
|
|
if (!note)
|
2011-02-22 23:42:26 +00:00
|
|
|
retval = error(_("No note found for object %s."),
|
2010-02-27 08:59:22 +00:00
|
|
|
sha1_to_hex(object));
|
|
|
|
else {
|
|
|
|
const char *show_args[3] = {"show", sha1_to_hex(note), NULL};
|
|
|
|
retval = execv_git_cmd(show_args);
|
|
|
|
}
|
|
|
|
free_notes(t);
|
2010-02-13 21:28:37 +00:00
|
|
|
return retval;
|
2010-02-13 21:28:20 +00:00
|
|
|
}
|
2010-02-27 08:59:22 +00: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-09 21:49:52 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (delete_ref("NOTES_MERGE_PARTIAL", NULL, 0))
|
|
|
|
ret += error("Failed to delete ref NOTES_MERGE_PARTIAL");
|
|
|
|
if (delete_ref("NOTES_MERGE_REF", NULL, REF_NODEREF))
|
|
|
|
ret += error("Failed to delete ref NOTES_MERGE_REF");
|
|
|
|
if (notes_merge_abort(o))
|
|
|
|
ret += error("Failed to remove 'git notes merge' worktree");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int merge_commit(struct notes_merge_options *o)
|
|
|
|
{
|
|
|
|
struct strbuf msg = STRBUF_INIT;
|
2010-11-09 21:49:54 +00:00
|
|
|
unsigned char sha1[20], parent_sha1[20];
|
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-09 21:49:52 +00:00
|
|
|
struct notes_tree *t;
|
|
|
|
struct commit *partial;
|
|
|
|
struct pretty_print_context pretty_ctx;
|
2011-12-13 14:17:48 +00:00
|
|
|
void *local_ref_to_free;
|
2011-11-13 10:22:15 +00: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-09 21:49:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read partial merge result from .git/NOTES_MERGE_PARTIAL,
|
|
|
|
* and target notes ref from .git/NOTES_MERGE_REF.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (get_sha1("NOTES_MERGE_PARTIAL", sha1))
|
|
|
|
die("Failed to read ref NOTES_MERGE_PARTIAL");
|
|
|
|
else if (!(partial = lookup_commit_reference(sha1)))
|
|
|
|
die("Could not find commit from NOTES_MERGE_PARTIAL.");
|
|
|
|
else if (parse_commit(partial))
|
|
|
|
die("Could not parse commit from NOTES_MERGE_PARTIAL.");
|
|
|
|
|
2010-11-09 21:49:54 +00:00
|
|
|
if (partial->parents)
|
2015-11-10 02:22:29 +00:00
|
|
|
hashcpy(parent_sha1, partial->parents->item->object.oid.hash);
|
2010-11-09 21:49:54 +00:00
|
|
|
else
|
|
|
|
hashclr(parent_sha1);
|
|
|
|
|
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-09 21:49:52 +00:00
|
|
|
t = xcalloc(1, sizeof(struct notes_tree));
|
|
|
|
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
|
|
|
|
|
2011-12-13 14:17:48 +00:00
|
|
|
o->local_ref = local_ref_to_free =
|
2014-07-15 19:59:36 +00:00
|
|
|
resolve_refdup("NOTES_MERGE_REF", 0, sha1, 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-09 21:49:52 +00:00
|
|
|
if (!o->local_ref)
|
|
|
|
die("Failed to resolve NOTES_MERGE_REF");
|
|
|
|
|
|
|
|
if (notes_merge_commit(o, t, partial, sha1))
|
|
|
|
die("Failed to finalize notes merge");
|
|
|
|
|
|
|
|
/* Reuse existing commit message in reflog message */
|
|
|
|
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
|
|
|
|
format_commit_message(partial, "%s", &msg, &pretty_ctx);
|
|
|
|
strbuf_trim(&msg);
|
|
|
|
strbuf_insert(&msg, 0, "notes: ", 7);
|
2010-11-09 21:49:54 +00:00
|
|
|
update_ref(msg.buf, o->local_ref, sha1,
|
|
|
|
is_null_sha1(parent_sha1) ? NULL : parent_sha1,
|
2014-04-07 13:47:56 +00: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-09 21:49:52 +00:00
|
|
|
|
|
|
|
free_notes(t);
|
|
|
|
strbuf_release(&msg);
|
2011-11-13 10:22:15 +00:00
|
|
|
ret = merge_abort(o);
|
2011-12-13 14:17:48 +00:00
|
|
|
free(local_ref_to_free);
|
2011-11-13 10:22:15 +00: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-09 21:49:52 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 21:33:33 +00:00
|
|
|
static int git_config_get_notes_strategy(const char *key,
|
|
|
|
enum notes_merge_strategy *strategy)
|
|
|
|
{
|
2016-04-01 00:35:43 +00:00
|
|
|
char *value;
|
2015-08-17 21:33:33 +00:00
|
|
|
|
2016-04-01 00:35:43 +00:00
|
|
|
if (git_config_get_string(key, &value))
|
2015-08-17 21:33:33 +00:00
|
|
|
return 1;
|
|
|
|
if (parse_notes_merge_strategy(value, strategy))
|
|
|
|
git_die_config(key, "unknown notes merge strategy %s", value);
|
|
|
|
|
2016-04-01 00:35:43 +00:00
|
|
|
free(value);
|
2015-08-17 21:33:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-09 21:49:46 +00:00
|
|
|
static int merge(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT;
|
|
|
|
unsigned char result_sha1[20];
|
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-14 23:54:11 +00:00
|
|
|
struct notes_tree *t;
|
2010-11-09 21:49:46 +00: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-09 21:49:52 +00:00
|
|
|
int do_merge = 0, do_commit = 0, do_abort = 0;
|
2010-11-09 21:49:46 +00:00
|
|
|
int verbosity = 0, result;
|
2010-11-14 23:55:12 +00:00
|
|
|
const char *strategy = NULL;
|
2010-11-09 21:49:46 +00:00
|
|
|
struct option options[] = {
|
2012-08-20 12:32:28 +00:00
|
|
|
OPT_GROUP(N_("General options")),
|
2010-11-09 21:49:46 +00:00
|
|
|
OPT__VERBOSITY(&verbosity),
|
2012-08-20 12:32:28 +00: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")),
|
2013-08-03 11:51:18 +00:00
|
|
|
{ OPTION_SET_INT, 0, "commit", &do_commit, NULL,
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("finalize notes merge by committing unmerged notes"),
|
2013-08-03 11:51:18 +00:00
|
|
|
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
|
2012-08-20 12:32:28 +00:00
|
|
|
OPT_GROUP(N_("Aborting notes merge resolution")),
|
2013-08-03 11:51:18 +00:00
|
|
|
{ OPTION_SET_INT, 0, "abort", &do_abort, NULL,
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("abort notes merge"),
|
2013-08-03 11:51:18 +00:00
|
|
|
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
|
2010-11-09 21:49:46 +00: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-09 21:49:52 +00:00
|
|
|
if (strategy || do_commit + do_abort == 0)
|
|
|
|
do_merge = 1;
|
|
|
|
if (do_merge + do_commit + do_abort != 1) {
|
|
|
|
error("cannot mix --commit, --abort or -s/--strategy");
|
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_merge && argc != 1) {
|
2010-11-09 21:49:46 +00:00
|
|
|
error("Must specify a notes ref to merge");
|
|
|
|
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-09 21:49:52 +00:00
|
|
|
} else if (!do_merge && argc) {
|
|
|
|
error("too many parameters");
|
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
2010-11-09 21:49:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init_notes_merge_options(&o);
|
|
|
|
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-09 21:49:52 +00:00
|
|
|
if (do_abort)
|
|
|
|
return merge_abort(&o);
|
|
|
|
if (do_commit)
|
|
|
|
return merge_commit(&o);
|
|
|
|
|
2010-11-09 21:49:46 +00:00
|
|
|
o.local_ref = default_notes_ref();
|
|
|
|
strbuf_addstr(&remote_ref, argv[0]);
|
2015-12-29 22:40:28 +00:00
|
|
|
expand_loose_notes_ref(&remote_ref);
|
2010-11-09 21:49:46 +00:00
|
|
|
o.remote_ref = remote_ref.buf;
|
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("merge", NOTES_INIT_WRITABLE);
|
2015-08-17 21:33:33 +00:00
|
|
|
|
2010-11-14 23:55:12 +00:00
|
|
|
if (strategy) {
|
2015-08-17 21:33:31 +00:00
|
|
|
if (parse_notes_merge_strategy(strategy, &o.strategy)) {
|
2010-11-14 23:55:12 +00:00
|
|
|
error("Unknown -s/--strategy: %s", strategy);
|
|
|
|
usage_with_options(git_notes_merge_usage, options);
|
|
|
|
}
|
2015-08-17 21:33:33 +00:00
|
|
|
} else {
|
2015-08-17 21:33:34 +00:00
|
|
|
struct strbuf merge_key = STRBUF_INIT;
|
|
|
|
const char *short_ref = NULL;
|
2010-11-14 23:55:12 +00:00
|
|
|
|
2015-08-17 21:33:34 +00:00
|
|
|
if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref))
|
|
|
|
die("BUG: local ref %s is outside of refs/notes/",
|
|
|
|
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-14 23:55:12 +00:00
|
|
|
}
|
2010-11-09 21:49:46 +00:00
|
|
|
|
|
|
|
strbuf_addf(&msg, "notes: Merged notes from %s into %s",
|
|
|
|
remote_ref.buf, default_notes_ref());
|
2010-11-09 21:49:53 +00: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-14 23:54:11 +00:00
|
|
|
|
|
|
|
result = notes_merge(&o, t, result_sha1);
|
|
|
|
|
|
|
|
if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
|
2010-11-09 21:49:46 +00:00
|
|
|
/* Update default notes ref with new commit */
|
|
|
|
update_ref(msg.buf, default_notes_ref(), result_sha1, NULL,
|
2014-04-07 13:47:56 +00: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-09 21:49:52 +00:00
|
|
|
else { /* Merge has unresolved conflicts */
|
2016-04-22 13:01:27 +00: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-09 21:49:52 +00:00
|
|
|
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
|
|
|
|
update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
|
2014-04-07 13:47:56 +00: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-09 21:49:52 +00:00
|
|
|
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
|
2016-04-22 13:01:27 +00:00
|
|
|
wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
|
|
|
|
if (wt)
|
2015-08-10 17:52:45 +00:00
|
|
|
die(_("A notes merge into %s is already in-progress at %s"),
|
2016-04-22 13:01:27 +00:00
|
|
|
default_notes_ref(), wt->path);
|
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-09 21:49:52 +00:00
|
|
|
if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
|
|
|
|
die("Failed to store link to current notes ref (%s)",
|
|
|
|
default_notes_ref());
|
|
|
|
printf("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",
|
2010-11-09 21:49:51 +00:00
|
|
|
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-09 21:49:52 +00:00
|
|
|
}
|
2010-11-09 21:49:46 +00: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-14 23:54:11 +00:00
|
|
|
free_notes(t);
|
2010-11-09 21:49:46 +00:00
|
|
|
strbuf_release(&remote_ref);
|
|
|
|
strbuf_release(&msg);
|
2010-11-09 21:49:51 +00:00
|
|
|
return result < 0; /* return non-zero on conflicts */
|
2010-11-09 21:49:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 23:44:30 +00:00
|
|
|
#define IGNORE_MISSING 1
|
2011-05-18 23:02:58 +00:00
|
|
|
|
|
|
|
static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
|
2011-05-18 22:44:37 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned char sha1[20];
|
|
|
|
if (get_sha1(name, sha1))
|
|
|
|
return error(_("Failed to resolve '%s' as a valid ref."), name);
|
|
|
|
status = remove_note(t, sha1);
|
|
|
|
if (status)
|
|
|
|
fprintf(stderr, _("Object %s has no note\n"), name);
|
|
|
|
else
|
|
|
|
fprintf(stderr, _("Removing note for object %s\n"), name);
|
2011-05-18 23:44:30 +00:00
|
|
|
return (flag & IGNORE_MISSING) ? 0 : status;
|
2011-05-18 22:44:37 +00:00
|
|
|
}
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
static int remove_cmd(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2011-05-18 23:02:58 +00:00
|
|
|
unsigned flag = 0;
|
2011-05-18 23:44:30 +00:00
|
|
|
int from_stdin = 0;
|
2010-02-27 08:59:22 +00:00
|
|
|
struct option options[] = {
|
2011-05-18 23:02:58 +00:00
|
|
|
OPT_BIT(0, "ignore-missing", &flag,
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("attempt to remove non-existent note is not an error"),
|
2011-05-18 23:44:30 +00:00
|
|
|
IGNORE_MISSING),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "stdin", &from_stdin,
|
2012-08-20 12:32:28 +00:00
|
|
|
N_("read object names from the standard input")),
|
2010-02-27 08:59:22 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
struct notes_tree *t;
|
2011-05-18 22:44:37 +00:00
|
|
|
int retval = 0;
|
2010-02-27 08:59:22 +00:00
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options,
|
|
|
|
git_notes_remove_usage, 0);
|
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("remove", NOTES_INIT_WRITABLE);
|
2010-02-27 08:59:22 +00:00
|
|
|
|
2011-05-18 23:44:30 +00:00
|
|
|
if (!argc && !from_stdin) {
|
2011-05-18 23:02:58 +00:00
|
|
|
retval = remove_one_note(t, "HEAD", flag);
|
2011-05-18 22:44:37 +00:00
|
|
|
} else {
|
|
|
|
while (*argv) {
|
2011-05-18 23:02:58 +00:00
|
|
|
retval |= remove_one_note(t, *argv, flag);
|
2011-05-18 22:44:37 +00:00
|
|
|
argv++;
|
|
|
|
}
|
2010-08-31 15:56:50 +00:00
|
|
|
}
|
2011-05-18 23:44:30 +00: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-18 22:44:37 +00:00
|
|
|
if (!retval)
|
|
|
|
commit_notes(t, "Notes removed by 'git notes remove'");
|
2010-02-27 08:59:22 +00:00
|
|
|
free_notes(t);
|
2010-08-31 15:56:50 +00:00
|
|
|
return retval;
|
2010-02-27 08:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int prune(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct notes_tree *t;
|
2010-05-14 21:42:07 +00:00
|
|
|
int show_only = 0, verbose = 0;
|
2010-02-27 08:59:22 +00:00
|
|
|
struct option options[] = {
|
2010-11-08 17:58:51 +00:00
|
|
|
OPT__DRY_RUN(&show_only, "do not remove, show only"),
|
2010-11-08 17:56:39 +00:00
|
|
|
OPT__VERBOSE(&verbose, "report pruned notes"),
|
2010-02-27 08:59:22 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_prune_usage,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (argc) {
|
2011-02-22 23:42:26 +00:00
|
|
|
error(_("too many parameters"));
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_prune_usage, options);
|
|
|
|
}
|
|
|
|
|
2015-10-08 02:54:43 +00:00
|
|
|
t = init_notes_check("prune", NOTES_INIT_WRITABLE);
|
2010-02-27 08:59:22 +00:00
|
|
|
|
2010-05-14 21:42:07 +00:00
|
|
|
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
|
|
|
|
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
|
|
|
|
if (!show_only)
|
|
|
|
commit_notes(t, "Notes removed by 'git notes prune'");
|
2010-02-27 08:59:22 +00:00
|
|
|
free_notes(t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-09 21:49:57 +00: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) {
|
|
|
|
error("too many parameters");
|
|
|
|
usage_with_options(git_notes_get_ref_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
puts(default_notes_ref());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-27 08:59:22 +00:00
|
|
|
int cmd_notes(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
const char *override_notes_ref = NULL;
|
|
|
|
struct option options[] = {
|
2014-03-23 22:58:12 +00:00
|
|
|
OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("use notes from <notes-ref>")),
|
2010-02-27 08:59:22 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
argc = parse_options(argc, argv, prefix, options, git_notes_usage,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
|
|
|
|
|
|
if (override_notes_ref) {
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
strbuf_addstr(&sb, override_notes_ref);
|
2010-11-09 21:49:45 +00:00
|
|
|
expand_notes_ref(&sb);
|
2010-02-27 08:59:22 +00:00
|
|
|
setenv("GIT_NOTES_REF", sb.buf, 1);
|
|
|
|
strbuf_release(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 1 || !strcmp(argv[0], "list"))
|
|
|
|
result = list(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "add"))
|
|
|
|
result = add(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "copy"))
|
|
|
|
result = copy(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "append") || !strcmp(argv[0], "edit"))
|
|
|
|
result = append_edit(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "show"))
|
|
|
|
result = show(argc, argv, prefix);
|
2010-11-09 21:49:46 +00:00
|
|
|
else if (!strcmp(argv[0], "merge"))
|
|
|
|
result = merge(argc, argv, prefix);
|
2010-02-27 08:59:22 +00:00
|
|
|
else if (!strcmp(argv[0], "remove"))
|
|
|
|
result = remove_cmd(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "prune"))
|
|
|
|
result = prune(argc, argv, prefix);
|
2010-11-09 21:49:57 +00:00
|
|
|
else if (!strcmp(argv[0], "get-ref"))
|
|
|
|
result = get_ref(argc, argv, prefix);
|
2010-02-27 08:59:22 +00:00
|
|
|
else {
|
2011-02-22 23:42:26 +00:00
|
|
|
result = error(_("Unknown subcommand: %s"), argv[0]);
|
2010-02-27 08:59:22 +00:00
|
|
|
usage_with_options(git_notes_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result ? 1 : 0;
|
|
|
|
}
|