#include "commit-slab.h"
#include "prio-queue.h"
#include "sha1-lookup.h"
+#include "wt-status.h"
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet)
{
- struct object *obj = deref_tag(parse_object(oid->hash), NULL, 0);
+ struct object *obj = deref_tag(parse_object(oid), NULL, 0);
if (!obj)
return NULL;
struct object_id oid;
struct commit *commit;
- if (get_sha1_committish(name, oid.hash))
+ if (get_oid_committish(name, &oid))
return NULL;
commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
return commit;
}
-static unsigned long parse_commit_date(const char *buf, const char *tail)
+static timestamp_t parse_commit_date(const char *buf, const char *tail)
{
const char *dateptr;
/* nada */;
if (buf >= tail)
return 0;
- /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
- return strtoul(dateptr, NULL, 10);
+ /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
+ return parse_timestamp(dateptr, NULL, 10);
}
static struct commit_graft **commit_graft;
return 0;
}
-struct commit_graft *read_graft_line(char *buf, int len)
+struct commit_graft *read_graft_line(struct strbuf *line)
{
/* The format is just "Commit Parent1 Parent2 ...\n" */
- int i;
+ int i, phase;
+ const char *tail = NULL;
struct commit_graft *graft = NULL;
- const int entry_size = GIT_SHA1_HEXSZ + 1;
+ struct object_id dummy_oid, *oid;
- while (len && isspace(buf[len-1]))
- buf[--len] = '\0';
- if (buf[0] == '#' || buf[0] == '\0')
+ strbuf_rtrim(line);
+ if (!line->len || line->buf[0] == '#')
return NULL;
- if ((len + 1) % entry_size)
- goto bad_graft_data;
- i = (len + 1) / entry_size - 1;
- graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
- graft->nr_parent = i;
- if (get_oid_hex(buf, &graft->oid))
- goto bad_graft_data;
- for (i = GIT_SHA1_HEXSZ; i < len; i += entry_size) {
- if (buf[i] != ' ')
- goto bad_graft_data;
- if (get_sha1_hex(buf + i + 1, graft->parent[i/entry_size].hash))
+ /*
+ * phase 0 verifies line, counts hashes in line and allocates graft
+ * phase 1 fills graft
+ */
+ for (phase = 0; phase < 2; phase++) {
+ oid = graft ? &graft->oid : &dummy_oid;
+ if (parse_oid_hex(line->buf, oid, &tail))
goto bad_graft_data;
+ for (i = 0; *tail != '\0'; i++) {
+ oid = graft ? &graft->parent[i] : &dummy_oid;
+ if (!isspace(*tail++) || parse_oid_hex(tail, oid, &tail))
+ goto bad_graft_data;
+ }
+ if (!graft) {
+ graft = xmalloc(st_add(sizeof(*graft),
+ st_mult(sizeof(struct object_id), i)));
+ graft->nr_parent = i;
+ }
}
return graft;
bad_graft_data:
- error("bad graft data: %s", buf);
- free(graft);
+ error("bad graft data: %s", line->buf);
+ assert(!graft);
return NULL;
}
static int read_graft_file(const char *graft_file)
{
- FILE *fp = fopen(graft_file, "r");
+ FILE *fp = fopen_or_warn(graft_file, "r");
struct strbuf buf = STRBUF_INIT;
if (!fp)
return -1;
while (!strbuf_getwholeline(&buf, fp, '\n')) {
/* The format is just "Commit Parent1 Parent2 ...\n" */
- struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
+ struct commit_graft *graft = read_graft_line(&buf);
if (!graft)
continue;
if (register_commit_graft(graft, 1))
commit_graft_prepared = 1;
}
-struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
+struct commit_graft *lookup_commit_graft(const struct object_id *oid)
{
int pos;
prepare_commit_graft();
- pos = commit_graft_pos(sha1);
+ pos = commit_graft_pos(oid->hash);
if (pos < 0)
return NULL;
return commit_graft[pos];
if (pos < 0)
return -1;
if (pos + 1 < commit_graft_nr)
- memmove(commit_graft + pos, commit_graft + pos + 1,
- sizeof(struct commit_graft *)
- * (commit_graft_nr - pos - 1));
+ MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,
+ commit_graft_nr - pos - 1);
commit_graft_nr--;
return 0;
}
{
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
if (v) {
- free(v->buffer);
- v->buffer = NULL;
+ FREE_AND_NULL(v->buffer);
v->size = 0;
}
}
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;
- graft = lookup_commit_graft(item->object.oid.hash);
+ graft = lookup_commit_graft(&item->object.oid);
while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
struct commit *new_parent;
static int commit_list_compare_by_date(const void *a, const void *b)
{
- unsigned long a_date = ((const struct commit_list *)a)->item->date;
- unsigned long b_date = ((const struct commit_list *)b)->item->date;
+ timestamp_t a_date = ((const struct commit_list *)a)->item->date;
+ timestamp_t b_date = ((const struct commit_list *)b)->item->date;
if (a_date < b_date)
return 1;
if (a_date > b_date)
const char *ident_line;
size_t ident_len;
char *date_end;
- unsigned long date;
+ timestamp_t date;
ident_line = find_commit_header(buffer, "author", &ident_len);
if (!ident_line)
!ident.date_begin || !ident.date_end)
goto fail_exit; /* malformed "author" line */
- date = strtoul(ident.date_begin, &date_end, 10);
+ date = parse_timestamp(ident.date_begin, &date_end, 10);
if (date_end != ident.date_end)
goto fail_exit; /* malformed date */
*(author_date_slab_at(author_date, commit)) = date;
{
const struct commit *a = a_, *b = b_;
struct author_date_slab *author_date = cb_data;
- unsigned long a_date = *(author_date_slab_at(author_date, a));
- unsigned long b_date = *(author_date_slab_at(author_date, b));
+ timestamp_t a_date = *(author_date_slab_at(author_date, a));
+ timestamp_t b_date = *(author_date_slab_at(author_date, b));
/* newer commits with larger date first */
if (a_date < b_date)
struct object *obj;
struct commit *commit;
struct object_id oid;
- if (get_sha1(name, oid.hash))
+ if (get_oid(name, &oid))
return NULL;
- obj = parse_object(oid.hash);
+ obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
if (commit && !commit->util)
set_merge_remote_desc(commit, name, obj);
/*
* Inspect the given string and determine the true "end" of the log message, in
* order to find where to put a new Signed-off-by: line. Ignored are
- * trailing comment lines and blank lines, and also the traditional
- * "Conflicts:" block that is not commented out, so that we can use
- * "git commit -s --amend" on an existing commit that forgot to remove
- * it.
+ * trailing comment lines and blank lines. To support "git commit -s
+ * --amend" on an existing commit, we also ignore "Conflicts:". To
+ * support "git commit -v", we truncate at cut lines.
*
* Returns the number of bytes from the tail to ignore, to be fed as
* the second parameter to append_signoff().
int boc = 0;
int bol = 0;
int in_old_conflicts_block = 0;
+ size_t cutoff = wt_status_locate_end(buf, len);
- while (bol < len) {
+ while (bol < cutoff) {
const char *next_line = memchr(buf + bol, '\n', len - bol);
if (!next_line)
}
bol = next_line - buf;
}
- return boc ? len - boc : 0;
+ return boc ? len - boc : len - cutoff;
}