Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-01-05 22:54:14 +0400
committerJunio C Hamano <gitster@pobox.com>2012-01-06 01:02:26 +0400
commitc871a1d17b8433d98df59b03da5538f10c4ae52c (patch)
treece9d496f4015b0aa1ac08eca1f3c2e7357c725cb /commit.c
parente3f55e07076f88ec01a49dcfb7c2ac56658145a4 (diff)
commit --amend -S: strip existing gpgsig headers
Any existing commit signature was made against the contents of the old commit, including its committer date that is about to change, and will become invalid by amending it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/commit.c b/commit.c
index 27c7226abb..2162a7c572 100644
--- a/commit.c
+++ b/commit.c
@@ -981,14 +981,15 @@ static void add_extra_header(struct strbuf *buffer,
strbuf_addch(buffer, '\n');
}
-struct commit_extra_header *read_commit_extra_headers(struct commit *commit)
+struct commit_extra_header *read_commit_extra_headers(struct commit *commit,
+ const char **exclude)
{
struct commit_extra_header *extra = NULL;
unsigned long size;
enum object_type type;
char *buffer = read_sha1_file(commit->object.sha1, &type, &size);
if (buffer && type == OBJ_COMMIT)
- extra = read_commit_extra_header_lines(buffer, size);
+ extra = read_commit_extra_header_lines(buffer, size, exclude);
free(buffer);
return extra;
}
@@ -1002,7 +1003,23 @@ static inline int standard_header_field(const char *field, size_t len)
(len == 8 && !memcmp(field, "encoding ", 9)));
}
-struct commit_extra_header *read_commit_extra_header_lines(const char *buffer, size_t size)
+static int excluded_header_field(const char *field, size_t len, const char **exclude)
+{
+ if (!exclude)
+ return 0;
+
+ while (*exclude) {
+ size_t xlen = strlen(*exclude);
+ if (len == xlen &&
+ !memcmp(field, *exclude, xlen) && field[xlen] == ' ')
+ return 1;
+ exclude++;
+ }
+ return 0;
+}
+
+struct commit_extra_header *read_commit_extra_header_lines(const char *buffer, size_t size,
+ const char **exclude)
{
struct commit_extra_header *extra = NULL, **tail = &extra, *it = NULL;
const char *line, *next, *eof, *eob;
@@ -1028,7 +1045,8 @@ struct commit_extra_header *read_commit_extra_header_lines(const char *buffer, s
if (next <= eof)
eof = next;
- if (standard_header_field(line, eof - line))
+ if (standard_header_field(line, eof - line) ||
+ excluded_header_field(line, eof - line, exclude))
continue;
it = xcalloc(1, sizeof(*it));