Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit d74a4e5

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b000c59 commit d74a4e5

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

sequencer.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,39 +116,23 @@ static const char *action_name(const struct replay_opts *opts)
116116
return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
117117
}
118118

119-
static char *get_encoding(const char *message);
120-
121119
struct commit_message {
122120
char *parent_label;
123121
const char *label;
124122
const char *subject;
125-
char *reencoded_message;
126123
const char *message;
127124
};
128125

129126
static int get_message(struct commit *commit, struct commit_message *out)
130127
{
131-
const char *encoding;
132128
const char *abbrev, *subject;
133129
int abbrev_len, subject_len;
134130
char *q;
135131

136-
if (!commit->buffer)
137-
return -1;
138-
encoding = get_encoding(commit->buffer);
139-
if (!encoding)
140-
encoding = "UTF-8";
141132
if (!git_commit_encoding)
142133
git_commit_encoding = "UTF-8";
143134

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);
152136
abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
153137
abbrev_len = strlen(abbrev);
154138

@@ -167,29 +151,10 @@ static int get_message(struct commit *commit, struct commit_message *out)
167151
return 0;
168152
}
169153

170-
static void free_message(struct commit_message *msg)
154+
static void free_message(struct commit *commit, struct commit_message *msg)
171155
{
172156
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);
193158
}
194159

195160
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)
485450
unsigned char head[20];
486451
struct commit *base, *next, *parent;
487452
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 };
489454
char *defmsg = NULL;
490455
struct strbuf msgbuf = STRBUF_INIT;
491456
int res, unborn = 0, allow;
@@ -650,7 +615,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
650615
res = run_git_commit(defmsg, opts, allow);
651616

652617
leave:
653-
free_message(&msg);
618+
free_message(commit, &msg);
654619
free(defmsg);
655620

656621
return res;

0 commit comments

Comments
 (0)