Skip to content

Commit

Permalink
Merge branch 'jc/pull-signed-tag'
Browse files Browse the repository at this point in the history
* jc/pull-signed-tag:
  commit-tree: teach -m/-F options to read logs from elsewhere
  commit-tree: update the command line parsing
  commit: teach --amend to carry forward extra headers
  merge: force edit and no-ff mode when merging a tag object
  commit: copy merged signed tags to headers of merge commit
  merge: record tag objects without peeling in MERGE_HEAD
  merge: make usage of commit->util more extensible
  fmt-merge-msg: Add contents of merged tag in the merge message
  fmt-merge-msg: package options into a structure
  fmt-merge-msg: avoid early returns
  refs DWIMmery: use the same rule for both "git fetch" and others
  fetch: allow "git fetch $there v1.0" to fetch a tag
  merge: notice local merging of tags and keep it unwrapped
  fetch: do not store peeled tag object names in FETCH_HEAD
  Split GPG interface into its own helper library

Conflicts:
	builtin/fmt-merge-msg.c
	builtin/merge.c
  • Loading branch information
Junio C Hamano committed Dec 9, 2011
2 parents a4043ae + 96b8d93 commit eb8aa3d
Show file tree
Hide file tree
Showing 83 changed files with 825 additions and 406 deletions.
16 changes: 13 additions & 3 deletions Documentation/git-commit-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ git-commit-tree - Create a new commit object
SYNOPSIS
--------
[verse]
'git commit-tree' <tree> [(-p <parent commit>)...] < changelog
'git commit-tree' <tree> [(-p <parent>)...] < changelog
'git commit-tree' [(-p <parent>)...] [(-m <message>)...] [(-F <file>)...] <tree>

DESCRIPTION
-----------
This is usually not what an end user wants to run directly. See
linkgit:git-commit[1] instead.

Creates a new commit object based on the provided tree object and
emits the new commit object id on stdout.
emits the new commit object id on stdout. The log message is read
from the standard input, unless `-m` or `-F` options are given.

A commit object may have any number of parents. With exactly one
parent, it is an ordinary commit. Having more than one parent makes
Expand All @@ -39,9 +41,17 @@ OPTIONS
<tree>::
An existing tree object

-p <parent commit>::
-p <parent>::
Each '-p' indicates the id of a parent commit object.

-m <message>::
A paragraph in the commig log message. This can be given more than
once and each <message> becomes its own paragraph.

-F <file>::
Read the commit log message from the given file. Use `-` to read
from the standard input.


Commit Information
------------------
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ LIB_H += fmt-merge-msg.h
LIB_H += fsck.h
LIB_H += gettext.h
LIB_H += git-compat-util.h
LIB_H += gpg-interface.h
LIB_H += graph.h
LIB_H += grep.h
LIB_H += hash.h
Expand Down Expand Up @@ -629,6 +630,7 @@ LIB_OBJS += entry.o
LIB_OBJS += environment.o
LIB_OBJS += exec_cmd.o
LIB_OBJS += fsck.o
LIB_OBJS += gpg-interface.o
LIB_OBJS += graph.o
LIB_OBJS += grep.o
LIB_OBJS += hash.o
Expand Down
8 changes: 7 additions & 1 deletion builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ extern const char git_usage_string[];
extern const char git_more_info_string[];

extern void prune_packed_objects(int);

struct fmt_merge_msg_opts {
unsigned add_title:1;
int shortlog_len;
};

extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
int merge_title, int shortlog_len);
struct fmt_merge_msg_opts *);
extern void commit_notes(struct notes_tree *t, const char *msg);

struct notes_rewrite_cfg {
Expand Down
74 changes: 58 additions & 16 deletions builtin/commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "builtin.h"
#include "utf8.h"

static const char commit_tree_usage[] = "git commit-tree <sha1> [(-p <sha1>)...] < changelog";
static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-F <file>] <sha1> <changelog";

static void new_parent(struct commit *parent, struct commit_list **parents_p)
{
Expand All @@ -27,7 +27,7 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)

int cmd_commit_tree(int argc, const char **argv, const char *prefix)
{
int i;
int i, got_tree = 0;
struct commit_list *parents = NULL;
unsigned char tree_sha1[20];
unsigned char commit_sha1[20];
Expand All @@ -37,24 +37,66 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)

if (argc < 2 || !strcmp(argv[1], "-h"))
usage(commit_tree_usage);
if (get_sha1(argv[1], tree_sha1))
die("Not a valid object name %s", argv[1]);

for (i = 2; i < argc; i += 2) {
unsigned char sha1[20];
const char *a, *b;
a = argv[i]; b = argv[i+1];
if (!b || strcmp(a, "-p"))
usage(commit_tree_usage);
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "-p")) {
unsigned char sha1[20];
if (argc <= ++i)
usage(commit_tree_usage);
if (get_sha1(argv[i], sha1))
die("Not a valid object name %s", argv[i]);
assert_sha1_type(sha1, OBJ_COMMIT);
new_parent(lookup_commit(sha1), &parents);
continue;
}

if (!strcmp(arg, "-m")) {
if (argc <= ++i)
usage(commit_tree_usage);
if (buffer.len)
strbuf_addch(&buffer, '\n');
strbuf_addstr(&buffer, argv[i]);
strbuf_complete_line(&buffer);
continue;
}

if (!strcmp(arg, "-F")) {
int fd;

if (get_sha1(b, sha1))
die("Not a valid object name %s", b);
assert_sha1_type(sha1, OBJ_COMMIT);
new_parent(lookup_commit(sha1), &parents);
if (argc <= ++i)
usage(commit_tree_usage);
if (buffer.len)
strbuf_addch(&buffer, '\n');
if (!strcmp(argv[i], "-"))
fd = 0;
else {
fd = open(argv[i], O_RDONLY);
if (fd < 0)
die_errno("git commit-tree: failed to open '%s'",
argv[i]);
}
if (strbuf_read(&buffer, fd, 0) < 0)
die_errno("git commit-tree: failed to read '%s'",
argv[i]);
if (fd && close(fd))
die_errno("git commit-tree: failed to close '%s'",
argv[i]);
strbuf_complete_line(&buffer);
continue;
}

if (get_sha1(arg, tree_sha1))
die("Not a valid object name %s", arg);
if (got_tree)
die("Cannot give more than one trees");
got_tree = 1;
}

if (strbuf_read(&buffer, 0, 0) < 0)
die_errno("git commit-tree: failed to read");
if (!buffer.len) {
if (strbuf_read(&buffer, 0, 0) < 0)
die_errno("git commit-tree: failed to read");
}

if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
strbuf_release(&buffer);
Expand Down
19 changes: 12 additions & 7 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
int allow_fast_forward = 1;
struct wt_status s;
struct commit *current_head = NULL;
struct commit_extra_header *extra = NULL;

if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_commit_usage, builtin_commit_options);
Expand Down Expand Up @@ -1425,7 +1426,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
pptr = &commit_list_insert(c->item, pptr)->next;
} else if (whence == FROM_MERGE) {
struct strbuf m = STRBUF_INIT;
struct commit *commit;
FILE *fp;

if (!reflog_msg)
Expand All @@ -1436,11 +1436,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
die_errno(_("could not open '%s' for reading"),
git_path("MERGE_HEAD"));
while (strbuf_getline(&m, fp, '\n') != EOF) {
unsigned char sha1[20];
if (get_sha1_hex(m.buf, sha1) < 0)
struct commit *parent;

parent = get_merge_parent(m.buf);
if (!parent)
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
commit = lookup_commit_or_die(sha1, "MERGE_HEAD");
pptr = &commit_list_insert(commit, pptr)->next;
pptr = &commit_list_insert(parent, pptr)->next;
}
fclose(fp);
strbuf_release(&m);
Expand Down Expand Up @@ -1483,12 +1484,16 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
exit(1);
}

if (commit_tree(sb.buf, active_cache_tree->sha1, parents, sha1,
author_ident.buf)) {
if (amend)
extra = read_commit_extra_headers(current_head);

if (commit_tree_extended(sb.buf, active_cache_tree->sha1, parents, sha1,
author_ident.buf, extra)) {
rollback_index_files();
die(_("failed to write commit object"));
}
strbuf_release(&author_ident);
free_commit_extra_headers(extra);

ref_lock = lock_any_ref_for_update("HEAD",
!current_head
Expand Down
3 changes: 1 addition & 2 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
}
note[note_len] = '\0';
fprintf(fp, "%s\t%s\t%s",
sha1_to_hex(commit ? commit->object.sha1 :
rm->old_sha1),
sha1_to_hex(rm->old_sha1),
rm->merge ? "" : "not-for-merge",
note);
for (i = 0; i < url_len; ++i)
Expand Down
Loading

0 comments on commit eb8aa3d

Please sign in to comment.