Diff
Not logged in

Differences From:

File src/diffcmd.c part of check-in [c9fdb846fb] - Add the "help" command and the "clean" command. More work is needed on the text for various help messages. by drh on 2007-08-18 02:45:47. [view]

To:

File src/diffcmd.c part of check-in [c82fb61775] - Added support for a user defined diff command, which if set (fossil config diff-command), is run by default. The user can give a -i flag to run the internal diff command regardless of user defined diff command setting. Removed command tkdiff, no longer needed. Made the config remove message a bit more clear, when removing a config setting, it states it has been removed instead of telling you it's undefined. by jnc on 2007-09-24 06:53:46. [view]

@@ -41,33 +41,50 @@
     if( z[i]=='"' ) z[i] = '_';
   }
 }
 
-
-
 /*
 ** COMMAND: diff
-** COMMAND: tkdiff
 **
-** Usage: %fossil diff|tkdiff FILE...
+** Usage: %fossil diff ?-i FILE...
+**
 ** Show the difference between the current version of a file (as it
-** exists on disk) and that same file as it was checked out.  Use
-** either "diff -u" or "tkdiff".
+** exists on disk) and that same file as it was checked out.
+** If -i is supplied, the internal diff command will be executed
+** otherwise, fossil attempts to use the user configured diff-command.
+**
+** Here are a few external diff command settings, for example:
+**
+**   %fossil config diff-command=tkdiff
+**   %fossil config diff-command=eskill22
+**   %fossil config diff-command=tortoisemerge
+**   %fossil config diff-command=meld
+**   %fossil config diff-command=xxdiff
+**   %fossil config diff-command=kdiff3
 */
 void diff_cmd(void){
   const char *zFile;
   Blob cmd;
   Blob fname;
-  int i;
+  int i, internalDiff;
   char *zV1 = 0;
   char *zV2 = 0;
+
+  internalDiff = find_option("intertal","i",0)!=0;
 
   if( g.argc<3 ){
     usage("?OPTIONS? FILE");
   }
   db_must_be_within_tree();
-  blob_zero(&cmd);
-  blob_appendf(&cmd, "%s ", g.argv[1]);
+
+  if( internalDiff==0 ){
+  	const char *zExternalCommand = db_global_get("diff-command", 0);
+    if( zExternalCommand==0 ){
+      internalDiff=1;
+    }
+  	blob_zero(&cmd);
+  	blob_appendf(&cmd, "%s ", zExternalCommand);
+  }
   for(i=2; i<g.argc-1; i++){
     const char *z = g.argv[i];
     if( (strcmp(z,"-v")==0 || strcmp(z,"--version")==0) && i<g.argc-2 ){
       if( zV1==0 ){
@@ -77,9 +94,11 @@
       }else{
         fossil_panic("too many versions");
       }
     }else{
-      blob_appendf(&cmd, "%s ", z);
+      if( internalDiff==0 ){
+        blob_appendf(&cmd, "%s ", z);
+      }
     }
   }
   zFile = g.argv[g.argc-1];
   if( !file_tree_name(zFile, &fname) ){
@@ -99,18 +118,30 @@
       blob_reset(&vname);
       blob_appendf(&vname, "%s~%d", zFile, cnt++);
     }while( access(blob_str(&vname),0)==0 );
     content_get(rid, &record);
-    blob_write_to_file(&record, blob_str(&vname));
-    blob_reset(&record);
-    shell_escape(&cmd, blob_str(&vname));
-    blob_appendf(&cmd, " ");
-    shell_escape(&cmd, zFile);
-    system(blob_str(&cmd));
-    unlink(blob_str(&vname));
-    blob_reset(&vname);
-    blob_reset(&cmd);
+    if( internalDiff==1 ){
+      Blob current;
+      Blob out;
+      blob_zero(&current);
+      blob_read_from_file(&current, zFile);
+      blob_zero(&out);
+      unified_diff(&current, &record, 5, &out);
+      printf("%s\n", blob_str(&out));
+      blob_reset(&current);
+      blob_reset(&out);
+    }else{
+      blob_write_to_file(&record, blob_str(&vname));
+      blob_reset(&record);
+      shell_escape(&cmd, blob_str(&vname));
+      blob_appendf(&cmd, " ");
+      shell_escape(&cmd, zFile);
+      system(blob_str(&cmd));
+      unlink(blob_str(&vname));
+      blob_reset(&vname);
+      blob_reset(&cmd);
+    }
   }else{
     fossil_panic("not yet implemented");
   }
   blob_reset(&fname);
 }