Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add the "stash diff" and "stash gdiff" commands. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | experimental |
Files: | files | file ages | folders |
SHA1: |
987e0ff78da1fe80776fe49556377b05 |
User & Date: | drh 2010-12-18 21:22:10.000 |
Context
2010-12-18
| ||
21:26 | Bring the "stash" enhancement into the trunk. ... (check-in: 12a2a5ea user: drh tags: trunk) | |
21:22 | Add the "stash diff" and "stash gdiff" commands. ... (Closed-Leaf check-in: 987e0ff7 user: drh tags: experimental) | |
20:54 | Fix a couple of out-of-order variable declarations. ... (check-in: 4a8b4210 user: drh tags: experimental) | |
Changes
Changes to src/diffcmd.c.
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <assert.h> /* ** Diff option flags */ #define DIFF_NEWFILE 0x01 /* Treat non-existing fails as empty files */ #define DIFF_NOEOLWS 0x02 /* Ignore whitespace at the end of lines */ /* ** Show the difference between two files, one in memory and one on disk. ** ** The difference is the set of edits needed to transform pFile1 into ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. ** ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the ** command zDiffCmd to do the diffing. */ | > > > > > > > > | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <assert.h> /* ** Diff option flags */ #define DIFF_NEWFILE 0x01 /* Treat non-existing fails as empty files */ #define DIFF_NOEOLWS 0x02 /* Ignore whitespace at the end of lines */ /* ** Print the "Index:" message that patch wants to see at the top of a diff. */ void diff_print_index(const char *zFile){ printf("Index: %s\n=======================================" "============================\n", zFile); } /* ** Show the difference between two files, one in memory and one on disk. ** ** The difference is the set of edits needed to transform pFile1 into ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. ** ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the ** command zDiffCmd to do the diffing. */ void diff_file( Blob *pFile1, /* In memory content to compare from */ const char *zFile2, /* On disk content to compare to */ const char *zName, /* Display name of the file */ const char *zDiffCmd, /* Command for comparison */ int ignoreEolWs /* Ignore whitespace at end of line */ ){ if( zDiffCmd==0 ){ |
︙ | ︙ | |||
102 103 104 105 106 107 108 | ** ** The difference is the set of edits needed to transform pFile1 into ** pFile2. ** ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the ** command zDiffCmd to do the diffing. */ | | | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | ** ** The difference is the set of edits needed to transform pFile1 into ** pFile2. ** ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the ** command zDiffCmd to do the diffing. */ void diff_file_mem( Blob *pFile1, /* In memory content to compare from */ Blob *pFile2, /* In memory content to compare to */ const char *zName, /* Display name of the file */ const char *zDiffCmd, /* Command for comparison */ int ignoreEolWs /* Ignore whitespace at end of lines */ ){ if( zDiffCmd==0 ){ |
︙ | ︙ | |||
255 256 257 258 259 260 261 | if( showDiff ){ Blob content; if( srcid>0 ){ content_get(srcid, &content); }else{ blob_zero(&content); } | < < | < | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | if( showDiff ){ Blob content; if( srcid>0 ){ content_get(srcid, &content); }else{ blob_zero(&content); } diff_print_index(zPathname); diff_file(&content, zFullName, zPathname, zDiffCmd, ignoreEolWs); blob_reset(&content); } free(zToFree); } db_finalize(&q); db_end_transaction(1); /* ROLLBACK */ |
︙ | ︙ | |||
305 306 307 308 309 310 311 | struct ManifestFile *pTo, const char *zDiffCmd, int ignoreEolWs ){ Blob f1, f2; int rid; const char *zName = pFrom ? pFrom->zName : pTo->zName; | < | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | struct ManifestFile *pTo, const char *zDiffCmd, int ignoreEolWs ){ Blob f1, f2; int rid; const char *zName = pFrom ? pFrom->zName : pTo->zName; diff_print_index(zName); if( pFrom ){ rid = uuid_to_rid(pFrom->zUuid, 0); content_get(rid, &f1); }else{ blob_zero(&f1); } if( pTo ){ |
︙ | ︙ |
Changes to src/stash.c.
︙ | ︙ | |||
178 179 180 181 182 183 184 185 186 187 188 189 190 191 | int isRemoved = db_column_int(&q, 1); const char *zOrig = db_column_text(&q, 3); const char *zNew = db_column_text(&q, 4); char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew); Blob delta; undo_save(zNew); if( rid==0 ){ db_ephemeral_blob(&q, 5, &delta); blob_write_to_file(&delta, zNPath); printf("ADD %s\n", zNew); }else if( isRemoved ){ printf("DELETE %s\n", zOrig); unlink(zOPath); | > | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | int isRemoved = db_column_int(&q, 1); const char *zOrig = db_column_text(&q, 3); const char *zNew = db_column_text(&q, 4); char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew); Blob delta; undo_save(zNew); blob_zero(&delta); if( rid==0 ){ db_ephemeral_blob(&q, 5, &delta); blob_write_to_file(&delta, zNPath); printf("ADD %s\n", zNew); }else if( isRemoved ){ printf("DELETE %s\n", zOrig); unlink(zOPath); |
︙ | ︙ | |||
207 208 209 210 211 212 213 | }else{ printf("MERGE %s\n", zNew); } blob_reset(&out); } blob_reset(&a); blob_reset(&b); | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | }else{ printf("MERGE %s\n", zNew); } blob_reset(&out); } blob_reset(&a); blob_reset(&b); blob_reset(&disk); } blob_reset(&delta); if( strcmp(zOrig,zNew)!=0 ){ undo_save(zOrig); unlink(zOPath); } } db_finalize(&q); if( nConflict ){ printf("WARNING: merge conflicts - see messages above for details.\n"); } } /* ** Show the diffs associate with a single stash. */ static void stash_diff(int stashid, const char *zDiffCmd){ Stmt q; Blob empty; blob_zero(&empty); db_prepare(&q, "SELECT rid, isRemoved, isExec, origname, newname, delta" " FROM stashfile WHERE stashid=%d", stashid ); while( db_step(&q)==SQLITE_ROW ){ int rid = db_column_int(&q, 0); int isRemoved = db_column_int(&q, 1); const char *zOrig = db_column_text(&q, 3); const char *zNew = db_column_text(&q, 4); char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig); Blob delta; if( rid==0 ){ db_ephemeral_blob(&q, 5, &delta); printf("ADDED %s\n", zNew); diff_print_index(zNew); diff_file_mem(&empty, &delta, zNew, zDiffCmd, 0); }else if( isRemoved ){ printf("DELETE %s\n", zOrig); blob_read_from_file(&delta, zOPath); diff_print_index(zNew); diff_file_mem(&delta, &empty, zOrig, zDiffCmd, 0); }else{ Blob a, b, disk; db_ephemeral_blob(&q, 5, &delta); blob_read_from_file(&disk, zOPath); content_get(rid, &a); blob_delta_apply(&a, &delta, &b); printf("CHANGED %s\n", zNew); diff_file_mem(&disk, &b, zNew, zDiffCmd, 0); blob_reset(&a); blob_reset(&b); blob_reset(&disk); } blob_reset(&delta); } db_finalize(&q); } /* ** Drop the indicates stash */ static void stash_drop(int stashid){ db_multi_exec( "DELETE FROM stash WHERE stashid=%d;" |
︙ | ︙ | |||
254 255 256 257 258 259 260 | } return stashid; } /* ** COMMAND: stash ** | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | } return stashid; } /* ** COMMAND: stash ** ** Usage: %fossil stash SUBCOMMAND ARGS... ** ** fossil stash ** fossil stash save ?-m COMMENT? ?FILES...? ** ** Save the current changes in the working tree as a new stash. ** Then revert the changes back to the last check-in. If FILES ** are listed, then only stash and revert the named files. The ** "save" verb can be omitted if and only if there are no other ** arguments. ** ** fossil stash list ** ** List all changes sets currently stashed. ** ** fossil stash pop ** ** Apply the most recently create stash to the current working ** check-out. Then delete that stash. This is equivalent to ** doing an "apply" and a "drop" against the most recent stash. ** This command is undoable. ** ** fossil stash apply ?STASHID? ** ** Apply the identified stash to the current working check-out. ** If no STASHID is specifed, use the most recent stash. Unlike ** the "pop" command, the stash is retained so that it can be used ** again. This command is undoable. ** ** fossil stash goto ?STASHID? ** ** Update to the baseline checkout for STASHID then apply the ** changes of STASHID. Keep STASHID so that it can be reused ** This command is undoable. ** ** fossil drop ?STASHID? ** ** Forget everything about STASHID. This command is undoable. ** ** fossil stash snapshot ?-m COMMENT? ?FILES...? ** ** Save the current changes in the working tress as a new stash ** but, unlike "save", do not revert those changes. ** ** fossil stash diff ?STASHID? ** fossil stash gdiff ?STASHID? ** ** Show diffs of the current working directory and what that ** directory would be if STASHID were applied. */ void stash_cmd(void){ const char *zDb; const char *zCmd; int nCmd; int stashid; |
︙ | ︙ | |||
389 390 391 392 393 394 395 396 | nConflict = update_to(vid); stash_apply(stashid, nConflict); db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN " "(SELECT origname FROM stashfile WHERE stashid=%d)", stashid); undo_finish(); }else { | > > > > > > > > > > > > | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | nConflict = update_to(vid); stash_apply(stashid, nConflict); db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN " "(SELECT origname FROM stashfile WHERE stashid=%d)", stashid); undo_finish(); }else if( memcmp(zCmd, "diff", nCmd)==0 ){ const char *zDiffCmd = db_get("diff-command", 0); if( g.argc>4 ) usage("stash diff STASHID"); stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); stash_diff(stashid, zDiffCmd); }else if( memcmp(zCmd, "gdiff", nCmd)==0 ){ const char *zDiffCmd = db_get("gdiff-command", 0); if( g.argc>4 ) usage("stash diff STASHID"); stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0); stash_diff(stashid, zDiffCmd); }else { usage("SUBCOMMAND ARGS..."); } db_end_transaction(0); } |