1 Depends-On-Patch: g2r-basis-filename.diff
3 This patch allows multiple --compare-dest or --link-dest options to be
4 used, making the transfer of some files more optimal. Note that the
5 algorithm does NOT search for the best match -- it stops at the first
6 match and uses that as the basis file for the transfer, so be sure to
7 order your arguments appropriately (the args are searched in the order
10 Before compiling, be sure to run "make proto".
12 --- orig/generator.c 2004-07-29 16:46:28
13 +++ generator.c 2004-07-29 16:42:25
14 @@ -43,7 +43,7 @@ extern int io_timeout;
15 extern int protocol_version;
16 extern int always_checksum;
17 extern char *partial_dir;
18 -extern char *compare_dest;
19 +extern char *compare_dest[];
21 extern int whole_file;
22 extern int local_server;
23 @@ -413,11 +413,19 @@ static void recv_generator(char *fname,
27 - if (statret == -1 && compare_dest != NULL) {
28 + if (statret == -1 && compare_dest[0] != NULL) {
29 /* try the file at compare_dest instead */
30 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
31 - if (link_stat(fnamecmpbuf, &st, 0) == 0
32 - && S_ISREG(st.st_mode)) {
35 + pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
36 + compare_dest[i], fname);
37 + if (link_stat(fnamecmpbuf, &st, 0) == 0
38 + && S_ISREG(st.st_mode)) {
42 + } while (compare_dest[++i] != NULL);
45 if (link_dest && !dry_run) {
46 if (do_link(fnamecmpbuf, fname) < 0) {
47 @@ -433,7 +441,6 @@ static void recv_generator(char *fname,
50 fnamecmp = fnamecmpbuf;
55 --- orig/main.c 2004-07-22 00:10:43
56 +++ main.c 2004-07-22 00:30:38
57 @@ -58,7 +58,7 @@ extern int filesfrom_fd;
58 extern pid_t cleanup_child_pid;
59 extern char *files_from;
60 extern char *remote_filesfrom_file;
61 -extern char *compare_dest;
62 +extern char *compare_dest[];
63 extern char *rsync_path;
64 extern char *shell_cmd;
65 extern char *batch_name;
66 @@ -458,7 +458,7 @@ static int do_recv(int f_in,int f_out,st
69 int error_pipe[2], name_pipe[2];
70 - BOOL need_name_pipe = compare_dest && !dry_run;
71 + BOOL need_name_pipe = compare_dest[0] && !dry_run;
73 if (preserve_hard_links)
74 init_hard_links(flist);
75 --- orig/options.c 2004-07-29 16:08:03
76 +++ options.c 2004-07-29 16:31:11
77 @@ -114,12 +114,13 @@ int write_batch = 0;
79 int backup_dir_len = 0;
80 int backup_suffix_len;
81 +int num_comp_dest = 0;
82 unsigned int backup_dir_remainder;
84 char *backup_suffix = NULL;
86 char *partial_dir = NULL;
87 -char *compare_dest = NULL;
88 +char *compare_dest[MAX_COMP_DEST+1];
89 char *config_file = NULL;
90 char *shell_cmd = NULL;
91 char *log_format = NULL;
92 @@ -140,6 +141,7 @@ char *batch_name = NULL;
94 static int daemon_opt; /* sets am_daemon after option error-reporting */
95 static int modify_window_set;
96 +static int saw_compare_dest = 0;
98 /** Local address to bind. As a character string because it's
99 * interpreted by the IPv6 layer: should be a numeric IP4 or IP6
100 @@ -317,7 +319,7 @@ void usage(enum logcode F)
103 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
104 - OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
105 + OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_COMPARE_DEST, OPT_LINK_DEST,
106 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
107 OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
108 OPT_REFUSED_BASE = 9000};
109 @@ -376,8 +378,8 @@ static struct poptOption long_options[]
110 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
111 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
112 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
113 - {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
114 - {"link-dest", 0, POPT_ARG_STRING, &compare_dest, OPT_LINK_DEST, 0, 0 },
115 + {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
116 + {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
117 /* TODO: Should this take an optional int giving the compression level? */
118 {"compress", 'z', POPT_ARG_NONE, &do_compression, 0, 0, 0 },
119 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
120 @@ -594,8 +596,28 @@ int parse_arguments(int *argc, const cha
121 select_timeout = io_timeout;
124 + case OPT_COMPARE_DEST:
125 + if (num_comp_dest >= MAX_COMP_DEST-1) {
126 + rprintf(FERROR, "ERROR: %s\n", "too many --compare-dest args given");
129 + arg = poptGetOptArg(pc);
130 + if (sanitize_paths)
131 + arg = alloc_sanitize_path(arg, curr_dir);
132 + compare_dest[num_comp_dest++] = (char *)arg;
133 + saw_compare_dest = 1;
138 + if (num_comp_dest >= MAX_COMP_DEST-1) {
139 + rprintf(FERROR, "ERROR: %s\n", "too many --link-dest args given");
142 + arg = poptGetOptArg(pc);
143 + if (sanitize_paths)
144 + arg = alloc_sanitize_path(arg, curr_dir);
145 + compare_dest[num_comp_dest++] = (char *)arg;
149 @@ -693,6 +715,11 @@ int parse_arguments(int *argc, const cha
150 exit_cleanup(RERR_SYNTAX);
153 + if (saw_compare_dest && link_dest) {
155 + "WARNING: promoting --compare-dest options to --link-dest.\n");
161 @@ -723,8 +750,6 @@ int parse_arguments(int *argc, const cha
162 tmpdir = alloc_sanitize_path(tmpdir, curr_dir);
164 partial_dir = alloc_sanitize_path(partial_dir, curr_dir);
166 - compare_dest = alloc_sanitize_path(compare_dest, curr_dir);
168 backup_dir = alloc_sanitize_path(backup_dir, curr_dir);
170 @@ -839,8 +864,8 @@ int parse_arguments(int *argc, const cha
172 void server_options(char **args,int *argc)
174 + static char argstr[50+MAX_COMP_DEST*2];
176 - static char argstr[50];
180 @@ -1021,13 +1046,16 @@ void server_options(char **args,int *arg
184 - if (compare_dest && am_sender) {
185 + if (compare_dest[0] && am_sender) {
186 /* the server only needs this option if it is not the sender,
187 * and it may be an older version that doesn't know this
188 * option, so don't send it if client is the sender.
190 - args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
191 - args[ac++] = compare_dest;
193 + for (i = 0; i < num_comp_dest; i++) {
194 + args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
195 + args[ac++] = compare_dest[i];
199 if (files_from && (!am_sender || remote_filesfrom_file)) {
200 --- orig/receiver.c 2004-07-23 21:59:07
201 +++ receiver.c 2004-07-23 22:05:04
202 @@ -39,7 +39,6 @@ extern int cvs_exclude;
205 extern char *partial_dir;
206 -extern char *compare_dest;
207 extern int make_backups;
208 extern int do_progress;
209 extern char *backup_dir;
210 --- orig/rsync.h 2004-07-29 16:08:03
211 +++ rsync.h 2004-07-03 17:33:30
214 #define MAX_ARGS 1000
216 +#define MAX_COMP_DEST 20
220 #define NO_EXCLUDES 0