178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
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(&delta);
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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
|
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 COMMAND ARGS...
** Usage: %fossil stash SUBCOMMAND ARGS...
**
** fossil stash
** fossil stash save ?-m COMMENT? ?FILES...?
** 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.
** 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
** fossil stash list
**
** List all changes sets currently stashed.
** List all changes sets currently stashed.
**
** fossil stash pop
** 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.
** 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?
** 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.
** 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?
** 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.
** 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?
** fossil drop ?STASHID?
**
** Forget everything about STASHID. This command is undoable.
** Forget everything about STASHID. This command is undoable.
**
** fossil stash snapshot ?-m COMMENT? ?FILES...?
** 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.
** 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
397
398
399
400
|
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("apply|drop|goto|list|pop|save|snapshot ARGS...");
usage("SUBCOMMAND ARGS...");
}
db_end_transaction(0);
}
|