summaryrefslogtreecommitdiffstats
path: root/src/syrep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/syrep.c')
-rw-r--r--src/syrep.c74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/syrep.c b/src/syrep.c
index aaf98f4..ad7619a 100644
--- a/src/syrep.c
+++ b/src/syrep.c
@@ -27,10 +27,11 @@
#include "history.h"
#include "dump.h"
#include "extract.h"
+#include "makepatch.h"
struct gengetopt_args_info args;
-int do_diff(void) {
+static int do_diff(void) {
struct syrep_db_context *c1 = NULL, *c2 = NULL;
char *path1 = NULL, *path2 = NULL;
DB *ddb = NULL;
@@ -85,7 +86,7 @@ finish:
return r;
}
-int do_merge(void) {
+static int do_merge(void) {
struct syrep_db_context *c1 = NULL, *c2 = NULL;
char *path1 = NULL, *path2 = NULL;
int r = 1;
@@ -107,7 +108,60 @@ int do_merge(void) {
goto finish;
if (!strcmp(path1, path2)) {
- fprintf(stderr, "ERROR: diff command requires two distinct snapshots as arguments\n");
+ fprintf(stderr, "ERROR: merge command requires two distinct snapshots as arguments\n");
+ goto finish;
+ }
+
+ if (!(c1 = db_context_open(path1)))
+ goto finish;
+
+ if (!(c2 = db_context_open(path2)))
+ goto finish;
+
+ if (merge(c1, c2, args.inputs[1]) < 0)
+ goto finish;
+
+ r = 0;
+
+finish:
+ if (c1)
+ db_context_free(c1);
+
+ if (c2)
+ db_context_free(c2);
+
+ if (path1)
+ free(path1);
+
+ if (path2)
+ free(path2);
+
+ return r;
+}
+
+static int do_makepatch(void) {
+ struct syrep_db_context *c1 = NULL, *c2 = NULL;
+ char *path1 = NULL, *path2 = NULL;
+ int r = 1;
+
+ if (args.inputs_num != 2) {
+ fprintf(stderr, "ERROR: Need exactly one repository and one repository snapshot for makepatch command\n");
+ goto finish;
+ }
+
+ if (isdirectory(args.inputs[0]) <= 0) {
+ fprintf(stderr, "ERROR: %s is not a directory\n", args.inputs[1]);
+ goto finish;
+ }
+
+ if (!(path1 = strdup(get_attached_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME))))
+ goto finish;
+
+ if (!(path2 = strdup(get_attached_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME))))
+ goto finish;
+
+ if (!strcmp(path1, path2)) {
+ fprintf(stderr, "ERROR: makepatch command requires two distinct snapshots as arguments\n");
goto finish;
}
@@ -117,7 +171,13 @@ int do_merge(void) {
if (!(c2 = db_context_open(path2)))
goto finish;
- if (merge_snapshot(c1, c2, args.inputs[1]) < 0)
+ if (makepatch(c1, c2, args.inputs[0]) < 0)
+ goto finish;
+
+
+ if (!args.output_file_given && isatty(fileno(stdout)))
+ fprintf(stderr, "Sorry, I am not going to write the patch data to a tty.\n");
+ else if (db_context_save(c1, args.output_file_given ? args.output_file_arg : NULL) < 0)
goto finish;
r = 0;
@@ -138,7 +198,7 @@ finish:
return r;
}
-int do_foreach(int (*func) (struct syrep_db_context *c), int m) {
+static int do_foreach(int (*func) (struct syrep_db_context *c), int m) {
char *path = NULL;
int r = 1, i;
struct syrep_db_context *c = NULL;
@@ -206,7 +266,7 @@ finish:
return r;
}
-int do_update(void) {
+static int do_update(void) {
char *path = NULL;
int r = 1, i;
struct syrep_db_context *c = NULL;
@@ -321,6 +381,8 @@ int main(int argc, char *argv[]) {
return do_foreach(dump, 0);
else if (args.extract_flag)
return do_foreach(extract, 1);
+ else if (args.makepatch_flag)
+ return do_makepatch();
cmdline_parser_print_help();