summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/merge.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/merge.c b/src/merge.c
index 0aad797..0b513e2 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id: merge.c 103 2006-04-22 10:57:59Z lennart $ */
/***
This file is part of syrep.
@@ -7,12 +7,12 @@
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
syrep is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
-
+
You should have received a copy of the GNU General Public License
along with syrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -73,31 +73,31 @@ static int conflict_phase(DB *ddb, struct syrep_name *name, struct diff_entry *d
if (f2)
if ((f2 = get_current_md_by_nrecno(cb_info->c2, &nrecno2, &md2)) < 0)
return -1;
-
+
snprintf(path, sizeof(path), "%s/%s", cb_info->root, name->path);
if (f1 && f2) {
char d1[SYREP_DIGESTLENGTH*2+1], d2[SYREP_DIGESTLENGTH*2+1];
int q;
-
+
fhex(md1.digest, SYREP_DIGESTLENGTH, d1);
fhex(md2.digest, SYREP_DIGESTLENGTH, d2);
d1[SYREP_DIGESTLENGTH*2] = d2[SYREP_DIGESTLENGTH*2] = 0;
-
+
fprintf(stderr, "CONFLICT: New file '%s': %s in *local* vs. %s in *remote* repository.\n", path, d2, d1);
if (!(q = question("Replace in local repository?", "ny")))
return -1;
-
+
if (q == 'y') {
de->action = DIFF_REPLACE;
de->repository = cb_info->c1;
writeback = 1;
}
-
+
} else if (f1 || f2) {
char d[SYREP_DIGESTLENGTH*2+1];
-
+
fhex(f1 ? md1.digest : md2.digest, SYREP_DIGESTLENGTH, d);
d[SYREP_DIGESTLENGTH*2] = 0;
@@ -105,10 +105,10 @@ static int conflict_phase(DB *ddb, struct syrep_name *name, struct diff_entry *d
if (f1) {
int q;
-
+
if (!(q = question("Add to local repository?", "yn")))
return -1;
-
+
if (q == 'y') {
de->action = DIFF_COPY;
de->repository = cb_info->c1;
@@ -116,7 +116,7 @@ static int conflict_phase(DB *ddb, struct syrep_name *name, struct diff_entry *d
}
} else {
int q;
-
+
if (!(q = question("Remove from local repository?", "ny")))
return -1;
@@ -140,13 +140,13 @@ static int conflict_phase(DB *ddb, struct syrep_name *name, struct diff_entry *d
data.data = (void*) de;
data.size = sizeof(struct diff_entry);
-
+
if ((ret = ddb->put(ddb, NULL, &key, &data, 0))) {
ddb->err(ddb, ret, "ddb::put()");
return -1;
}
}
-
+
return 0;
}
@@ -155,20 +155,26 @@ static int do_copy(const char *a, const char *b) {
if (!args.always_replace_flag) {
int r, q;
-
+ char t[PATH_MAX];
+
if ((r = copy_proc(a, b, 0)) >= 0)
return r;
if (errno != EEXIST)
return r;
- if (!(q = question("Replace existing file?", "ny"))) {
+ snprintf(t, sizeof(t), "Replace existing file '%s'?", b);
+ t[sizeof(t)-1] = 0;
+
+ if (!(q = question(t, "nya"))) {
errno = EINVAL;
return -1;
}
- if (q != 'y') /* Treat as success */
- return 0;
+ if (q == 'a')
+ args.always_replace_flag = 1;
+ else if (q != 'y') /* Treat as success */
+ return 0;
}
return copy_proc(a, b, 1);
@@ -214,7 +220,7 @@ static int copy_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de, v
if (f)
if ((f = get_name_by_nrecno(cb_info->c2, &nrecno2, &name2)) < 0)
return -1;
-
+
if (f) {
char path2[PATH_MAX];
snprintf(path2, sizeof(path2), "%s/%s", cb_info->root, name2.path);
@@ -231,18 +237,18 @@ static int copy_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de, v
return -1;
} else {
snprintf(path2, sizeof(path2), "%s/%s", cb_info->trash_dir, name2.path);
-
+
if (do_copy(path2, path) < 0) {
if (errno == ENOENT)
fprintf(stderr, "COPY: Local file <%s> vanished. Snapshot not up to date\n", name2.path);
else
fprintf(stderr, "COPY: Failed to copy file '%s' to '%s': %s\n", path2, path, strerror(errno));
-
+
return -1;
}
}
}
-
+
} else {
char spath[PATH_MAX];
const char* a;
@@ -253,7 +259,7 @@ static int copy_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de, v
return -1;
t = "patch";
-
+
if (!k && cb_info->sroot) {
snprintf(spath, sizeof(spath), "%s/%s", cb_info->sroot, name->path);
a = spath;
@@ -261,14 +267,14 @@ static int copy_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de, v
if ((k = (access(spath, R_OK) == 0)))
t = "tree";
}
-
+
if (k) {
if (args.verbose_flag)
fprintf(stderr, "COPY: Copying file <%s> from %s.\n", name->path, t);
-
+
if (makeprefixpath(path, 0777) < 0)
return -1;
-
+
if (do_copy(a, path) < 0)
return -1;
} else
@@ -284,7 +290,7 @@ static int delete_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de,
char path[PATH_MAX], target[PATH_MAX];
assert(ddb && name && de && p);
-
+
if (de->action != DIFF_DELETE && de->action != DIFF_REPLACE)
return 0;
@@ -299,7 +305,7 @@ static int delete_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de,
if (args.check_md_flag) {
uint8_t digest[16];
struct syrep_md md;
-
+
if (fmd5(path, digest) < 0) {
fprintf(stderr, "Unable to calculate message digest sum on '%s'\n", name->path);
return -1;
@@ -316,28 +322,28 @@ static int delete_phase(DB *ddb, struct syrep_name *name, struct diff_entry *de,
return -1;
}
}
-
+
if (args.question_flag) {
char text[256];
int q;
snprintf(text, sizeof(text), "Delete %s?", name->path);
-
+
if ((q = question(text, "yn")) < 0)
return -1;
if (q != 'y')
return 0;
}
-
+
snprintf(target, sizeof(target), "%s/%s", cb_info->trash_dir, name->path);
-
+
if (args.verbose_flag)
fprintf(stderr, "DELETE: Moving file <%s> to <%s>\n", path, target);
if (makeprefixpath(target, 0777) < 0)
return -1;
-
+
if (move_file(path, target, 1) < 0) {
if (errno == ENOENT && !access(target, F_OK))
fprintf(stderr, "DELETE: File is probably already in trash, continuing\n");
@@ -382,15 +388,14 @@ int merge(struct syrep_db_context *c1, struct syrep_db_context *c2, const char*
if (!args.keep_trash_flag)
if (rm_rf(cb_info.trash_dir, 1) < 0)
goto finish;
-
+
r = 0;
-
+
finish:
if (ddb)
ddb->close(ddb, 0);
rmdir(cb_info.trash_dir);
-
+
return r;
}
-