revert: refactor code to find commit subject in find_commit_subject()
Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jul 22, 2010 at 15:18 UTC
11af2aaed657d10dea083f5d5cb7f93bb96a7b70
3 files changed
+24
-12
builtin/revert.c
+2
-12
@@ -98,7 +98,7 @@ struct commit_message {
98
static int get_message(const char *raw_message, struct commit_message *out)
99
{
100
const char *encoding;
101
- const char *p, *abbrev, *eol;
101
+ const char *p, *abbrev;
102
char *q;
103
int abbrev_len, oneline_len;
104
@@ -121,17 +121,7 @@ static int get_message(const char *raw_message, struct commit_message *out)
121
abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
122
abbrev_len = strlen(abbrev);
123
124
- /* Find beginning and end of commit subject. */
125
- p = out->message;
126
- while (*p && (*p != '\n' || p[1] != '\n'))
127
- p++;
128
- if (*p) {
129
- p += 2;
130
- for (eol = p; *eol && *eol != '\n'; eol++)
131
- ; /* do nothing */
132
- } else
133
- eol = p;
134
- oneline_len = eol - p;
124
+ oneline_len = find_commit_subject(out->message, &p);
125
126
out->parent_label = xmalloc(strlen("parent of ") + abbrev_len +
127
strlen("... ") + oneline_len + 1);
commit.c
+19
@@ -315,6 +315,25 @@ int parse_commit(struct commit *item)
315
return ret;
316
}
317
318
+int find_commit_subject(const char *commit_buffer, const char **subject)
319
+{
320
+ const char *eol;
321
+ const char *p = commit_buffer;
322
+
323
+ while (*p && (*p != '\n' || p[1] != '\n'))
324
+ p++;
325
+ if (*p) {
326
+ p += 2;
327
+ for (eol = p; *eol && *eol != '\n'; eol++)
328
+ ; /* do nothing */
329
+ } else
330
+ eol = p;
331
+
332
+ *subject = p;
333
+
334
+ return eol - p;
335
+}
336
+
337
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
338
{
339
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
commit.h
+3
@@ -40,6 +40,9 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
40
41
int parse_commit(struct commit *item);
42
43
+/* Find beginning and length of commit subject. */
44
+int find_commit_subject(const char *commit_buffer, const char **subject);
45
+
46
struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
47
unsigned commit_list_count(const struct commit_list *l);
48
struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);