Diff
Not logged in

Differences From:

File src/merge.c part of check-in [a36177bcce] - Add the "undo" and "redo" commands. Untested at this point so don't try to use them yet. by drh on 2007-09-11 02:25:19. Also file src/merge.c part of check-in [f76192b245] - Pulled the latest CLI, website, and sqlite changes into the importer branch. by aku on 2007-09-17 01:00:32. [view]

To:

File src/merge.c part of check-in [36b96b8616] - Rework the merge algorithm. It now only works for text files. But, it no longer gets confused by line endings (\r\n versus \n) and it reports conflicts. by drh on 2007-11-16 20:42:31. Also file src/merge.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -45,9 +45,11 @@
   int vid;              /* Current version */
   int mid;              /* Version we are merging against */
   int pid;              /* The pivot version - most recent common ancestor */
   Stmt q;
+  int detailFlag;
 
+  detailFlag = find_option("detail",0,0)!=0;
   if( g.argc!=3 ){
     usage("VERSION");
   }
   db_must_be_within_tree();
@@ -216,30 +218,43 @@
   /*
   ** Do a three-way merge on files that have changes pid->mid and pid->vid
   */
   db_prepare(&q,
-    "SELECT ridm, idv, ridp FROM fv"
+    "SELECT ridm, idv, ridp, ridv FROM fv"
     " WHERE idp>0 AND idv>0 AND idm>0"
     "   AND ridm!=ridp AND (ridv!=ridp OR chnged)"
   );
   while( db_step(&q)==SQLITE_ROW ){
     int ridm = db_column_int(&q, 0);
     int idv = db_column_int(&q, 1);
     int ridp = db_column_int(&q, 2);
+    int ridv = db_column_int(&q, 3);
+    int rc;
     char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idv);
     char *zFullPath;
     Blob m, p, v, r;
     /* Do a 3-way merge of idp->idm into idp->idv.  The results go into idv. */
-    printf("MERGE %s\n", zName);
+    if( detailFlag ){
+      printf("MERGE %s  (pivot=%d v1=%d v2=%d)\n", zName, ridp, ridm, ridv);
+    }else{
+      printf("MERGE %s\n", zName);
+    }
     undo_save(zName);
     zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
-    free(zName);
     content_get(ridp, &p);
     content_get(ridm, &m);
     blob_zero(&v);
     blob_read_from_file(&v, zFullPath);
-    blob_merge(&p, &m, &v, &r);
-    blob_write_to_file(&r, zFullPath);
+    rc = blob_merge(&p, &m, &v, &r);
+    if( rc>=0 ){
+      blob_write_to_file(&r, zFullPath);
+      if( rc>0 ){
+        printf("***** %d merge conflicts in %s\n", rc, zName);
+      }
+    }else{
+      printf("***** Cannot merge binary file %s\n", zName);
+    }
+    free(zName);
     blob_reset(&p);
     blob_reset(&m);
     blob_reset(&v);
     blob_reset(&r);