Fossil

Artifact [c72ee756]
Login

Artifact [c72ee756]

Artifact c72ee75675029fff6efae39b723dcd9884adf9f5:

Attachment "patch" to ticket [aee1b21f] added by anonymous 2010-08-26 09:23:46.
--- src\diffcmd.c
+++ src\diffcmd.c
@@ -179,36 +179,57 @@
     blob_reset(&cmd);
   }
 }
 
 /*
-** Do a diff against a single file named in g.argv[2] from version zFrom
+** Do a diff against a specified file from version zFrom
 ** against the same file on disk.
 */
 static void diff_one_against_disk(
+  const char *zFile,         /* Display name of the file */
   const char *zFrom,        /* Name of file */
-  const char *zDiffCmd,     /* Use this "diff" command */
-  int ignoreEolWs           /* Ignore whitespace changes at end of lines */
+  const char *zDiffCmd      /* Use this "diff" command */
 ){
+
   Blob fname;
   Blob content;
-  file_tree_name(g.argv[2], &fname, 1);
+  file_tree_name(zFile, &fname, 1);
   historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
-  diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
+  diff_file(&content, zFile, zFile, zDiffCmd, 0);
   blob_reset(&content);
   blob_reset(&fname);
+}
+
+/*
+** Do a diff against some specified files from version zFrom
+** against the same file on disk.
+**
+** Notice: The array azFile is NULL teminated.
+*/
+static void diff_some_against_disk(
+        const char **azFile,       /* Display name of these files */
+        int nFile,                 /* Max number of files to be compared */
+        const char *zFrom,         /* which version */
+        const char *zDiffCmd       /* Command for comparison */
+){
+  while( azFile && *azFile && nFile>0 ){
+    diff_one_against_disk(*azFile, zFrom, zDiffCmd);
+
+    ++azFile;
+    --nFile;
+  }
 }
 
 /*
 ** Run a diff between the version zFrom and files on disk.  zFrom might
 ** be NULL which means to simply show the difference between the edited
 ** files on disk and the check-out on which they are based.
 */
 static void diff_all_against_disk(
   const char *zFrom,        /* Version to difference from */
-  const char *zDiffCmd,     /* Use this diff command.  NULL for built-in */
-  int ignoreEolWs           /* Ignore end-of-line whitespace */
+  const char *zDiffCmd      /* Use this diff command.  NULL for built-in */
+
 ){
   int vid;
   Blob sql;
   Stmt q;
 
@@ -275,51 +296,71 @@
       content_get(srcid, &content);
       printf("Index: %s\n======================================="
              "============================\n",
              zPathname
       );
-      diff_file(&content, zFullName, zPathname, zDiffCmd, ignoreEolWs);
+      diff_file(&content, zFullName, zPathname, zDiffCmd, 0);
       blob_reset(&content);
     }
     free(zFullName);
   }
   db_finalize(&q);
   db_end_transaction(1);  /* ROLLBACK */
 }
 
 /*
-** Output the differences between two versions of a single file.
-** zFrom and zTo are the check-ins containing the two file versions.
-** The filename is contained in g.argv[2].
+** Output the differences between two versions of a specified file.
+** zFrom and zTo are the check-ins containing the two file versions.
 */
 static void diff_one_two_versions(
+  const char *zFile,
   const char *zFrom,
   const char *zTo,
-  const char *zDiffCmd,
-  int ignoreEolWs
+  const char *zDiffCmd
 ){
   char *zName;
   Blob fname;
   Blob v1, v2;
-  file_tree_name(g.argv[2], &fname, 1);
+  file_tree_name(zFile, &fname, 1);
   zName = blob_str(&fname);
   historical_version_of_file(zFrom, zName, &v1, 0);
   historical_version_of_file(zTo, zName, &v2, 0);
-  diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
+  diff_file_mem(&v1, &v2, zName, zDiffCmd, 0);
   blob_reset(&v1);
   blob_reset(&v2);
   blob_reset(&fname);
+}
+
+/*
+** Output the differences between two versions of some specified files.
+** zFrom and zTo are the check-ins containing the two file versions.
+** These files are specified in azFile.
+**
+** Notice: The array azFile is NULL teminated.
+*/
+static void diff_some_two_versions(
+  const char **azFile,           /* Display name of these files */
+  int nFile,                     /* Max number of files to be compared */
+  const char *zFrom,             /*  */
+  const char *zTo,               /*  */
+  const char *zDiffCmd           /* Command for comparison */
+){
+  while( azFile && *azFile && nFile>0 ){
+    diff_one_two_versions(*azFile, zFrom, zTo, zDiffCmd);
+
+    ++azFile;
+    --nFile;
+  }
 }
 
 /*
 ** Output the differences between two check-ins.
 */
 static void diff_all_two_versions(
   const char *zFrom,
   const char *zTo,
-  const char *zDiffCmd,
-  int ignoreEolWs
+  const char *zDiffCmd
 ){
   Manifest mFrom, mTo;
   int iFrom, iTo;
 
   manifest_from_name(zFrom, &mFrom);
@@ -354,11 +395,11 @@
       );
       rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
       content_get(rid, &f1);
       rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
       content_get(rid, &f2);
-      diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd, ignoreEolWs);
+      diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd, 0);
       blob_reset(&f1);
       blob_reset(&f2);
       iFrom++;
       iTo++;
     }
@@ -369,11 +410,12 @@
 
 /*
 ** COMMAND: diff
 ** COMMAND: gdiff
 **
-** Usage: %fossil diff|gdiff ?options? ?FILE?
+** Usage: %fossil diff|gdiff ?options? ?FILE...?
+**    Or: %fossil diff|gdiff --from|-r VERSION --to VERSION -R REPOSITORY
 **
 ** Show the difference between the current version of FILE (as it
 ** exists on disk) and that same file as it was checked out.  Or
 ** if the FILE argument is omitted, show the unsaved changed currently
 ** in the working check-out.
@@ -408,25 +450,25 @@
     db_must_be_within_tree();
     verify_all_options();
     if( !isInternDiff ){
       zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
     }
-    if( g.argc==3 ){
-      diff_one_against_disk(zFrom, zDiffCmd, 0);
+    if( g.argc>=3 ){
+      diff_some_against_disk(&g.argv[2], g.argc-2, zFrom, zDiffCmd);
     }else{
-      diff_all_against_disk(zFrom, zDiffCmd, 0);
+      diff_all_against_disk(zFrom, zDiffCmd);
     }
   }else if( zFrom==0 ){
     fossil_fatal("must use --from if --to is present");
   }else{
     db_find_and_open_repository(1);
     verify_all_options();
     if( !isInternDiff ){
       zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0);
     }
-    if( g.argc==3 ){
-      diff_one_two_versions(zFrom, zTo, zDiffCmd, 0);
+    if( g.argc>=3 ){
+      diff_some_two_versions(&g.argv[2], g.argc-2, zFrom, zTo, zDiffCmd);
     }else{
-      diff_all_two_versions(zFrom, zTo, zDiffCmd, 0);
+      diff_all_two_versions(zFrom, zTo, zDiffCmd);
     }
   }
 }