Diff
Not logged in

Differences From Artifact [45ab33f629]:

To Artifact [51b883b5f6]:


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
     stashid
  );
  while( db_step(&q)==SQLITE_ROW ){
    int deleted = db_column_int(&q, 0);
    int rid = db_column_int(&q, 2);
    const char *zName = db_column_text(&q, 3);
    const char *zOrig = db_column_text(&q, 4);
    char *zPath = mprintf("%s/%s", g.zLocalRoot, zName);
    Blob content;

    db_bind_int(&ins, ":rid", rid);
    db_bind_int(&ins, ":isadd", rid==0);
    db_bind_int(&ins, ":isrm", deleted);
#ifdef _WIN32
    db_bind_int(&ins, ":isexe", db_column_int(&q, 2));







|







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
     stashid
  );
  while( db_step(&q)==SQLITE_ROW ){
    int deleted = db_column_int(&q, 0);
    int rid = db_column_int(&q, 2);
    const char *zName = db_column_text(&q, 3);
    const char *zOrig = db_column_text(&q, 4);
    char *zPath = mprintf("%s%s", g.zLocalRoot, zName);
    Blob content;

    db_bind_int(&ins, ":rid", rid);
    db_bind_int(&ins, ":isadd", rid==0);
    db_bind_int(&ins, ":isrm", deleted);
#ifdef _WIN32
    db_bind_int(&ins, ":isexe", db_column_int(&q, 2));
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
**
** If the "-m" or "--comment" command-line option is present, gather
** its argument as the stash comment.
**
** If files are named on the command-line, then only stash the named
** files.
*/
static void stash_create(void){
  const char *zComment;              /* Comment to add to the stash */
  int stashid;                       /* ID of the new stash */
  int vid;                           /* Current checkout */

  zComment = find_option("comment", "m", 1);
  verify_all_options();
  stashid = db_lget_int("stash-next", 1);







|







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
**
** If the "-m" or "--comment" command-line option is present, gather
** its argument as the stash comment.
**
** If files are named on the command-line, then only stash the named
** files.
*/
static int stash_create(void){
  const char *zComment;              /* Comment to add to the stash */
  int stashid;                       /* ID of the new stash */
  int vid;                           /* Current checkout */

  zComment = find_option("comment", "m", 1);
  verify_all_options();
  stashid = db_lget_int("stash-next", 1);
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  if( g.argc>3 ){
    int i;
    for(i=3; i<g.argc; i++){
      stash_add_file_or_dir(stashid, vid, g.argv[i]);
    }
  }else{
    stash_add_file_or_dir(stashid, vid, ".");
  } 

}

/*
** Apply a stash to the current check-out.
*/
static void stash_apply(int stashid, int nConflict){
  Stmt q;
  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);
    char *zNPath = mprintf("%s/%s", g.zLocalRoot, zNew);
    undo_save(zNPath);
    Blob 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);







|
>

















|
|
|







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  if( g.argc>3 ){
    int i;
    for(i=3; i<g.argc; i++){
      stash_add_file_or_dir(stashid, vid, g.argv[i]);
    }
  }else{
    stash_add_file_or_dir(stashid, vid, ".");
  }
  return stashid;
}

/*
** Apply a stash to the current check-out.
*/
static void stash_apply(int stashid, int nConflict){
  Stmt q;
  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);
    char *zNPath = mprintf("%s%s", g.zLocalRoot, zNew);
    undo_save(zNew);
    Blob 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);
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        blob_reset(&out);
      }
      blob_reset(&a);
      blob_reset(&b);
      blob_reset(&delta);
    }
    if( strcmp(zOrig,zNew)!=0 ){
      undo_save(zOPath);
      unlink(zOPath);
    }
  }
  db_finalize(&q);
  if( nConflict ){
    printf("WARNING: merge conflicts - see messages above for details.\n");
  }







|







210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
        blob_reset(&out);
      }
      blob_reset(&a);
      blob_reset(&b);
      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");
  }
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
311
312
313
314

/*
** COMMAND: stash
**
** Usage: %fossil COMMAND 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.

**
**    fossil stash apply STASHID
**
**         Apply the identified stash to the current working check-out.


**         But unlike "pop", keep the stash so that it can be used again.
**
**    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

**
**    fossil drop STASHID
**
**         Forget everything about STASHID.
**
**    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.
*/
void stash_cmd(void){
  const char *zDb = "localdb";
  const char *zCmd;
  int nCmd;


  undo_capture_command_line();
  db_must_be_within_tree();
  db_begin_transaction();
  if( strcmp(g.zMainDbType, zDb)==0 ) zDb = "main";
  db_multi_exec(zStashInit, zDb, zDb);
  if( g.argc<=2 ){
    zCmd = "save";
  }else{
    zCmd = g.argv[2];
  }
  nCmd = strlen(zCmd);







|
















>

|


>
>
|

|



>

|

|

|





|


>
>



|







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
311
312
313
314
315
316
317
318
319
320
321

/*
** COMMAND: stash
**
** Usage: %fossil COMMAND 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.
*/
void stash_cmd(void){
  const char *zDb;
  const char *zCmd;
  int nCmd;
  int stashid;

  undo_capture_command_line();
  db_must_be_within_tree();
  db_begin_transaction();
  zDb = db_name("localdb");
  db_multi_exec(zStashInit, zDb, zDb);
  if( g.argc<=2 ){
    zCmd = "save";
  }else{
    zCmd = g.argv[2];
  }
  nCmd = strlen(zCmd);
345
346
347
348
349
350
351
352


353

354
355
356
357
358
359

360
361
362
363
364
365
366
367
368
369
370



371
372
373
374

375



376
377
378
379
380
381
382
      }
    }
    db_finalize(&q);
    if( n==0 ) printf("empty stash\n");
  }else
  if( memcmp(zCmd, "drop", nCmd)==0 ){
    if( g.argc>4 ) usage("stash apply STASHID");
    int stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);


    stash_drop(stashid);

  }else
  if( memcmp(zCmd, "pop", nCmd)==0 ){
    if( g.argc>3 ) usage("stash pop");
    int stashid = stash_get_id(0);
    undo_begin();
    stash_apply(stashid, 0);

    undo_finish();
    stash_drop(stashid);
  }else
  if( memcmp(zCmd, "apply", nCmd)==0 ){
    if( g.argc>4 ) usage("stash apply STASHID");
    int stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
    undo_begin();
    stash_apply(stashid, 0);
    undo_finish();
  }else
  if( memcmp(zCmd, "goto", nCmd)==0 ){



    if( g.argc>4 ) usage("stash apply STASHID");
    int stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
    undo_begin();
    update_to(db_int(0, "SELECT vid FROM stash WHERE stashid=%d", stashid));

    stash_apply(stashid, 0);



    undo_finish();
  }else
  {
    usage("apply|drop|goto|list|pop|save|snapshot ARGS...");
  }
  db_end_transaction(0);
}







|
>
>

>



|


>





|





>
>
>

|

|
>
|
>
>
>







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
      }
    }
    db_finalize(&q);
    if( n==0 ) printf("empty stash\n");
  }else
  if( memcmp(zCmd, "drop", nCmd)==0 ){
    if( g.argc>4 ) usage("stash apply STASHID");
    stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
    undo_begin();
    undo_save_stash(stashid);
    stash_drop(stashid);
    undo_finish();
  }else
  if( memcmp(zCmd, "pop", nCmd)==0 ){
    if( g.argc>3 ) usage("stash pop");
    stashid = stash_get_id(0);
    undo_begin();
    stash_apply(stashid, 0);
    undo_save_stash(stashid);
    undo_finish();
    stash_drop(stashid);
  }else
  if( memcmp(zCmd, "apply", nCmd)==0 ){
    if( g.argc>4 ) usage("stash apply STASHID");
    stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
    undo_begin();
    stash_apply(stashid, 0);
    undo_finish();
  }else
  if( memcmp(zCmd, "goto", nCmd)==0 ){
    int nConflict;
    int vid;

    if( g.argc>4 ) usage("stash apply STASHID");
    stashid = stash_get_id(g.argc==4 ? g.argv[3] : 0);
    undo_begin();
    vid = db_int(0, "SELECT vid FROM stash WHERE stashid=%d", stashid);
    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
  {
    usage("apply|drop|goto|list|pop|save|snapshot ARGS...");
  }
  db_end_transaction(0);
}