summaryrefslogtreecommitdiffstats
path: root/src/diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/src/diff.c b/src/diff.c
index 8338be9..b722198 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -72,29 +72,40 @@ static int add_diff_entry(DB *ddb, struct syrep_name *name, int action, struct s
static int foreach(DB *ddb, struct syrep_db_context *c1, struct syrep_db_context *c2, struct syrep_name *name) {
struct syrep_md md1, md2;
- int md1_valid, md2_valid;
+ struct syrep_nrecno nrecno1, nrecno2;
+ int md1_valid = 0, md2_valid = 0;
+ int nrecno1_valid, nrecno2_valid;
+ if ((nrecno1_valid = get_nrecno_by_name(c1, name, &nrecno1, 0)) < 0)
+ return 1;
- if ((md1_valid = get_current_md_by_name(c1, name, &md1)) < 0)
- return -1;
+ if (nrecno1_valid)
+ if ((md1_valid = get_current_md_by_nrecno(c1, &nrecno1, &md1)) < 0)
+ return -1;
- if ((md2_valid = get_current_md_by_name(c2, name, &md2)) < 0)
- return -1;
+ if ((nrecno1_valid = get_nrecno_by_name(c1, name, &nrecno2, 0)) < 0)
+ return 1;
+
+ if (nrecno2_valid)
+ if ((md2_valid = get_current_md_by_nrecno(c2, &nrecno2, &md2)) < 0)
+ return -1;
//fprintf(stderr, "FOREACH %i %i %s\n", md1_valid, md2_valid, name->path);
if (md1_valid && md2_valid) {
- int f1, f2;
+ int f1 = 0, f2 = 0;
/* Same file? */
if (!memcmp(&md1, &md2, sizeof(struct syrep_md)))
return 0;
-
- if ((f1 = get_meta_by_name_md(c1, name, &md2, NULL)) < 0)
+
+ if (nrecno1_valid)
+ if ((f1 = get_meta_by_nrecno_md(c1, &nrecno1, &md2, NULL)) < 0)
+ return -1;
+
+ if (nrecno2_valid)
+ if ((f2 = get_meta_by_nrecno_md(c2, &nrecno2, &md1, NULL)) < 0)
return -1;
-
- if ((f2 = get_meta_by_name_md(c2, name, &md1, NULL)) < 0)
- return -1;
/* The version in c1 is a newer version of that in c2 */
if (f1 && !f2)
@@ -111,9 +122,10 @@ static int foreach(DB *ddb, struct syrep_db_context *c1, struct syrep_db_context
struct syrep_meta meta1, meta2;
int f1, f2;
uint32_t t1, t2;
-
- if ((md2_valid = get_last_md_by_name(c2, name, &md2)) < 0)
- return -1;
+
+ if (nrecno2_valid)
+ if ((md2_valid = get_last_md_by_nrecno(c2, &nrecno2, &md2)) < 0)
+ return -1;
if (!md2_valid)
return add_diff_entry(ddb, name, DIFF_COPY, c1);
@@ -121,10 +133,10 @@ static int foreach(DB *ddb, struct syrep_db_context *c1, struct syrep_db_context
if (memcmp(&md1, &md2, sizeof(struct syrep_md)))
return add_diff_entry(ddb, name, DIFF_COPY, c1);
- if ((f1 = get_meta_by_name_md(c1, name, &md1, &meta1)) < 0)
+ if ((f1 = get_meta_by_nrecno_md(c1, &nrecno1, &md1, &meta1)) < 0)
return -1;
- if ((f2 = get_meta_by_name_md(c2, name, &md2, &meta2)) < 0)
+ if ((f2 = get_meta_by_nrecno_md(c2, &nrecno2, &md2, &meta2)) < 0)
return -1;
if (!f1 || !f2) {
@@ -180,6 +192,8 @@ static int enumerate(DB *ddb, struct syrep_db_context *c1, struct syrep_db_conte
while ((ret = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) {
struct syrep_id *id = (struct syrep_id*) key.data;
struct syrep_meta *meta = (struct syrep_meta*) data.data;
+ struct syrep_name name;
+ int f;
assert(id && meta);
@@ -190,10 +204,15 @@ static int enumerate(DB *ddb, struct syrep_db_context *c1, struct syrep_db_conte
if (meta->last_seen != c1->version)
continue;
-
- if (foreach(ddb, c1, c2, &id->name) < 0) {
- fprintf(stderr, "foreach() failed\n");
- goto finish;
+
+ if ((f = get_name_by_nrecno(c1, &id->nrecno, &name)) < 0)
+ return -1;
+
+ if (f) {
+ if (foreach(ddb, c1, c2, &name) < 0) {
+ fprintf(stderr, "foreach() failed\n");
+ goto finish;
+ }
}
rotdash();
@@ -254,16 +273,25 @@ struct cb_info {
static int list_cb(DB *ddb, struct syrep_name *name, struct diff_entry *de, void *p) {
struct syrep_md md1, md2;
+ struct syrep_nrecno nrecno1, nrecno2;
int f1, f2;
struct cb_info *cb_info = p;
assert(name && de);
- if ((f1 = get_last_md_by_name(cb_info->c1, name, &md1)) < 0)
+ if ((f1 = get_nrecno_by_name(cb_info->c1, name, &nrecno1, 0)) < 0)
return -1;
- if ((f2 = get_last_md_by_name(cb_info->c2, name, &md2)) < 0)
+ if (f1)
+ if ((f1 = get_last_md_by_nrecno(cb_info->c1, &nrecno1, &md1)) < 0)
+ return -1;
+
+ if ((f2 = get_nrecno_by_name(cb_info->c2, name, &nrecno2, 0)) < 0)
return -1;
+
+ if (f2)
+ if ((f2 = get_last_md_by_nrecno(cb_info->c2, &nrecno2, &md2)) < 0)
+ return -1;
if (!(f1 || f2)) {
fprintf(stderr, "Diff inconsicteny\n");