sequencer: use logmsg_reencode in get_message
This simplifies the code, as logmsg_reencode handles the reencoding for us in a single call. It also means we learn logmsg_reencode's trick of pulling the buffer from disk when commit->buffer is NULL (we currently just silently return!). It is doubtful this matters in practice, though, as sequencer operations would not generally turn off save_commit_buffer. Note that we may be fixing a bug here. The existing code does: if (same_encoding(to, from)) reencode_string(buf, to, from); That probably should have been "!same_encoding". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 10, 2014 at 17:39 UTC
d74a4e57d2703e841deed994752b948a768f31ec
1 file changed
+5
-40
sequencer.c
+5
-40
@@ -116,39 +116,23 @@ static const char *action_name(const struct replay_opts *opts)
116
return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
117
}
118
119
-static char *get_encoding(const char *message);
120
-
119
struct commit_message {
120
char *parent_label;
121
const char *label;
122
const char *subject;
125
- char *reencoded_message;
123
const char *message;
124
};
125
126
static int get_message(struct commit *commit, struct commit_message *out)
127
{
131
- const char *encoding;
128
const char *abbrev, *subject;
129
int abbrev_len, subject_len;
130
char *q;
131
136
- if (!commit->buffer)
137
- return -1;
138
- encoding = get_encoding(commit->buffer);
139
- if (!encoding)
140
- encoding = "UTF-8";
132
if (!git_commit_encoding)
133
git_commit_encoding = "UTF-8";
134
144
- out->reencoded_message = NULL;
145
- out->message = commit->buffer;
146
- if (same_encoding(encoding, git_commit_encoding))
147
- out->reencoded_message = reencode_string(commit->buffer,
148
- git_commit_encoding, encoding);
149
- if (out->reencoded_message)
150
- out->message = out->reencoded_message;
151
-
135
+ out->message = logmsg_reencode(commit, NULL, git_commit_encoding);
136
abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
137
abbrev_len = strlen(abbrev);
138
@@ -167,29 +151,10 @@ static int get_message(struct commit *commit, struct commit_message *out)
151
return 0;
152
}
153
170
-static void free_message(struct commit_message *msg)
154
+static void free_message(struct commit *commit, struct commit_message *msg)
155
{
156
free(msg->parent_label);
173
- free(msg->reencoded_message);
174
-}
175
-
176
-static char *get_encoding(const char *message)
177
-{
178
- const char *p = message, *eol;
179
-
180
- while (*p && *p != '\n') {
181
- for (eol = p + 1; *eol && *eol != '\n'; eol++)
182
- ; /* do nothing */
183
- if (starts_with(p, "encoding ")) {
184
- char *result = xmalloc(eol - 8 - p);
185
- strlcpy(result, p + 9, eol - 8 - p);
186
- return result;
187
- }
188
- p = eol;
189
- if (*p == '\n')
190
- p++;
191
- }
192
- return NULL;
157
+ logmsg_free(msg->message, commit);
158
}
159
160
static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)
@@ -485,7 +450,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
450
unsigned char head[20];
451
struct commit *base, *next, *parent;
452
const char *base_label, *next_label;
488
- struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
453
+ struct commit_message msg = { NULL, NULL, NULL, NULL };
454
char *defmsg = NULL;
455
struct strbuf msgbuf = STRBUF_INIT;
456
int res, unborn = 0, allow;
@@ -650,7 +615,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
615
res = run_git_commit(defmsg, opts, allow);
616
617
leave:
653
- free_message(&msg);
618
+ free_message(commit, &msg);
619
free(defmsg);
620
621
return res;