Fossil SCM

Add the "stash show" command. Simplifications to the diff code, and especially the looks_like_binary() function.

drh 2012-10-05 20:39 trunk
Commit 4e0e69f691d5c4cd0fb969e4becfb27a68beba07
+22 -9
--- src/diff.c
+++ src/diff.c
@@ -172,19 +172,32 @@
172172
173173
/*
174174
** Returns non-zero if the specified content appears to be binary or
175175
** contains a line that is too long.
176176
*/
177
-int looks_like_binary(const char *z, int n){
178
- int nLine;
179
- DLine *aContent = break_into_lines(z, n, &nLine, 0);
180
- if( aContent ){
181
- fossil_free(aContent);
182
- return 0;
183
- }else{
184
- return 1;
185
- }
177
+int looks_like_binary(Blob *pContent){
178
+ const char *z = blob_str(pContent);
179
+ int n = blob_size(pContent);
180
+ int i, j;
181
+
182
+ /* Count the number of lines. Allocate space to hold
183
+ ** the returned array.
184
+ */
185
+ for(i=j=0; i<n; i++, j++){
186
+ int c = z[i];
187
+ if( c==0 ) return 1; /* \000 byte in a file -> binary */
188
+ if( c=='\n' && z[i+1]!=0 ){
189
+ if( j>LENGTH_MASK ){
190
+ return 1; /* Very long line -> binary */
191
+ }
192
+ j = 0;
193
+ }
194
+ }
195
+ if( j>LENGTH_MASK ){
196
+ return 1; /* Very long line -> binary */
197
+ }
198
+ return 0; /* No problems seen -> not binary */
186199
}
187200
188201
/*
189202
** Return true if two DLine elements are identical.
190203
*/
191204
--- src/diff.c
+++ src/diff.c
@@ -172,19 +172,32 @@
172
173 /*
174 ** Returns non-zero if the specified content appears to be binary or
175 ** contains a line that is too long.
176 */
177 int looks_like_binary(const char *z, int n){
178 int nLine;
179 DLine *aContent = break_into_lines(z, n, &nLine, 0);
180 if( aContent ){
181 fossil_free(aContent);
182 return 0;
183 }else{
184 return 1;
185 }
 
 
 
 
 
 
 
 
 
 
 
 
 
186 }
187
188 /*
189 ** Return true if two DLine elements are identical.
190 */
191
--- src/diff.c
+++ src/diff.c
@@ -172,19 +172,32 @@
172
173 /*
174 ** Returns non-zero if the specified content appears to be binary or
175 ** contains a line that is too long.
176 */
177 int looks_like_binary(Blob *pContent){
178 const char *z = blob_str(pContent);
179 int n = blob_size(pContent);
180 int i, j;
181
182 /* Count the number of lines. Allocate space to hold
183 ** the returned array.
184 */
185 for(i=j=0; i<n; i++, j++){
186 int c = z[i];
187 if( c==0 ) return 1; /* \000 byte in a file -> binary */
188 if( c=='\n' && z[i+1]!=0 ){
189 if( j>LENGTH_MASK ){
190 return 1; /* Very long line -> binary */
191 }
192 j = 0;
193 }
194 }
195 if( j>LENGTH_MASK ){
196 return 1; /* Very long line -> binary */
197 }
198 return 0; /* No problems seen -> not binary */
199 }
200
201 /*
202 ** Return true if two DLine elements are identical.
203 */
204
+4 -7
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -147,11 +147,11 @@
147147
blob_read_link(&file2, zFile2);
148148
}else{
149149
blob_read_from_file(&file2, zFile2);
150150
}
151151
}
152
- if( looks_like_binary(blob_str(&file2), blob_size(&file2)) ){
152
+ if( looks_like_binary(&file2) ){
153153
fossil_print(DIFF_CANNOT_COMPUTE_BINARY);
154154
blob_reset(&file2);
155155
return;
156156
}
157157
blob_reset(&file2);
@@ -401,12 +401,11 @@
401401
if( srcid>0 ){
402402
content_get(srcid, &content);
403403
}else{
404404
blob_zero(&content);
405405
}
406
- isBin = fIncludeBinary ? 0 : looks_like_binary(blob_str(&content),
407
- blob_size(&content));
406
+ isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
408407
diff_print_index(zPathname, diffFlags);
409408
diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
410409
zBinGlob, fIncludeBinary, diffFlags);
411410
blob_reset(&content);
412411
}
@@ -495,14 +494,12 @@
495494
rid = uuid_to_rid(pTo->zUuid, 0);
496495
content_get(rid, &f2);
497496
}else{
498497
blob_zero(&f2);
499498
}
500
- isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&f1),
501
- blob_size(&f1));
502
- isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&f2),
503
- blob_size(&f2));
499
+ isBin1 = fIncludeBinary ? 0 : looks_like_binary(&f1);
500
+ isBin2 = fIncludeBinary ? 0 : looks_like_binary(&f2);
504501
diff_file_mem(&f1, &f2, isBin1, isBin2, zName, zDiffCmd,
505502
zBinGlob, fIncludeBinary, diffFlags);
506503
blob_reset(&f1);
507504
blob_reset(&f2);
508505
}
509506
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -147,11 +147,11 @@
147 blob_read_link(&file2, zFile2);
148 }else{
149 blob_read_from_file(&file2, zFile2);
150 }
151 }
152 if( looks_like_binary(blob_str(&file2), blob_size(&file2)) ){
153 fossil_print(DIFF_CANNOT_COMPUTE_BINARY);
154 blob_reset(&file2);
155 return;
156 }
157 blob_reset(&file2);
@@ -401,12 +401,11 @@
401 if( srcid>0 ){
402 content_get(srcid, &content);
403 }else{
404 blob_zero(&content);
405 }
406 isBin = fIncludeBinary ? 0 : looks_like_binary(blob_str(&content),
407 blob_size(&content));
408 diff_print_index(zPathname, diffFlags);
409 diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
410 zBinGlob, fIncludeBinary, diffFlags);
411 blob_reset(&content);
412 }
@@ -495,14 +494,12 @@
495 rid = uuid_to_rid(pTo->zUuid, 0);
496 content_get(rid, &f2);
497 }else{
498 blob_zero(&f2);
499 }
500 isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&f1),
501 blob_size(&f1));
502 isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&f2),
503 blob_size(&f2));
504 diff_file_mem(&f1, &f2, isBin1, isBin2, zName, zDiffCmd,
505 zBinGlob, fIncludeBinary, diffFlags);
506 blob_reset(&f1);
507 blob_reset(&f2);
508 }
509
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -147,11 +147,11 @@
147 blob_read_link(&file2, zFile2);
148 }else{
149 blob_read_from_file(&file2, zFile2);
150 }
151 }
152 if( looks_like_binary(&file2) ){
153 fossil_print(DIFF_CANNOT_COMPUTE_BINARY);
154 blob_reset(&file2);
155 return;
156 }
157 blob_reset(&file2);
@@ -401,12 +401,11 @@
401 if( srcid>0 ){
402 content_get(srcid, &content);
403 }else{
404 blob_zero(&content);
405 }
406 isBin = fIncludeBinary ? 0 : looks_like_binary(&content);
 
407 diff_print_index(zPathname, diffFlags);
408 diff_file(&content, isBin, zFullName, zPathname, zDiffCmd,
409 zBinGlob, fIncludeBinary, diffFlags);
410 blob_reset(&content);
411 }
@@ -495,14 +494,12 @@
494 rid = uuid_to_rid(pTo->zUuid, 0);
495 content_get(rid, &f2);
496 }else{
497 blob_zero(&f2);
498 }
499 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&f1);
500 isBin2 = fIncludeBinary ? 0 : looks_like_binary(&f2);
 
 
501 diff_file_mem(&f1, &f2, isBin1, isBin2, zName, zDiffCmd,
502 zBinGlob, fIncludeBinary, diffFlags);
503 blob_reset(&f1);
504 blob_reset(&f2);
505 }
506
+46 -54
--- src/stash.c
+++ src/stash.c
@@ -282,15 +282,16 @@
282282
283283
/*
284284
** Show the diffs associate with a single stash.
285285
*/
286286
static void stash_diff(
287
- int stashid,
288
- const char *zDiffCmd,
289
- const char *zBinGlob,
290
- int fIncludeBinary,
291
- u64 diffFlags
287
+ int stashid, /* The stash entry to diff */
288
+ const char *zDiffCmd, /* Command used for diffing */
289
+ const char *zBinGlob, /* GLOB pattern to determine binary files */
290
+ int fBaseline, /* Diff against original baseline check-in if true */
291
+ int fIncludeBinary, /* Do diffs against binary files */
292
+ u64 diffFlags /* Other diff flags */
292293
){
293294
Stmt q;
294295
Blob empty;
295296
blob_zero(&empty);
296297
db_prepare(&q,
@@ -304,62 +305,62 @@
304305
int isLink = db_column_int(&q, 3);
305306
int isBin1, isBin2;
306307
const char *zOrig = db_column_text(&q, 4);
307308
const char *zNew = db_column_text(&q, 5);
308309
char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
309
- Blob delta;
310
+ Blob delta, a, b, disk;
310311
if( rid==0 ){
311
- db_ephemeral_blob(&q, 6, &delta);
312
+ db_ephemeral_blob(&q, 6, &a);
312313
fossil_print("ADDED %s\n", zNew);
313314
diff_print_index(zNew, diffFlags);
314
- isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty),
315
- blob_size(&empty));
316
- isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta),
317
- blob_size(&delta));
318
- diff_file_mem(&empty, &delta, isBin1, isBin2, zNew, zDiffCmd,
315
+ isBin1 = 0;
316
+ isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
317
+ diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
319318
zBinGlob, fIncludeBinary, diffFlags);
320319
}else if( isRemoved ){
321320
fossil_print("DELETE %s\n", zOrig);
322
- if( file_wd_islink(zOPath) ){
323
- blob_read_link(&delta, zOPath);
321
+ if( fBaseline==0 ){
322
+ if( file_wd_islink(zOPath) ){
323
+ blob_read_link(&a, zOPath);
324
+ }else{
325
+ blob_read_from_file(&a, zOPath);
326
+ }
324327
}else{
325
- blob_read_from_file(&delta, zOPath);
328
+ content_get(rid, &a);
326329
}
327330
diff_print_index(zNew, diffFlags);
328
- isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta),
329
- blob_size(&delta));
330
- isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty),
331
- blob_size(&empty));
332
- diff_file_mem(&delta, &empty, isBin1, isBin2, zOrig, zDiffCmd,
331
+ isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
332
+ isBin2 = 0;
333
+ diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
333334
zBinGlob, fIncludeBinary, diffFlags);
334335
}else{
335
- Blob a, b, disk;
336336
int isOrigLink = file_wd_islink(zOPath);
337337
db_ephemeral_blob(&q, 6, &delta);
338
- if( isOrigLink ){
339
- blob_read_link(&disk, zOPath);
340
- }else{
341
- blob_read_from_file(&disk, zOPath);
338
+ if( fBaseline==0 ){
339
+ if( isOrigLink ){
340
+ blob_read_link(&disk, zOPath);
341
+ }else{
342
+ blob_read_from_file(&disk, zOPath);
343
+ }
342344
}
343345
fossil_print("CHANGED %s\n", zNew);
344346
if( !isOrigLink != !isLink ){
345347
diff_print_index(zNew, diffFlags);
346348
diff_print_filenames(zOrig, zNew, diffFlags);
347349
printf(DIFF_CANNOT_COMPUTE_SYMLINK);
348350
}else{
351
+ Blob *pBase = fBaseline ? &a : &disk;
349352
content_get(rid, &a);
350353
blob_delta_apply(&a, &delta, &b);
351
- isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&disk),
352
- blob_size(&disk));
353
- isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&b),
354
- blob_size(&b));
355
- diff_file_mem(&disk, &b, isBin1, isBin2, zNew, zDiffCmd,
356
- zBinGlob, fIncludeBinary, diffFlags);
354
+ isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase);
355
+ isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b);
356
+ diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew,
357
+ zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
357358
blob_reset(&a);
358359
blob_reset(&b);
359360
}
360
- blob_reset(&disk);
361
+ if( !fBaseline ) blob_reset(&disk);
361362
}
362363
blob_reset(&delta);
363364
}
364365
db_finalize(&q);
365366
}
@@ -415,10 +416,14 @@
415416
** fossil stash ls ?-l?
416417
**
417418
** List all changes sets currently stashed. Show information about
418419
** individual files in each changeset if --detail or -l is used.
419420
**
421
+** fossil stash show ?STASHID? ?DIFF-FLAGS?
422
+**
423
+** Show the content of a stash
424
+**
420425
** fossil stash pop
421426
** fossil stash apply ?STASHID?
422427
**
423428
** Apply STASHID or the most recently create stash to the current
424429
** working check-out. The "pop" command deletes that changeset from
@@ -446,10 +451,11 @@
446451
** SUMMARY:
447452
** fossil stash
448453
** fossil stash save ?-m COMMENT? ?FILES...?
449454
** fossil stash snapshot ?-m COMMENT? ?FILES...?
450455
** fossil stash list|ls ?-l? ?--detail?
456
+** fossil stash show ?STASHID? ?DIFF-OPTIONS?
451457
** fossil stash pop
452458
** fossil stash apply ?STASHID?
453459
** fossil stash goto ?STASHID?
454460
** fossil stash rm|drop ?STASHID? ?--all?
455461
** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
@@ -596,50 +602,36 @@
596602
db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN "
597603
"(SELECT origname FROM stashfile WHERE stashid=%d)",
598604
stashid);
599605
undo_finish();
600606
}else
601
- if( memcmp(zCmd, "diff", nCmd)==0 ){
607
+ if( memcmp(zCmd, "diff", nCmd)==0
608
+ || memcmp(zCmd, "gdiff", nCmd)==0
609
+ || memcmp(zCmd, "show", nCmd)==0
610
+ ){
602611
const char *zDiffCmd = 0;
603612
const char *zBinGlob = 0;
604613
int fIncludeBinary = 0;
605614
u64 diffFlags;
606615
607616
if( find_option("tk",0,0)!=0 ){
608617
db_close(0);
609
- diff_tk("stash diff", 3);
618
+ diff_tk((zCmd[0]=='s' ? "stash show" : "stash diff"), 3);
610619
return;
611620
}
612621
if( find_option("internal","i",0)==0 ){
613622
zDiffCmd = diff_command_external(0);
614623
}
615624
diffFlags = diff_options();
616
- if( g.argc>4 ) usage("diff STASHID");
625
+ if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd));
617626
if( zDiffCmd ){
618627
zBinGlob = diff_get_binary_glob();
619628
fIncludeBinary = diff_include_binary_files();
620629
}
621630
stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
622
- stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
623
- }else
624
- if( memcmp(zCmd, "gdiff", nCmd)==0 ){
625
- const char *zDiffCmd = 0;
626
- const char *zBinGlob = 0;
627
- int fIncludeBinary = 0;
628
- u64 diffFlags;
629
-
630
- if( find_option("internal","i",0)==0 ){
631
- zDiffCmd = diff_command_external(0);
632
- }
633
- diffFlags = diff_options();
634
- if( g.argc>4 ) usage("gdiff STASHID");
635
- if( zDiffCmd ){
636
- zBinGlob = diff_get_binary_glob();
637
- fIncludeBinary = diff_include_binary_files();
638
- }
639
- stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
640
- stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
631
+ stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary,
632
+ diffFlags);
641633
}else
642634
if( memcmp(zCmd, "help", nCmd)==0 ){
643635
g.argv[1] = "help";
644636
g.argv[2] = "stash";
645637
g.argc = 3;
646638
--- src/stash.c
+++ src/stash.c
@@ -282,15 +282,16 @@
282
283 /*
284 ** Show the diffs associate with a single stash.
285 */
286 static void stash_diff(
287 int stashid,
288 const char *zDiffCmd,
289 const char *zBinGlob,
290 int fIncludeBinary,
291 u64 diffFlags
 
292 ){
293 Stmt q;
294 Blob empty;
295 blob_zero(&empty);
296 db_prepare(&q,
@@ -304,62 +305,62 @@
304 int isLink = db_column_int(&q, 3);
305 int isBin1, isBin2;
306 const char *zOrig = db_column_text(&q, 4);
307 const char *zNew = db_column_text(&q, 5);
308 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
309 Blob delta;
310 if( rid==0 ){
311 db_ephemeral_blob(&q, 6, &delta);
312 fossil_print("ADDED %s\n", zNew);
313 diff_print_index(zNew, diffFlags);
314 isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty),
315 blob_size(&empty));
316 isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta),
317 blob_size(&delta));
318 diff_file_mem(&empty, &delta, isBin1, isBin2, zNew, zDiffCmd,
319 zBinGlob, fIncludeBinary, diffFlags);
320 }else if( isRemoved ){
321 fossil_print("DELETE %s\n", zOrig);
322 if( file_wd_islink(zOPath) ){
323 blob_read_link(&delta, zOPath);
 
 
 
 
324 }else{
325 blob_read_from_file(&delta, zOPath);
326 }
327 diff_print_index(zNew, diffFlags);
328 isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&delta),
329 blob_size(&delta));
330 isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&empty),
331 blob_size(&empty));
332 diff_file_mem(&delta, &empty, isBin1, isBin2, zOrig, zDiffCmd,
333 zBinGlob, fIncludeBinary, diffFlags);
334 }else{
335 Blob a, b, disk;
336 int isOrigLink = file_wd_islink(zOPath);
337 db_ephemeral_blob(&q, 6, &delta);
338 if( isOrigLink ){
339 blob_read_link(&disk, zOPath);
340 }else{
341 blob_read_from_file(&disk, zOPath);
 
 
342 }
343 fossil_print("CHANGED %s\n", zNew);
344 if( !isOrigLink != !isLink ){
345 diff_print_index(zNew, diffFlags);
346 diff_print_filenames(zOrig, zNew, diffFlags);
347 printf(DIFF_CANNOT_COMPUTE_SYMLINK);
348 }else{
 
349 content_get(rid, &a);
350 blob_delta_apply(&a, &delta, &b);
351 isBin1 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&disk),
352 blob_size(&disk));
353 isBin2 = fIncludeBinary ? 0 : looks_like_binary(blob_str(&b),
354 blob_size(&b));
355 diff_file_mem(&disk, &b, isBin1, isBin2, zNew, zDiffCmd,
356 zBinGlob, fIncludeBinary, diffFlags);
357 blob_reset(&a);
358 blob_reset(&b);
359 }
360 blob_reset(&disk);
361 }
362 blob_reset(&delta);
363 }
364 db_finalize(&q);
365 }
@@ -415,10 +416,14 @@
415 ** fossil stash ls ?-l?
416 **
417 ** List all changes sets currently stashed. Show information about
418 ** individual files in each changeset if --detail or -l is used.
419 **
 
 
 
 
420 ** fossil stash pop
421 ** fossil stash apply ?STASHID?
422 **
423 ** Apply STASHID or the most recently create stash to the current
424 ** working check-out. The "pop" command deletes that changeset from
@@ -446,10 +451,11 @@
446 ** SUMMARY:
447 ** fossil stash
448 ** fossil stash save ?-m COMMENT? ?FILES...?
449 ** fossil stash snapshot ?-m COMMENT? ?FILES...?
450 ** fossil stash list|ls ?-l? ?--detail?
 
451 ** fossil stash pop
452 ** fossil stash apply ?STASHID?
453 ** fossil stash goto ?STASHID?
454 ** fossil stash rm|drop ?STASHID? ?--all?
455 ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
@@ -596,50 +602,36 @@
596 db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN "
597 "(SELECT origname FROM stashfile WHERE stashid=%d)",
598 stashid);
599 undo_finish();
600 }else
601 if( memcmp(zCmd, "diff", nCmd)==0 ){
 
 
 
602 const char *zDiffCmd = 0;
603 const char *zBinGlob = 0;
604 int fIncludeBinary = 0;
605 u64 diffFlags;
606
607 if( find_option("tk",0,0)!=0 ){
608 db_close(0);
609 diff_tk("stash diff", 3);
610 return;
611 }
612 if( find_option("internal","i",0)==0 ){
613 zDiffCmd = diff_command_external(0);
614 }
615 diffFlags = diff_options();
616 if( g.argc>4 ) usage("diff STASHID");
617 if( zDiffCmd ){
618 zBinGlob = diff_get_binary_glob();
619 fIncludeBinary = diff_include_binary_files();
620 }
621 stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
622 stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
623 }else
624 if( memcmp(zCmd, "gdiff", nCmd)==0 ){
625 const char *zDiffCmd = 0;
626 const char *zBinGlob = 0;
627 int fIncludeBinary = 0;
628 u64 diffFlags;
629
630 if( find_option("internal","i",0)==0 ){
631 zDiffCmd = diff_command_external(0);
632 }
633 diffFlags = diff_options();
634 if( g.argc>4 ) usage("gdiff STASHID");
635 if( zDiffCmd ){
636 zBinGlob = diff_get_binary_glob();
637 fIncludeBinary = diff_include_binary_files();
638 }
639 stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
640 stash_diff(stashid, zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
641 }else
642 if( memcmp(zCmd, "help", nCmd)==0 ){
643 g.argv[1] = "help";
644 g.argv[2] = "stash";
645 g.argc = 3;
646
--- src/stash.c
+++ src/stash.c
@@ -282,15 +282,16 @@
282
283 /*
284 ** Show the diffs associate with a single stash.
285 */
286 static void stash_diff(
287 int stashid, /* The stash entry to diff */
288 const char *zDiffCmd, /* Command used for diffing */
289 const char *zBinGlob, /* GLOB pattern to determine binary files */
290 int fBaseline, /* Diff against original baseline check-in if true */
291 int fIncludeBinary, /* Do diffs against binary files */
292 u64 diffFlags /* Other diff flags */
293 ){
294 Stmt q;
295 Blob empty;
296 blob_zero(&empty);
297 db_prepare(&q,
@@ -304,62 +305,62 @@
305 int isLink = db_column_int(&q, 3);
306 int isBin1, isBin2;
307 const char *zOrig = db_column_text(&q, 4);
308 const char *zNew = db_column_text(&q, 5);
309 char *zOPath = mprintf("%s%s", g.zLocalRoot, zOrig);
310 Blob delta, a, b, disk;
311 if( rid==0 ){
312 db_ephemeral_blob(&q, 6, &a);
313 fossil_print("ADDED %s\n", zNew);
314 diff_print_index(zNew, diffFlags);
315 isBin1 = 0;
316 isBin2 = fIncludeBinary ? 0 : looks_like_binary(&a);
317 diff_file_mem(&empty, &a, isBin1, isBin2, zNew, zDiffCmd,
 
 
318 zBinGlob, fIncludeBinary, diffFlags);
319 }else if( isRemoved ){
320 fossil_print("DELETE %s\n", zOrig);
321 if( fBaseline==0 ){
322 if( file_wd_islink(zOPath) ){
323 blob_read_link(&a, zOPath);
324 }else{
325 blob_read_from_file(&a, zOPath);
326 }
327 }else{
328 content_get(rid, &a);
329 }
330 diff_print_index(zNew, diffFlags);
331 isBin1 = fIncludeBinary ? 0 : looks_like_binary(&a);
332 isBin2 = 0;
333 diff_file_mem(&a, &empty, isBin1, isBin2, zOrig, zDiffCmd,
 
 
334 zBinGlob, fIncludeBinary, diffFlags);
335 }else{
 
336 int isOrigLink = file_wd_islink(zOPath);
337 db_ephemeral_blob(&q, 6, &delta);
338 if( fBaseline==0 ){
339 if( isOrigLink ){
340 blob_read_link(&disk, zOPath);
341 }else{
342 blob_read_from_file(&disk, zOPath);
343 }
344 }
345 fossil_print("CHANGED %s\n", zNew);
346 if( !isOrigLink != !isLink ){
347 diff_print_index(zNew, diffFlags);
348 diff_print_filenames(zOrig, zNew, diffFlags);
349 printf(DIFF_CANNOT_COMPUTE_SYMLINK);
350 }else{
351 Blob *pBase = fBaseline ? &a : &disk;
352 content_get(rid, &a);
353 blob_delta_apply(&a, &delta, &b);
354 isBin1 = fIncludeBinary ? 0 : looks_like_binary(pBase);
355 isBin2 = fIncludeBinary ? 0 : looks_like_binary(&b);
356 diff_file_mem(fBaseline? &a : &disk, &b, isBin1, isBin2, zNew,
357 zDiffCmd, zBinGlob, fIncludeBinary, diffFlags);
 
 
358 blob_reset(&a);
359 blob_reset(&b);
360 }
361 if( !fBaseline ) blob_reset(&disk);
362 }
363 blob_reset(&delta);
364 }
365 db_finalize(&q);
366 }
@@ -415,10 +416,14 @@
416 ** fossil stash ls ?-l?
417 **
418 ** List all changes sets currently stashed. Show information about
419 ** individual files in each changeset if --detail or -l is used.
420 **
421 ** fossil stash show ?STASHID? ?DIFF-FLAGS?
422 **
423 ** Show the content of a stash
424 **
425 ** fossil stash pop
426 ** fossil stash apply ?STASHID?
427 **
428 ** Apply STASHID or the most recently create stash to the current
429 ** working check-out. The "pop" command deletes that changeset from
@@ -446,10 +451,11 @@
451 ** SUMMARY:
452 ** fossil stash
453 ** fossil stash save ?-m COMMENT? ?FILES...?
454 ** fossil stash snapshot ?-m COMMENT? ?FILES...?
455 ** fossil stash list|ls ?-l? ?--detail?
456 ** fossil stash show ?STASHID? ?DIFF-OPTIONS?
457 ** fossil stash pop
458 ** fossil stash apply ?STASHID?
459 ** fossil stash goto ?STASHID?
460 ** fossil stash rm|drop ?STASHID? ?--all?
461 ** fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS?
@@ -596,50 +602,36 @@
602 db_multi_exec("UPDATE vfile SET mtime=0 WHERE pathname IN "
603 "(SELECT origname FROM stashfile WHERE stashid=%d)",
604 stashid);
605 undo_finish();
606 }else
607 if( memcmp(zCmd, "diff", nCmd)==0
608 || memcmp(zCmd, "gdiff", nCmd)==0
609 || memcmp(zCmd, "show", nCmd)==0
610 ){
611 const char *zDiffCmd = 0;
612 const char *zBinGlob = 0;
613 int fIncludeBinary = 0;
614 u64 diffFlags;
615
616 if( find_option("tk",0,0)!=0 ){
617 db_close(0);
618 diff_tk((zCmd[0]=='s' ? "stash show" : "stash diff"), 3);
619 return;
620 }
621 if( find_option("internal","i",0)==0 ){
622 zDiffCmd = diff_command_external(0);
623 }
624 diffFlags = diff_options();
625 if( g.argc>4 ) usage(mprintf("%s STASHID", zCmd));
626 if( zDiffCmd ){
627 zBinGlob = diff_get_binary_glob();
628 fIncludeBinary = diff_include_binary_files();
629 }
630 stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
631 stash_diff(stashid, zDiffCmd, zBinGlob, zCmd[0]=='s', fIncludeBinary,
632 diffFlags);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633 }else
634 if( memcmp(zCmd, "help", nCmd)==0 ){
635 g.argv[1] = "help";
636 g.argv[2] = "stash";
637 g.argc = 3;
638
+1 -1
--- src/update.c
+++ src/update.c
@@ -625,11 +625,11 @@
625625
if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
626626
if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
627627
manifest_destroy(pManifest);
628628
rc = content_get(rid, content);
629629
if( rc && pIsBin ){
630
- *pIsBin = looks_like_binary(blob_str(content), blob_size(content));
630
+ *pIsBin = looks_like_binary(content);
631631
}
632632
return rc;
633633
}
634634
manifest_destroy(pManifest);
635635
if( errCode<=0 ){
636636
--- src/update.c
+++ src/update.c
@@ -625,11 +625,11 @@
625 if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
626 if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
627 manifest_destroy(pManifest);
628 rc = content_get(rid, content);
629 if( rc && pIsBin ){
630 *pIsBin = looks_like_binary(blob_str(content), blob_size(content));
631 }
632 return rc;
633 }
634 manifest_destroy(pManifest);
635 if( errCode<=0 ){
636
--- src/update.c
+++ src/update.c
@@ -625,11 +625,11 @@
625 if( pIsExe ) *pIsExe = ( manifest_file_mperm(pFile)==PERM_EXE );
626 if( pIsLink ) *pIsLink = ( manifest_file_mperm(pFile)==PERM_LNK );
627 manifest_destroy(pManifest);
628 rc = content_get(rid, content);
629 if( rc && pIsBin ){
630 *pIsBin = looks_like_binary(content);
631 }
632 return rc;
633 }
634 manifest_destroy(pManifest);
635 if( errCode<=0 ){
636

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button