Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add the "stash show" command. Simplifications to the diff code, and especially the looks_like_binary() function. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
4e0e69f691d5c4cd0fb969e4becfb27a |
| User & Date: | drh 2012-10-05 20:39:19.969 |
Context
|
2012-10-07
| ||
| 10:12 | Add 'tcl-setup' setting for the optional Tcl script to evaluate after creating and initializing the Tcl interpreter. Make sure Tcl gets a copy of all the original expanded arguments. check-in: fa4e828653 user: mistachkin tags: trunk | |
|
2012-10-05
| ||
| 20:39 | Add the "stash show" command. Simplifications to the diff code, and especially the looks_like_binary() function. check-in: 4e0e69f691 user: drh tags: trunk | |
| 16:36 | Fix a couple of C99-isms in the recent stash changes. check-in: f378800aed user: drh tags: trunk | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
170 171 172 173 174 175 176 | return a; } /* ** Returns non-zero if the specified content appears to be binary or ** contains a line that is too long. */ | | > > | | > | > > | > > > > > | < > > > | > | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
return a;
}
/*
** Returns non-zero if the specified content appears to be binary or
** contains a line that is too long.
*/
int looks_like_binary(Blob *pContent){
const char *z = blob_str(pContent);
int n = blob_size(pContent);
int i, j;
/* Count the number of lines. Allocate space to hold
** the returned array.
*/
for(i=j=0; i<n; i++, j++){
int c = z[i];
if( c==0 ) return 1; /* \000 byte in a file -> binary */
if( c=='\n' && z[i+1]!=0 ){
if( j>LENGTH_MASK ){
return 1; /* Very long line -> binary */
}
j = 0;
}
}
if( j>LENGTH_MASK ){
return 1; /* Very long line -> binary */
}
return 0; /* No problems seen -> not binary */
}
/*
** Return true if two DLine elements are identical.
*/
static int same_dline(DLine *pA, DLine *pB){
return pA->h==pB->h && memcmp(pA->z,pB->z,pA->h & LENGTH_MASK)==0;
|
| ︙ | ︙ |
Changes to src/diffcmd.c.
| ︙ | ︙ | |||
145 146 147 148 149 150 151 |
if( file_wd_size(zFile2)>=0 ){
if( file_wd_islink(zFile2) ){
blob_read_link(&file2, zFile2);
}else{
blob_read_from_file(&file2, zFile2);
}
}
| | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
if( file_wd_size(zFile2)>=0 ){
if( file_wd_islink(zFile2) ){
blob_read_link(&file2, zFile2);
}else{
blob_read_from_file(&file2, zFile2);
}
}
if( looks_like_binary(&file2) ){
fossil_print(DIFF_CANNOT_COMPUTE_BINARY);
blob_reset(&file2);
return;
}
blob_reset(&file2);
}
|
| ︙ | ︙ | |||
399 400 401 402 403 404 405 |
continue;
}
if( srcid>0 ){
content_get(srcid, &content);
}else{
blob_zero(&content);
}
| | < | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
continue;
}
if( srcid>0 ){
content_get(srcid, &content);
}else{
blob_zero(&content);
}
isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
diff_print_index(zPathname, diffFlags);
diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
zBinGlob, fIncludeBinary, diffFlags);
blob_reset(&content);
}
free(zToFree);
}
|
| ︙ | ︙ | |||
493 494 495 496 497 498 499 |
}
if( pTo ){
rid = uuid_to_rid(pTo->zUuid, 0);
content_get(rid, &f2);
}else{
blob_zero(&f2);
}
| | < | < | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
}
if( pTo ){
rid = uuid_to_rid(pTo->zUuid, 0);
content_get(rid, &f2);
}else{
blob_zero(&f2);
}
isBin1 = fIncludeBinary ? 0 : looks_like_binary(&f1);
isBin2 = fIncludeBinary ? 0 : looks_like_binary(&f2);
diff_file_mem(&f1, &f2, isBin1, isBin2, zName, zDiffCmd,
zBinGlob, fIncludeBinary, diffFlags);
blob_reset(&f1);
blob_reset(&f2);
}
/*
|
| ︙ | ︙ |
Changes to src/stash.c.
| ︙ | ︙ | |||
280 281 282 283 284 285 286 | } } /* ** Show the diffs associate with a single stash. */ static void stash_diff( | | | | > | | | | | < | < | > | | | | | > > > | < | < | < > | | | | > > | < | < | | | | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 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 365 366 367 368 |
}
}
/*
** Show the diffs associate with a single stash.
*/
static void stash_diff(
int stashid, /* The stash entry to diff */
const char *zDiffCmd, /* Command used for diffing */
const char *zBinGlob, /* GLOB pattern to determine binary files */
int fBaseline, /* Diff against original baseline check-in if true */
int fIncludeBinary, /* Do diffs against binary files */
u64 diffFlags /* Other diff flags */
){
Stmt q;
Blob empty;
blob_zero(&empty);
db_prepare(&q,
"SELECT rid, isRemoved, isExec, isLink, 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);
int isLink = db_column_int(&q, 3);
int isBin1, isBin2;
const char *zOrig = db_column_text(&q, 4);
const char *zNew = db_column_text(&q, 5);
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
Blob delta, a, b, disk;
if( rid==0 ){
db_ephemeral_blob(&q, 6, &a);
fossil_print("ADDED %s\n", zNew);
diff_print_index(zNew, diffFlags);
isBin1 = 0;
isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
zBinGlob, fIncludeBinary, diffFlags);
}else if( isRemoved ){
fossil_print("DELETE %s\n", zOrig);
if( fBaseline==0 ){
if( file_wd_islink(zOPath) ){
blob_read_link(&a, zOPath);
}else{
blob_read_from_file(&a, zOPath);
}
}else{
content_get(rid, &a);
}
diff_print_index(zNew, diffFlags);
isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
isBin2 = 0;
diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
zBinGlob, fIncludeBinary, diffFlags);
}else{
int isOrigLink = file_wd_islink(zOPath);
db_ephemeral_blob(&q, 6, &delta);
if( fBaseline==0 ){
if( isOrigLink ){
blob_read_link(&disk, zOPath);
}else{
blob_read_from_file(&disk, zOPath);
}
}
fossil_print("CHANGED %s\n", zNew);
if( !isOrigLink != !isLink ){
diff_print_index(zNew, diffFlags);
diff_print_filenames(zOrig, zNew, diffFlags);
printf(DIFF_CANNOT_COMPUTE_SYMLINK);
}else{
Blob *pBase = fBaseline ? &a : &disk;
content_get(rid, &a);
blob_delta_apply(&a, &delta, &b);
isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase);
isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b);
diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew,
zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
blob_reset(&a);
blob_reset(&b);
}
if( !fBaseline ) blob_reset(&disk);
}
blob_reset(&delta);
}
db_finalize(&q);
}
/*
|
| ︙ | ︙ | |||
413 414 415 416 417 418 419 420 421 422 423 424 425 426 | ** ** fossil stash list ?--detail? ** fossil stash ls ?-l? ** ** List all changes sets currently stashed. Show information about ** individual files in each changeset if --detail or -l is used. ** ** fossil stash pop ** fossil stash apply ?STASHID? ** ** Apply STASHID or the most recently create stash to the current ** working check-out. The "pop" command deletes that changeset from ** the stash after applying it but the "apply" command retains the ** changeset. | > > > > | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | ** ** fossil stash list ?--detail? ** fossil stash ls ?-l? ** ** List all changes sets currently stashed. Show information about ** individual files in each changeset if --detail or -l is used. ** ** fossil stash show ?STASHID? ?DIFF-FLAGS? ** ** Show the content of a stash ** ** fossil stash pop ** fossil stash apply ?STASHID? ** ** Apply STASHID or the most recently create stash to the current ** working check-out. The "pop" command deletes that changeset from ** the stash after applying it but the "apply" command retains the ** changeset. |
| ︙ | ︙ | |||
444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
** directory would be if STASHID were applied.
**
** SUMMARY:
** fossil stash
** fossil stash save ?-m COMMENT? ?FILES...?
** fossil stash snapshot ?-m COMMENT? ?FILES...?
** fossil stash list|ls ?-l? ?--detail?
** fossil stash pop
** fossil stash apply ?STASHID?
** fossil stash goto ?STASHID?
** fossil stash rm|drop ?STASHID? ?--all?
** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
*/
void stash_cmd(void){
| > | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
** directory would be if STASHID were applied.
**
** SUMMARY:
** fossil stash
** fossil stash save ?-m COMMENT? ?FILES...?
** fossil stash snapshot ?-m COMMENT? ?FILES...?
** fossil stash list|ls ?-l? ?--detail?
** fossil stash show ?STASHID? ?DIFF-OPTIONS?
** fossil stash pop
** fossil stash apply ?STASHID?
** fossil stash goto ?STASHID?
** fossil stash rm|drop ?STASHID? ?--all?
** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
*/
void stash_cmd(void){
|
| ︙ | ︙ | |||
594 595 596 597 598 599 600 |
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
| | > > > | | | < < < < < | < < < < < < < < < < < < | 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
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
|| memcmp(zCmd, "gdiff", nCmd)==0
|| memcmp(zCmd, "show", nCmd)==0
){
const char *zDiffCmd = 0;
const char *zBinGlob = 0;
int fIncludeBinary = 0;
u64 diffFlags;
if( find_option("tk",0,0)!=0 ){
db_close(0);
diff_tk((zCmd[0]=='s' ? "stash show" : "stash diff"), 3);
return;
}
if( find_option("internal","i",0)==0 ){
zDiffCmd = diff_command_external(0);
}
diffFlags = diff_options();
if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd));
if( zDiffCmd ){
zBinGlob = diff_get_binary_glob();
fIncludeBinary = diff_include_binary_files();
}
stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary,
diffFlags);
}else
if( memcmp(zCmd, "help", nCmd)==0 ){
g.argv[1] = "help";
g.argv[2] = "stash";
g.argc = 3;
help_cmd();
}else
{
usage("SUBCOMMAND ARGS...");
}
db_end_transaction(0);
}
|
Changes to src/update.c.
| ︙ | ︙ | |||
623 624 625 626 627 628 629 |
int rc;
rid = uuid_to_rid(pFile->zUuid, 0);
if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
manifest_destroy(pManifest);
rc = content_get(rid, content);
if( rc && pIsBin ){
| | | 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
int rc;
rid = uuid_to_rid(pFile->zUuid, 0);
if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
manifest_destroy(pManifest);
rc = content_get(rid, content);
if( rc && pIsBin ){
*pIsBin = looks_like_binary(content);
}
return rc;
}
manifest_destroy(pManifest);
if( errCode<=0 ){
fossil_fatal("file %s does not exist in checkin: %s", file, revision);
}
|
| ︙ | ︙ |