Fossil SCM
Allow more than one file to be specified to the diff command.
Commit
3cdcb51573a0e6d9fc47699fa0e4cd1ed6b1323d
Parent
dd74352d2c919e7…
1 file changed
+22
-16
+22
-16
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -175,23 +175,24 @@ | ||
| 175 | 175 | blob_reset(&cmd); |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /* |
| 180 | -** Do a diff against a single file named in g.argv[2] from version zFrom | |
| 180 | +** Do a diff against a single file named in zFileTreeName from version zFrom | |
| 181 | 181 | ** against the same file on disk. |
| 182 | 182 | */ |
| 183 | 183 | static void diff_one_against_disk( |
| 184 | 184 | const char *zFrom, /* Name of file */ |
| 185 | 185 | const char *zDiffCmd, /* Use this "diff" command */ |
| 186 | - int ignoreEolWs /* Ignore whitespace changes at end of lines */ | |
| 186 | + int ignoreEolWs, /* Ignore whitespace changes at end of lines */ | |
| 187 | + const char *zFileTreeName | |
| 187 | 188 | ){ |
| 188 | 189 | Blob fname; |
| 189 | 190 | Blob content; |
| 190 | - file_tree_name(g.argv[2], &fname, 1); | |
| 191 | + file_tree_name(zFileTreeName, &fname, 1); | |
| 191 | 192 | historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0); |
| 192 | - diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs); | |
| 193 | + diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs); | |
| 193 | 194 | blob_reset(&content); |
| 194 | 195 | blob_reset(&fname); |
| 195 | 196 | } |
| 196 | 197 | |
| 197 | 198 | /* |
| @@ -295,22 +296,22 @@ | ||
| 295 | 296 | } |
| 296 | 297 | |
| 297 | 298 | /* |
| 298 | 299 | ** Output the differences between two versions of a single file. |
| 299 | 300 | ** zFrom and zTo are the check-ins containing the two file versions. |
| 300 | -** The filename is contained in g.argv[2]. | |
| 301 | 301 | */ |
| 302 | 302 | static void diff_one_two_versions( |
| 303 | 303 | const char *zFrom, |
| 304 | 304 | const char *zTo, |
| 305 | 305 | const char *zDiffCmd, |
| 306 | - int ignoreEolWs | |
| 306 | + int ignoreEolWs, | |
| 307 | + const char *zFileTreeName | |
| 307 | 308 | ){ |
| 308 | 309 | char *zName; |
| 309 | 310 | Blob fname; |
| 310 | 311 | Blob v1, v2; |
| 311 | - file_tree_name(g.argv[2], &fname, 1); | |
| 312 | + file_tree_name(zFileTreeName, &fname, 1); | |
| 312 | 313 | zName = blob_str(&fname); |
| 313 | 314 | historical_version_of_file(zFrom, zName, &v1, 0, 0); |
| 314 | 315 | historical_version_of_file(zTo, zName, &v2, 0, 0); |
| 315 | 316 | diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs); |
| 316 | 317 | blob_reset(&v1); |
| @@ -408,16 +409,16 @@ | ||
| 408 | 409 | |
| 409 | 410 | /* |
| 410 | 411 | ** COMMAND: diff |
| 411 | 412 | ** COMMAND: gdiff |
| 412 | 413 | ** |
| 413 | -** Usage: %fossil diff|gdiff ?options? ?FILE? | |
| 414 | +** Usage: %fossil diff|gdiff ?options? ?FILE1? ?FILE2 ...? | |
| 414 | 415 | ** |
| 415 | -** Show the difference between the current version of FILE (as it | |
| 416 | -** exists on disk) and that same file as it was checked out. Or | |
| 417 | -** if the FILE argument is omitted, show the unsaved changed currently | |
| 418 | -** in the working check-out. | |
| 416 | +** Show the difference between the current version of each of the FILEs | |
| 417 | +** specified (as they exist on disk) and that same file as it was checked | |
| 418 | +** out. Or if the FILE arguments are omitted, show the unsaved changed | |
| 419 | +** currently in the working check-out. | |
| 419 | 420 | ** |
| 420 | 421 | ** If the "--from VERSION" or "-r VERSION" option is used it specifies |
| 421 | 422 | ** the source check-in for the diff operation. If not specified, the |
| 422 | 423 | ** source check-in is the base check-in for the current check-out. |
| 423 | 424 | ** |
| @@ -440,10 +441,11 @@ | ||
| 440 | 441 | int hasNFlag; /* True if -N or --new-file flag is used */ |
| 441 | 442 | const char *zFrom; /* Source version number */ |
| 442 | 443 | const char *zTo; /* Target version number */ |
| 443 | 444 | const char *zDiffCmd = 0; /* External diff command. NULL for internal diff */ |
| 444 | 445 | int diffFlags = 0; /* Flags to control the DIFF */ |
| 446 | + int f; | |
| 445 | 447 | |
| 446 | 448 | isGDiff = g.argv[1][0]=='g'; |
| 447 | 449 | isInternDiff = find_option("internal","i",0)!=0; |
| 448 | 450 | zFrom = find_option("from", "r", 1); |
| 449 | 451 | zTo = find_option("to", 0, 1); |
| @@ -455,12 +457,14 @@ | ||
| 455 | 457 | db_must_be_within_tree(); |
| 456 | 458 | verify_all_options(); |
| 457 | 459 | if( !isInternDiff ){ |
| 458 | 460 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 459 | 461 | } |
| 460 | - if( g.argc==3 ){ | |
| 461 | - diff_one_against_disk(zFrom, zDiffCmd, 0); | |
| 462 | + if( g.argc>=3 ){ | |
| 463 | + for(f=2; f<g.argc; ++f){ | |
| 464 | + diff_one_against_disk(zFrom, zDiffCmd, 0, g.argv[f]); | |
| 465 | + } | |
| 462 | 466 | }else{ |
| 463 | 467 | diff_all_against_disk(zFrom, zDiffCmd, diffFlags); |
| 464 | 468 | } |
| 465 | 469 | }else if( zFrom==0 ){ |
| 466 | 470 | fossil_fatal("must use --from if --to is present"); |
| @@ -468,12 +472,14 @@ | ||
| 468 | 472 | db_find_and_open_repository(0, 0); |
| 469 | 473 | verify_all_options(); |
| 470 | 474 | if( !isInternDiff ){ |
| 471 | 475 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 472 | 476 | } |
| 473 | - if( g.argc==3 ){ | |
| 474 | - diff_one_two_versions(zFrom, zTo, zDiffCmd, 0); | |
| 477 | + if( g.argc>=3 ){ | |
| 478 | + for(f=2; f<g.argc; ++f){ | |
| 479 | + diff_one_two_versions(zFrom, zTo, zDiffCmd, 0, g.argv[f]); | |
| 480 | + } | |
| 475 | 481 | }else{ |
| 476 | 482 | diff_all_two_versions(zFrom, zTo, zDiffCmd, diffFlags); |
| 477 | 483 | } |
| 478 | 484 | } |
| 479 | 485 | } |
| 480 | 486 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -175,23 +175,24 @@ | |
| 175 | blob_reset(&cmd); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | ** Do a diff against a single file named in g.argv[2] from version zFrom |
| 181 | ** against the same file on disk. |
| 182 | */ |
| 183 | static void diff_one_against_disk( |
| 184 | const char *zFrom, /* Name of file */ |
| 185 | const char *zDiffCmd, /* Use this "diff" command */ |
| 186 | int ignoreEolWs /* Ignore whitespace changes at end of lines */ |
| 187 | ){ |
| 188 | Blob fname; |
| 189 | Blob content; |
| 190 | file_tree_name(g.argv[2], &fname, 1); |
| 191 | historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0); |
| 192 | diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs); |
| 193 | blob_reset(&content); |
| 194 | blob_reset(&fname); |
| 195 | } |
| 196 | |
| 197 | /* |
| @@ -295,22 +296,22 @@ | |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | ** Output the differences between two versions of a single file. |
| 299 | ** zFrom and zTo are the check-ins containing the two file versions. |
| 300 | ** The filename is contained in g.argv[2]. |
| 301 | */ |
| 302 | static void diff_one_two_versions( |
| 303 | const char *zFrom, |
| 304 | const char *zTo, |
| 305 | const char *zDiffCmd, |
| 306 | int ignoreEolWs |
| 307 | ){ |
| 308 | char *zName; |
| 309 | Blob fname; |
| 310 | Blob v1, v2; |
| 311 | file_tree_name(g.argv[2], &fname, 1); |
| 312 | zName = blob_str(&fname); |
| 313 | historical_version_of_file(zFrom, zName, &v1, 0, 0); |
| 314 | historical_version_of_file(zTo, zName, &v2, 0, 0); |
| 315 | diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs); |
| 316 | blob_reset(&v1); |
| @@ -408,16 +409,16 @@ | |
| 408 | |
| 409 | /* |
| 410 | ** COMMAND: diff |
| 411 | ** COMMAND: gdiff |
| 412 | ** |
| 413 | ** Usage: %fossil diff|gdiff ?options? ?FILE? |
| 414 | ** |
| 415 | ** Show the difference between the current version of FILE (as it |
| 416 | ** exists on disk) and that same file as it was checked out. Or |
| 417 | ** if the FILE argument is omitted, show the unsaved changed currently |
| 418 | ** in the working check-out. |
| 419 | ** |
| 420 | ** If the "--from VERSION" or "-r VERSION" option is used it specifies |
| 421 | ** the source check-in for the diff operation. If not specified, the |
| 422 | ** source check-in is the base check-in for the current check-out. |
| 423 | ** |
| @@ -440,10 +441,11 @@ | |
| 440 | int hasNFlag; /* True if -N or --new-file flag is used */ |
| 441 | const char *zFrom; /* Source version number */ |
| 442 | const char *zTo; /* Target version number */ |
| 443 | const char *zDiffCmd = 0; /* External diff command. NULL for internal diff */ |
| 444 | int diffFlags = 0; /* Flags to control the DIFF */ |
| 445 | |
| 446 | isGDiff = g.argv[1][0]=='g'; |
| 447 | isInternDiff = find_option("internal","i",0)!=0; |
| 448 | zFrom = find_option("from", "r", 1); |
| 449 | zTo = find_option("to", 0, 1); |
| @@ -455,12 +457,14 @@ | |
| 455 | db_must_be_within_tree(); |
| 456 | verify_all_options(); |
| 457 | if( !isInternDiff ){ |
| 458 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 459 | } |
| 460 | if( g.argc==3 ){ |
| 461 | diff_one_against_disk(zFrom, zDiffCmd, 0); |
| 462 | }else{ |
| 463 | diff_all_against_disk(zFrom, zDiffCmd, diffFlags); |
| 464 | } |
| 465 | }else if( zFrom==0 ){ |
| 466 | fossil_fatal("must use --from if --to is present"); |
| @@ -468,12 +472,14 @@ | |
| 468 | db_find_and_open_repository(0, 0); |
| 469 | verify_all_options(); |
| 470 | if( !isInternDiff ){ |
| 471 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 472 | } |
| 473 | if( g.argc==3 ){ |
| 474 | diff_one_two_versions(zFrom, zTo, zDiffCmd, 0); |
| 475 | }else{ |
| 476 | diff_all_two_versions(zFrom, zTo, zDiffCmd, diffFlags); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -175,23 +175,24 @@ | |
| 175 | blob_reset(&cmd); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | ** Do a diff against a single file named in zFileTreeName from version zFrom |
| 181 | ** against the same file on disk. |
| 182 | */ |
| 183 | static void diff_one_against_disk( |
| 184 | const char *zFrom, /* Name of file */ |
| 185 | const char *zDiffCmd, /* Use this "diff" command */ |
| 186 | int ignoreEolWs, /* Ignore whitespace changes at end of lines */ |
| 187 | const char *zFileTreeName |
| 188 | ){ |
| 189 | Blob fname; |
| 190 | Blob content; |
| 191 | file_tree_name(zFileTreeName, &fname, 1); |
| 192 | historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0); |
| 193 | diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs); |
| 194 | blob_reset(&content); |
| 195 | blob_reset(&fname); |
| 196 | } |
| 197 | |
| 198 | /* |
| @@ -295,22 +296,22 @@ | |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | ** Output the differences between two versions of a single file. |
| 300 | ** zFrom and zTo are the check-ins containing the two file versions. |
| 301 | */ |
| 302 | static void diff_one_two_versions( |
| 303 | const char *zFrom, |
| 304 | const char *zTo, |
| 305 | const char *zDiffCmd, |
| 306 | int ignoreEolWs, |
| 307 | const char *zFileTreeName |
| 308 | ){ |
| 309 | char *zName; |
| 310 | Blob fname; |
| 311 | Blob v1, v2; |
| 312 | file_tree_name(zFileTreeName, &fname, 1); |
| 313 | zName = blob_str(&fname); |
| 314 | historical_version_of_file(zFrom, zName, &v1, 0, 0); |
| 315 | historical_version_of_file(zTo, zName, &v2, 0, 0); |
| 316 | diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs); |
| 317 | blob_reset(&v1); |
| @@ -408,16 +409,16 @@ | |
| 409 | |
| 410 | /* |
| 411 | ** COMMAND: diff |
| 412 | ** COMMAND: gdiff |
| 413 | ** |
| 414 | ** Usage: %fossil diff|gdiff ?options? ?FILE1? ?FILE2 ...? |
| 415 | ** |
| 416 | ** Show the difference between the current version of each of the FILEs |
| 417 | ** specified (as they exist on disk) and that same file as it was checked |
| 418 | ** out. Or if the FILE arguments are omitted, show the unsaved changed |
| 419 | ** currently in the working check-out. |
| 420 | ** |
| 421 | ** If the "--from VERSION" or "-r VERSION" option is used it specifies |
| 422 | ** the source check-in for the diff operation. If not specified, the |
| 423 | ** source check-in is the base check-in for the current check-out. |
| 424 | ** |
| @@ -440,10 +441,11 @@ | |
| 441 | int hasNFlag; /* True if -N or --new-file flag is used */ |
| 442 | const char *zFrom; /* Source version number */ |
| 443 | const char *zTo; /* Target version number */ |
| 444 | const char *zDiffCmd = 0; /* External diff command. NULL for internal diff */ |
| 445 | int diffFlags = 0; /* Flags to control the DIFF */ |
| 446 | int f; |
| 447 | |
| 448 | isGDiff = g.argv[1][0]=='g'; |
| 449 | isInternDiff = find_option("internal","i",0)!=0; |
| 450 | zFrom = find_option("from", "r", 1); |
| 451 | zTo = find_option("to", 0, 1); |
| @@ -455,12 +457,14 @@ | |
| 457 | db_must_be_within_tree(); |
| 458 | verify_all_options(); |
| 459 | if( !isInternDiff ){ |
| 460 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 461 | } |
| 462 | if( g.argc>=3 ){ |
| 463 | for(f=2; f<g.argc; ++f){ |
| 464 | diff_one_against_disk(zFrom, zDiffCmd, 0, g.argv[f]); |
| 465 | } |
| 466 | }else{ |
| 467 | diff_all_against_disk(zFrom, zDiffCmd, diffFlags); |
| 468 | } |
| 469 | }else if( zFrom==0 ){ |
| 470 | fossil_fatal("must use --from if --to is present"); |
| @@ -468,12 +472,14 @@ | |
| 472 | db_find_and_open_repository(0, 0); |
| 473 | verify_all_options(); |
| 474 | if( !isInternDiff ){ |
| 475 | zDiffCmd = db_get(isGDiff ? "gdiff-command" : "diff-command", 0); |
| 476 | } |
| 477 | if( g.argc>=3 ){ |
| 478 | for(f=2; f<g.argc; ++f){ |
| 479 | diff_one_two_versions(zFrom, zTo, zDiffCmd, 0, g.argv[f]); |
| 480 | } |
| 481 | }else{ |
| 482 | diff_all_two_versions(zFrom, zTo, zDiffCmd, diffFlags); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 |