AmendHub

Download:

jcs

/

amend

/

amendments

/

141

repo: Bump repo version just to fix diffs generated in 3.3

3.3 had a bug in diffreg that was inserting errant newlines after a
@@ chunk, which confuses patch. We can detect and fix these, which
we do with a version migration. The repo format doesn't actually
change.
 
Unfortunately we still have problems with files that didn't have
newlines at the end since we were just inserting a newline rather
than leaving the default "\ No newline at end of file" that diff
prints, which patch knows to ignore. I'm not sure it's possible to
automatically detect and fix such diffs at this point.
 
Also show amendment number when viewing.

jcs made amendment 141 over 2 years ago
--- repo.c Fri Mar 15 08:23:12 2024 +++ repo.c Mon Mar 18 08:54:33 2024 @@ -393,10 +393,12 @@ repo_diff_header(struct repo *repo, struct repo_amendm *ret = xmalloc(128 + amendment->log_len); ttm = localtime(&amendment->date); - header_len = sprintf(*ret, - "Author: %s\r" - "Date: %04d-%02d-%02d %02d:%02d:%02d\r" + header_len = snprintf(*ret, 128, + "Amendment: %d\r" + "Author: %s\r" + "Date: %04d-%02d-%02d %02d:%02d:%02d\r" "\r ", + amendment->id, amendment->author, ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, ttm->tm_hour, ttm->tm_min, ttm->tm_sec); @@ -1190,7 +1192,9 @@ repo_migrate(struct repo *repo, bool is_new) if (!is_new) { progress("Backing up repo..."); + SetCursor(*(GetCursor(watchCursor))); repo_backup(repo); + SetCursor(&arrow); } /* per-version migrations */ @@ -1203,6 +1207,70 @@ repo_migrate(struct repo *repo, bool is_new) case 2: /* 2->3 was switching from resource forks to bile */ break; + case 3: { + /* 3->4 fixes diffs generated in 3.3 */ + size_t namendments, i, n, j, size; + char *diff; + unsigned long *ids; + bool bad; + + namendments = bile_sorted_ids_by_type(repo->bile, + REPO_AMENDMENT_RTYPE, &ids); + + for (i = 0; i < namendments; i++) { + progress("Checking amendment %lu/%lu...", ids[i], + namendments); + + size = bile_read_alloc(repo->bile, REPO_DIFF_RTYPE, ids[i], + &diff); + if (size == 0) + panic("Failed finding DIFF %d, corrupted repo?", + ids[i]); + + bad = false; + for (n = 0; n < size; ) { + /* look for \r@@ */ + if (!(n > 3 && diff[n - 2] == '\r' && + diff[n - 1] == '@' && diff[n] == '@')) { + n++; + continue; + } + + /* walk to end of line */ + for (; n < size; n++) { + if (diff[n] == '\r') { + n++; + break; + } + } + if (n == size) + break; + + if (diff[n] != '\r') + continue; + + /* found @@...\r\r, remove second \r */ + progress("Fixing bad diff chunk in amendment %lu...", + ids[i]); + for (j = n; j < size - 1; j++) + diff[j] = diff[j + 1]; + size--; + bad = true; + } + + if (bad) { + progress("Saving fixed diff for amendment %lu...", + ids[i]); + bile_write(repo->bile, REPO_DIFF_RTYPE, + ids[i], diff, size); + } + + xfree(&diff); + } + + xfree(&ids); + break; + } } ver++; --- repo.h Thu Jan 11 13:31:35 2024 +++ repo.h Fri Mar 15 08:55:31 2024 @@ -34,7 +34,7 @@ #define REPO_DIFF_TOO_BIG "\r[ Diff too large to view, %lu bytes not shown ]" -#define REPO_CUR_VERS 3 +#define REPO_CUR_VERS 4 struct repo_file { short id;