X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/a06b419d425294588bbc6ef943246e78ca16cd73..d733de97f51cdac1316c27fb4c96eb307d4842ce:/match.c diff --git a/match.c b/match.c index 031cc30c..eae3d140 100644 --- a/match.c +++ b/match.c @@ -20,16 +20,16 @@ #include "rsync.h" extern int verbose; -extern int am_server; extern int do_progress; extern int checksum_seed; -extern int inplace; -extern int make_backups; +extern int append_mode; + +int updating_basis_file; typedef unsigned short tag; #define TABLESIZE (1<<16) -#define NULL_TAG ((size_t)-1) +#define NULL_TAG (-1) static int false_alarms; static int tag_hits; @@ -44,12 +44,12 @@ extern struct stats stats; struct target { tag t; - size_t i; + int32 i; }; static struct target *targets; -static size_t *tag_table; +static int32 *tag_table; #define gettag2(s1,s2) (((s1) + (s2)) & 0xFFFF) #define gettag(sum) gettag2((sum)&0xFFFF,(sum)>>16) @@ -62,10 +62,10 @@ static int compare_targets(struct target *t1,struct target *t2) static void build_hash_table(struct sum_struct *s) { - size_t i; + int32 i; if (!tag_table) - tag_table = new_array(size_t, TABLESIZE); + tag_table = new_array(int32, TABLESIZE); targets = new_array(struct target, s->count); if (!tag_table || !targets) @@ -102,7 +102,7 @@ static OFF_T last_match; * have only literal data. **/ static void matched(int f, struct sum_struct *s, struct map_struct *buf, - OFF_T offset, int i) + OFF_T offset, int32 i) { int32 n = offset - last_match; /* max value: block_size (int32) */ int32 j; @@ -127,18 +127,13 @@ static void matched(int f, struct sum_struct *s, struct map_struct *buf, sum_update(map_ptr(buf, last_match + j, n1), n1); } - if (i >= 0) last_match = offset + s->sums[i].len; else last_match = offset; - if (buf && do_progress) { + if (buf && do_progress) show_progress(last_match, buf->file_size); - - if (i == -1) - end_progress(buf->file_size); - } } @@ -146,8 +141,7 @@ static void hash_search(int f,struct sum_struct *s, struct map_struct *buf, OFF_T len) { OFF_T offset, end, backup; - int32 k; - size_t want_i; + int32 k, want_i; char sum2[SUM_LENGTH]; uint32 s1, s2, sum; int more; @@ -184,7 +178,7 @@ static void hash_search(int f,struct sum_struct *s, do { tag t = gettag2(s1,s2); int done_csum2 = 0; - size_t j = tag_table[t]; + int32 j = tag_table[t]; if (verbose > 4) rprintf(FINFO,"offset=%.0f sum=%08x\n",(double)offset,sum); @@ -195,8 +189,7 @@ static void hash_search(int f,struct sum_struct *s, sum = (s1 & 0xffff) | (s2 << 16); tag_hits++; do { - int32 l; - size_t i = targets[j].i; + int32 l, i = targets[j].i; if (sum != s->sums[i].sum1) continue; @@ -206,9 +199,9 @@ static void hash_search(int f,struct sum_struct *s, if (l != s->sums[i].len) continue; - /* inplace: ensure chunk's offset is either >= our + /* in-place: ensure chunk's offset is either >= our * offset or that the data didn't move. */ - if (inplace && !make_backups && s->sums[i].offset < offset + if (updating_basis_file && s->sums[i].offset < offset && !(s->sums[i].flags & SUMFLG_SAME_OFFSET)) continue; @@ -227,12 +220,12 @@ static void hash_search(int f,struct sum_struct *s, continue; } - /* If inplace is enabled, the best possible match is + /* When updating in-place, the best possible match is * one with an identical offset, so we prefer that over * the following want_i optimization. */ - if (inplace && !make_backups) { + if (updating_basis_file) { do { - size_t i2 = targets[j].i; + int32 i2 = targets[j].i; if (s->sums[i2].offset != offset) continue; if (i2 != i) { @@ -253,7 +246,7 @@ static void hash_search(int f,struct sum_struct *s, /* we've found a match, but now check to see * if want_i can hint at a better match. */ if (i != want_i && want_i < s->count - && (!inplace || make_backups || s->sums[want_i].offset >= offset + && (!updating_basis_file || s->sums[want_i].offset >= offset || s->sums[want_i].flags & SUMFLG_SAME_OFFSET) && sum == s->sums[want_i].sum1 && memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) { @@ -336,6 +329,25 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) sum_init(checksum_seed); + if (append_mode) { + OFF_T j = 0; + for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { + if (buf && do_progress) + show_progress(last_match, buf->file_size); + sum_update(map_ptr(buf, last_match, CHUNK_SIZE), + CHUNK_SIZE); + last_match = j; + } + if (last_match < s->flength) { + int32 len = s->flength - last_match; + if (buf && do_progress) + show_progress(last_match, buf->file_size); + sum_update(map_ptr(buf, last_match, len), len); + last_match = s->flength; + } + s->count = 0; + } + if (len > 0 && s->count > 0) { build_hash_table(s); @@ -349,7 +361,7 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) } else { OFF_T j; /* by doing this in pieces we avoid too many seeks */ - for (j = CHUNK_SIZE; j < len; j += CHUNK_SIZE) + for (j = last_match + CHUNK_SIZE; j < len; j += CHUNK_SIZE) matched(f, s, buf, j, -2); matched(f, s, buf, len, -1); }