commit - bc3056e371270495a28abba4ecc49db3d40d6f56
commit + 1e45b069d0cceff0ca943c3fe8dd62d7d2d2e8c6
blob - 5f4d297389d1fcdcdda02f1929bea4e8ecd572bf
blob + f702f135fdf85e0a7b47cd7da46228b1dceed9b9
--- lib/diffoffset.c
+++ lib/diffoffset.c
}
const struct got_error *
-got_diffoffset_add(struct got_diffoffset_chunks *chunks,
- int old_lineno, int old_length, int new_lineno, int new_length)
+add_chunk(struct got_diffoffset_chunks *chunks, int lineno, int offset)
{
- struct got_diffoffset_chunk *chunk1, *chunk2;
+ struct got_diffoffset_chunk *chunk;
- chunk1 = alloc_chunk(old_lineno, new_lineno - old_lineno);
- if (chunk1 == NULL)
+ chunk = alloc_chunk(lineno, offset);
+ if (chunk == NULL)
return got_error_from_errno("alloc_chunk");
- chunk2 = alloc_chunk(old_lineno + old_length,
- new_lineno - old_lineno + new_length - old_length);
- if (chunk2 == NULL) {
- const struct got_error *err =
- got_error_from_errno("alloc_chunk");
- free(chunk1);
- return err;
+ SIMPLEQ_INSERT_TAIL(chunks, chunk, entry);
+ return NULL;
+}
+
+
+const struct got_error *
+got_diffoffset_add(struct got_diffoffset_chunks *chunks,
+ int old_lineno, int old_length, int new_lineno, int new_length)
+{
+ const struct got_error *err = NULL;
+ int offset;
+
+ offset = new_lineno - old_lineno;
+ if (offset != 0) {
+ err = add_chunk(chunks, old_lineno, offset);
+ if (err)
+ return err;
}
- SIMPLEQ_INSERT_TAIL(chunks, chunk1, entry);
- SIMPLEQ_INSERT_TAIL(chunks, chunk2, entry);
- return NULL;
+ offset = new_lineno - old_lineno + new_length - old_length;
+ if (offset != 0)
+ err = add_chunk(chunks, old_lineno + old_length, offset);
+
+ return err;
}
int