Commits


always cast ctype' is*() arguments to unsigned char Almost all had already an unsigned argument (uint8_t or unsigned char), but cast anyway in case the types are changed in the future. ok stsp@


Don't return errno when fread fails fread doesn't consistently set errno on failure. - On OpenBSD fread sets errno on possible argument overflows, but this doesn't occur on other platforms. rfread doesn't set errno on EOF or other failures. - ferror does not set errno on failure. Returning errno here is possibly inconsistent. Return EIO here instead. ok stsp@


revert previous; got lib/blame.c needs diff_atom_hash_update()


make diff_atom_hash_update private to diff_atomize_text.c ok stsp@


reuse diff_atom_hash_update ok stsp@


fix accounting for line endings in CRLF files There are two different subtles error in computing the end of line in diff_data_atomize_text_lines (one in per implementation, _fd and _mmap) that causes the '\n' of the '\r\n' case to be left out the current line. It causes strange bugs when diffing CRLF files, such as printing the "\ No newline at end of file" marker very often and showing the wrong offsets in the hunk headers. ok stsp@


handle binary files like diff(1) does; new -a option forces text


expose struct diff_atom in public API for external atomizer implementations


add a missing include for uint8_t and switch from <inttypes.h> to <stdint.h> ok millert stsp


allow diff API users to atomize files separately This is a breaking API change (not that we care about that at this point). This can avoid redundant work spent on atomizing a file multiple times. There are use cases where one particular file must be compared to other files over and over again, such as when blaming file history. The old API gave access to both versions of the file to the atomizer just in case a future atomizer implementation needs this. This can still be achieved by passing a second file via the atomizer's private data pointer.


reflect ignore-whitespace in atom hash


fix off-by-one in the off-by-one fix made in bdfcb086


fix off-by-one access beyond mapped file in diff_data_atomize_text_lines_mmap() Thread 1 received signal SIGSEGV, Segmentation fault. 0x0000013992a89eca in diff_data_atomize_text_lines_mmap (d=0x13b9b455668) \ at /home/stsp/src/got/got/../lib/diff_atomize_text.c:134 134 if (line_end[0] == '\r' (gdb) p pos $1 = (const uint8_t *) 0x13be402006d "" (gdb) p end $2 = (const uint8_t *) 0x13be4023000 <error: Cannot access memory at \ address 0x13be4023000> (gdb) p end-1 $3 = (const uint8_t *) 0x13be4022fff "" (gdb) p line_end $4 = (const uint8_t *) 0x13be4023000 <error: Cannot access memory at \ address 0x13be4023000>


revert 1ea185225fc4897fdfbe0043837b43ddab3f1449 which caused an infinite loop


fix a segfault: d->data may point to "", this cannot be checked for NULL


rename diff_atom->d to diff_atom->root, because it always is The idea was that for each diff box within the files, the atoms would have a backpointer to the current layer of diff_data (indicating the current section), but it is not actually needed to update the backpointer in each atom to the current diff_data. That is why the current code always points atom->d to the root diff_data for the entire file. Clarify by proper name. Constructs like atom->d->root->foo are redundant, just use atom->root->foo.


move headers from include/diff/ to include/; makes things easier for consumers


repair DEBUG build


move some definitions from the public diff_main.h to an internal header file


use buffered stdio if falling back on file i/o; this is much faster


return error instead of abort()


rename 'debug.h' to 'diff_debug.h'


avoid include statements in header files; make each .c pull in what's needed


replace enum diff_rc errors with plain errno values


fall back on file i/o in case an input file cannot be memory-mapped