Make --inplace work with --compare-dest, and efficient too.
[rsync/rsync-patches.git] / inplace-protocol-bump.diff
1 This patch sends the new fnamecmp_type value from the generator to the
2 sender if --inplace was specified.  This allows the sender to know when
3 the transfer can fully utilize the basis file (i.e., when the basis file
4 is not the destination file).
5
6 --- orig/generator.c    2004-11-03 20:30:45
7 +++ generator.c 2004-11-03 20:37:57
8 @@ -563,6 +563,8 @@ prepare_to_open:
9  
10  notify_others:
11         write_int(f_out, i);
12 +       if (protocol_version >= 29 && inplace && !read_batch)
13 +               write_byte(f_out, fnamecmp_type);
14         if (f_out_name >= 0)
15                 write_byte(f_out_name, fnamecmp_type);
16  
17 --- orig/match.c        2004-09-07 21:45:30
18 +++ match.c     2004-11-03 20:38:34
19 @@ -24,7 +24,8 @@ extern int am_server;
20  extern int do_progress;
21  extern int checksum_seed;
22  extern int inplace;
23 -extern int make_backups;
24 +
25 +int alternate_basis;
26  
27  typedef unsigned short tag;
28  
29 @@ -205,7 +206,7 @@ static void hash_search(int f,struct sum
30  
31                         /* inplace: ensure chunk's offset is either >= our
32                          * offset or that the data didn't move. */
33 -                       if (inplace && !make_backups && s->sums[i].offset < offset
34 +                       if (inplace && !alternate_basis && s->sums[i].offset < offset
35                             && !(s->sums[i].flags & SUMFLG_SAME_OFFSET))
36                                 continue;
37  
38 @@ -227,7 +228,7 @@ static void hash_search(int f,struct sum
39                         /* If inplace is enabled, the best possible match is
40                          * one with an identical offset, so we prefer that over
41                          * the following want_i optimization. */
42 -                       if (inplace && !make_backups) {
43 +                       if (inplace && !alternate_basis) {
44                                 do {
45                                         size_t i2 = targets[j].i;
46                                         if (s->sums[i2].offset != offset)
47 @@ -250,7 +251,7 @@ static void hash_search(int f,struct sum
48                         /* we've found a match, but now check to see
49                          * if want_i can hint at a better match. */
50                         if (i != want_i && want_i < s->count
51 -                           && (!inplace || make_backups || s->sums[want_i].offset >= offset
52 +                           && (!inplace || alternate_basis || s->sums[want_i].offset >= offset
53                              || s->sums[want_i].flags & SUMFLG_SAME_OFFSET)
54                             && sum == s->sums[want_i].sum1
55                             && memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) {
56 --- orig/options.c      2004-10-14 17:11:40
57 +++ options.c   2004-11-03 20:47:21
58 @@ -884,10 +884,9 @@ int parse_arguments(int *argc, const cha
59                          am_server ? "server" : "client");
60                 return 0;
61  #endif
62 -               if (compare_dest) {
63 +               if (link_dest) {
64                         snprintf(err_buf, sizeof err_buf,
65 -                                "--inplace does not yet work with %s\n",
66 -                                link_dest ? "--link-dest" : "--compare-dest");
67 +                                "--inplace does not yet work with --link-dest\n");
68                         return 0;
69                 }
70         } else {
71 --- orig/rsync.h        2004-11-03 20:30:45
72 +++ rsync.h     2004-11-03 20:32:34
73 @@ -62,7 +62,7 @@
74  #define FLAG_MOUNT_POINT (1<<2)        /* sender only */
75  
76  /* update this if you make incompatible changes */
77 -#define PROTOCOL_VERSION 28
78 +#define PROTOCOL_VERSION 29
79  
80  /* We refuse to interoperate with versions that are not in this range.
81   * Note that we assume we'll work with later versions: the onus is on
82 --- orig/sender.c       2004-09-20 05:10:48
83 +++ sender.c    2004-11-03 20:38:50
84 @@ -27,7 +27,9 @@ extern int dry_run;
85  extern int am_server;
86  extern int am_daemon;
87  extern int protocol_version;
88 +extern int alternate_basis;
89  extern int make_backups;
90 +extern int inplace;
91  extern struct stats stats;
92  
93  
94 @@ -117,6 +119,7 @@ void send_files(struct file_list *flist,
95         struct map_struct *mbuf = NULL;
96         STRUCT_STAT st;
97         char *fname2, fname[MAXPATHLEN];
98 +       uchar fnamecmp_type = FNAMECMP_FNAME;
99         int i;
100         struct file_struct *file;
101         int phase = 0;
102 @@ -166,6 +169,11 @@ void send_files(struct file_list *flist,
103                 } else
104                         offset = 0;
105                 fname2 = f_name_to(file, fname + offset);
106 +               if (protocol_version >= 29 && inplace) {
107 +                       fnamecmp_type = read_byte(f_in);
108 +                       alternate_basis = fnamecmp_type != FNAMECMP_FNAME;
109 +               } else
110 +                       alternate_basis = make_backups;
111  
112                 if (verbose > 2)
113                         rprintf(FINFO, "send_files(%d, %s)\n", i, fname);