---- old/compat.c
-+++ new/compat.c
-@@ -47,6 +47,7 @@ extern int preserve_hard_links;
- extern int need_messages_from_generator;
- extern int delete_mode, delete_before, delete_during, delete_after;
- extern int delete_excluded;
+diff --git a/compat.c b/compat.c
+--- a/compat.c
++++ b/compat.c
+@@ -41,6 +41,7 @@ extern int checksum_seed;
+ extern int basis_dir_cnt;
+ extern int prune_empty_dirs;
+ extern int protocol_version;
- extern int make_backups;
- extern char *backup_dir, *backup_suffix;
- extern char *partial_dir;
-@@ -163,7 +164,7 @@ void setup_protocol(int f_out,int f_in)
- } else if (protocol_version >= 30) {
- if (recurse && allow_inc_recurse && !preserve_hard_links
- && !delete_before && !delete_after && !delay_updates
-- && !prune_empty_dirs)
-+ && !prune_empty_dirs && !detect_renamed)
- inc_recurse = 1;
- need_messages_from_generator = 1;
- }
---- old/flist.c
-+++ new/flist.c
-@@ -57,6 +57,7 @@ extern int non_perishable_cnt;
+ extern int protect_args;
+ extern int preserve_uid;
+ extern int preserve_gid;
+@@ -107,6 +108,7 @@ void set_allow_inc_recurse(void)
+ allow_inc_recurse = 0;
+ else if (!am_sender
+ && (delete_before || delete_after
++ || detect_renamed
+ || delay_updates || prune_empty_dirs))
+ allow_inc_recurse = 0;
+ else if (am_server && !local_server
+diff --git a/flist.c b/flist.c
+--- a/flist.c
++++ b/flist.c
+@@ -61,6 +61,7 @@ extern int non_perishable_cnt;
extern int prune_empty_dirs;
extern int copy_links;
extern int copy_unsafe_links;
+extern int detect_renamed;
extern int protocol_version;
extern int sanitize_paths;
extern int prune_empty_dirs;
extern int copy_links;
extern int copy_unsafe_links;
+extern int detect_renamed;
extern int protocol_version;
extern int sanitize_paths;
- extern struct stats stats;
-@@ -87,6 +88,8 @@ static int64 tmp_dev, tmp_ino;
+ extern int munge_symlinks;
+@@ -118,6 +119,8 @@ static int64 tmp_dev, tmp_ino;
+ the_fattr_list.files = new_array(struct file_struct *, j);
+ if (!the_fattr_list.files)
+ out_of_memory("recv_file_list");
+ the_fattr_list.files = new_array(struct file_struct *, j);
+ if (!the_fattr_list.files)
+ out_of_memory("recv_file_list");
- if (inc_recurse) {
- qsort(dir_flist->files + dstart, dir_flist->count - dstart,
- sizeof dir_flist->files[0], (int (*)())file_compare);
---- old/generator.c
-+++ new/generator.c
+ if (protocol_version < 30) {
+ /* Recv the io_error flag */
+ if (ignore_errors)
+diff --git a/generator.c b/generator.c
+--- a/generator.c
++++ b/generator.c
@@ -96,6 +97,7 @@ extern char *backup_suffix;
extern int backup_suffix_len;
extern struct file_list *cur_flist, *first_flist, *dir_flist;
@@ -96,6 +97,7 @@ extern char *backup_suffix;
extern int backup_suffix_len;
extern struct file_list *cur_flist, *first_flist, *dir_flist;
static int deldelay_size = 0, deldelay_cnt = 0;
static char *deldelay_buf = NULL;
static int deldelay_fd = -1;
static int deldelay_size = 0, deldelay_cnt = 0;
static char *deldelay_buf = NULL;
static int deldelay_fd = -1;
+ if (fmid->modtime == f->modtime
+ && f_name_cmp(fmid, f) == 0)
+ return -1; /* assume we can't help */
+ if (fmid->modtime == f->modtime
+ && f_name_cmp(fmid, f) == 0)
+ return -1; /* assume we can't help */
-+ /* We only use the file if we can hard-link it into our tmp dir. */
-+ if (link(fname, partialptr) == 0) {
-+ if (verbose > 2) {
-+ rprintf(FINFO, "found renamed: %s => %s\n",
-+ fname, partialptr);
++ if (!dry_run) {
++ if ((partialptr = partial_dir_fname(fn)) == NULL
++ || !handle_partial_dir(partialptr, PDIR_CREATE))
++ return;
++ /* We only use the file if we can hard-link it into our tmp dir. */
++ if (link(fname, partialptr) != 0) {
++ if (errno != EEXIST)
++ handle_partial_dir(partialptr, PDIR_DELETE);
++ return;
* its contents, otherwise just checks for content. Returns DR_SUCCESS or
* DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
* buffer is used for recursion, but returned unchanged.)
* its contents, otherwise just checks for content. Returns DR_SUCCESS or
* DR_NOT_EMPTY. Note that fname must point to a MAXPATHLEN buffer! (The
* buffer is used for recursion, but returned unchanged.)
* all the --delete-WHEN options. Note that the fbuf pointer must point to a
* MAXPATHLEN buffer with the name of the directory in it (the functions we
* call will append names onto the end, but the old dir value will be restored
- * on exit). */
* all the --delete-WHEN options. Note that the fbuf pointer must point to a
* MAXPATHLEN buffer with the name of the directory in it (the functions we
* call will append names onto the end, but the old dir value will be restored
- * on exit). */
- static void delete_in_dir(struct file_list *flist, char *fbuf,
-- struct file_struct *file, dev_t *fs_dev)
-+ struct file_struct *file, dev_t *fs_dev, int flags)
++static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev,
++ int flags)
- if (!flist) {
-@@ -430,21 +555,28 @@ static void delete_in_dir(struct file_li
+ if (!fbuf) {
+ change_local_filter_dir(NULL, 0, 0);
+@@ -430,21 +557,28 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
+ *p++ = '/';
+ remainder = MAXPATHLEN - (p - fbuf);
+
/* If an item in dirlist is not found in flist, delete it
* from the filesystem. */
+ *p++ = '/';
+ remainder = MAXPATHLEN - (p - fbuf);
+
/* If an item in dirlist is not found in flist, delete it
* from the filesystem. */
- for (i = dirlist->count; i--; ) {
-@@ -466,16 +603,23 @@ static void delete_in_dir(struct file_li
+ for (i = dirlist->used; i--; ) {
+@@ -466,16 +608,25 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
+ strlcpy(p, fp->basename, remainder);
+ look_for_rename(fp, fbuf);
+ }
+ strlcpy(p, fp->basename, remainder);
+ look_for_rename(fp, fbuf);
+ }
-- delete_in_dir(flist, fbuf, file, &st.st_dev);
-+ delete_in_dir(flist, fbuf, file, &st.st_dev, 0);
+- delete_in_dir(fbuf, file, &st.st_dev);
++ delete_in_dir(fbuf, file, &st.st_dev, 0);
-- delete_in_dir(NULL, NULL, NULL, &dev_zero);
-+ delete_in_dir(NULL, NULL, NULL, &dev_zero, 0);
+- delete_in_dir(NULL, NULL, &dev_zero);
++ delete_in_dir(NULL, NULL, &dev_zero, 0);
-- && (file->flags & FLAG_XFER_DIR))
-- delete_in_dir(cur_flist, fname, file, &real_sx.st.st_dev);
-+ && (file->flags & FLAG_XFER_DIR)) {
+- && (file->flags & FLAG_CONTENT_DIR))
+- delete_in_dir(fname, file, &real_sx.st.st_dev);
++ && (file->flags & FLAG_CONTENT_DIR)) {
-@@ -1510,8 +1659,14 @@ static void recv_generator(char *fname,
- if (preserve_hard_links && F_HLINK_NOT_LAST(file))
+@@ -1662,8 +1818,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
-@@ -1855,7 +2016,7 @@ void generate_files(int f_out, const cha
- dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
- } else
- dirdev = MAKEDEV(0, 0);
-- delete_in_dir(cur_flist, f_name(fp, fbuf), fp, &dirdev);
-+ delete_in_dir(cur_flist, f_name(fp, fbuf), fp, &dirdev, 0);
+@@ -2048,7 +2216,7 @@ void generate_files(int f_out, const char *local_name)
+ dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
+ } else
+ dirdev = MAKEDEV(0, 0);
+- delete_in_dir(f_name(fp, fbuf), fp, &dirdev);
++ delete_in_dir(f_name(fp, fbuf), fp, &dirdev, 0);
+ }
-- delete_in_dir(NULL, NULL, NULL, &dev_zero);
-+ delete_in_dir(NULL, NULL, NULL, &dev_zero, 0);
+- delete_in_dir(NULL, NULL, &dev_zero);
++ delete_in_dir(NULL, NULL, &dev_zero, 0);
rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n");
rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n");
rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n");
{"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
{"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
{"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
{"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
{"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
{"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
{"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
{"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
+ {"detect-renamed", 0, POPT_ARG_NONE, &detect_renamed, 0, 0, 0 },
{"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 },
{"compress", 'z', POPT_ARG_NONE, 0, 'z', 0, 0 },
- {"compress-level", 0, POPT_ARG_INT, &def_compress_level, 'z', 0, 0 },
-@@ -1402,7 +1405,7 @@ int parse_arguments(int *argc, const cha
+ {"no-compress", 0, POPT_ARG_VAL, &do_compression, 0, 0, 0 },
+@@ -1535,7 +1538,7 @@ int parse_arguments(int *argc_p, const char ***argv_p, int frommain)
snprintf(err_buf, sizeof err_buf,
"--%s cannot be used with --%s\n",
append_mode ? "append" : "inplace",
snprintf(err_buf, sizeof err_buf,
"--%s cannot be used with --%s\n",
append_mode ? "append" : "inplace",
- }
-
- if (modify_window_set) {
---- old/rsync.yo
-+++ new/rsync.yo
-@@ -365,6 +365,7 @@ to the detailed description below for a
+ } else {
+ if (skip_compress) {
+ if (asprintf(&arg, "--skip-compress=%s", skip_compress) < 0)
+diff --git a/rsync.yo b/rsync.yo
+--- a/rsync.yo
++++ b/rsync.yo
+@@ -385,6 +385,7 @@ to the detailed description below for a complete description. verb(
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--compare-dest=DIR also compare received files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
--compare-dest=DIR also compare received files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
-+dit(bf(--detect-renamed)) This option tells rsync to scan the receiving
-+side for files that have been renamed, and to use any that are found as
-+alternate basis files to help speed up the transfer.
++dit(bf(--detect-renamed)) With this option, for each new source file
++(call it em(src/S)), rsync looks for a file em(dest/D) anywhere in the
++destination that passes the quick check with em(src/S). If such a em(dest/D)
++is found, rsync uses it as an alternate basis for transferring em(S). The
++idea is that if em(src/S) was renamed from em(src/D) (as opposed to em(src/S)
++passing the quick check with em(dest/D) by coincidence), the delta-transfer
++algorithm will find that all the data matches between em(src/S) and em(dest/D),
++and the transfer will be really fast.
++
+By default, alternate-basis files are hard-linked into a directory named
+".~tmp~" in each file's destination directory, but if you've specified
+the bf(--partial-dir) option, that directory will be used instead. These
+By default, alternate-basis files are hard-linked into a directory named
+".~tmp~" in each file's destination directory, but if you've specified
+the bf(--partial-dir) option, that directory will be used instead. These
dit(bf(--compare-dest=DIR)) This option instructs rsync to use em(DIR) on
the destination machine as an additional hierarchy to compare destination
files against doing transfers (if the files are missing in the destination
dit(bf(--compare-dest=DIR)) This option instructs rsync to use em(DIR) on
the destination machine as an additional hierarchy to compare destination
files against doing transfers (if the files are missing in the destination