Fossil

Diff
Login

Differences From Artifact [e87cafeb71]:

To Artifact [7dbd96ec46]:


131
132
133
134
135
136
137
138
139
140
141
142
143























144
145
146
147
148
149
150
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172







-





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







** Reset the undo memory.
*/
void undo_reset(void){
  static const char zSql[] =
    @ DROP TABLE IF EXISTS undo;
    @ DROP TABLE IF EXISTS undo_vfile;
    @ DROP TABLE IF EXISTS undo_vmerge;
    @ DROP TABLE IF EXISTS undo_pending;
    ;
  db_multi_exec(zSql);
  db_lset_int("undo_available", 0);
  db_lset_int("undo_checkout", 0);
}

/*
** The following variable stores the original command-line of the
** command that is a candidate to be undone.
*/
static char *undoCmd = 0;

/*
** Capture the current command-line and store it as part of the undo
** state.  This routine is called before options are extracted from the
** command-line so that we can record the complete command-line.
*/
void undo_capture_command_line(void){
  Blob cmdline;
  int i;
  assert( undoCmd==0 );
  blob_zero(&cmdline);
  for(i=1; i<g.argc; i++){
    if( i>1 ) blob_append(&cmdline, " ", 1);
    blob_append(&cmdline, g.argv[i], -1);
  }
  undoCmd = blob_str(&cmdline);
}

/*
** This flag is true if we are in the process of collecting file changes
** for undo.  When this flag is false, undo_save() is a no-op.
*/
static int undoActive = 0;

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
191
192
193
194
195
196
197
198
199
200
201
202







-







+







    @   pathname TEXT UNIQUE,             -- Name of the file
    @   redoflag BOOLEAN,                 -- 0 for undoable.  1 for redoable
    @   existsflag BOOLEAN,               -- True if the file exists
    @   content BLOB                      -- Saved content
    @ );
    @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
    @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
    @ CREATE TABLE %s.undo_pending(undoId INTEGER PRIMARY KEY);
  ;
  undo_reset();
  if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main";
  db_multi_exec(zSql, zDb, zDb, zDb, zDb);
  cid = db_lget_int("checkout", 0);
  db_lset_int("undo_checkout", cid);
  db_lset_int("undo_available", 1);
  db_lset("undo_cmdline", undoCmd);
  undoActive = 1;
}

/*
** This flag is true if one or more files have changed and have been
** recorded in the undo log but the undo log has not yet been committed.
**
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
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
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
322
323
324
325
326


327
328
329
330
331

332
333
334
335
336
337

338
339
340
341
342
343







+

-
+
+



-
+
+
+
+
+
+





+

+
+



-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+



-
+





-
+





  undoActive = 0;
  printf("Rolling back prior filesystem changes...\n");
  undo_all_filesystem(0);
}

/*
** COMMAND: undo
** COMMAND: redo
**
** Usage: %fossil undo ?FILENAME...?
** Usage: %fossil undo ?--explain? ?FILENAME...?
**    or: %fossil redo ?--explain? ?FILENAME...?
**
** Undo the most recent update or merge or revert operation.  If FILENAME is
** specified then restore the content of the named file(s) but otherwise
** leave the update or merge or revert in effect.
** leave the update or merge or revert in effect.  The redo command undoes
** the effect of the most recent undo.
**
** If the --explain option is present, not changes are made and instead
** the undo or redo command explains what actions the undo or redo would
** have done had the --explain been omitted.
**
** A single level of undo/redo is supported.  The undo/redo stack
** is cleared by the commit and checkout commands.
*/
void undo_cmd(void){
  int isRedo = g.argv[1][0]=='r';
  int undo_available;
  int explainFlag = find_option("explain", 0, 0)!=0;
  const char *zCmd = isRedo ? "redo" : "undo";
  db_must_be_within_tree();
  db_begin_transaction();
  undo_available = db_lget_int("undo_available", 0);
  if( g.argc==2 ){
    if( undo_available!=1 ){
  if( explainFlag ){
    if( undo_available==0 ){
      fossil_fatal("no update or merge operation is available to undo");
    }
    undo_all(0);
    db_lset_int("undo_available", 2);
  }else if( g.argc>=3 ){
    int i;
    if( undo_available==0 ){
      fossil_fatal("no update or merge operation is available to undo");
      printf("No undo or redo is available\n");
    }else{
      Stmt q;
      int nChng = 0;
      zCmd = undo_available==1 ? "undo" : "redo";
      printf("A %s is available for the following command:\n\n   %s %s\n\n",
    }
    for(i=2; i<g.argc; i++){
      const char *zFile = g.argv[i];
      Blob path;
      file_tree_name(zFile, &path, 1);
      undo_one(blob_str(&path), 0);
      blob_reset(&path);
              zCmd, g.argv[0], db_lget("undo_cmdline", "???"));
      db_prepare(&q,
        "SELECT existsflag, pathname FROM undo ORDER BY pathname"
      );
      while( db_step(&q)==SQLITE_ROW ){
        if( nChng==0 ){
    }
  }
  db_end_transaction(0);
}

          printf("The following file changes would occur if the "
/*
** COMMAND: redo
**
** Usage: %fossil redo ?FILENAME...?
**
** Redo an update or merge or revert operation that has been undone
** by the undo command.  If FILENAME is specified then restore the changes
** associated with the named file(s) but otherwise leave the update
** or merge undone.
**
** A single level of undo/redo is supported.  The undo/redo stack
** is cleared by the commit and checkout commands.
                 "command above is %sne:\n\n", zCmd);
*/
void redo_cmd(void){
  int undo_available;
  db_must_be_within_tree();
  db_begin_transaction();
        }
        nChng++;
        printf("%s %s\n", 
           db_column_int(&q,0) ? "UPDATE" : "DELETE",
           db_column_text(&q, 1)
        );
      }
      db_finalize(&q);
  undo_available = db_lget_int("undo_available", 0);
  if( g.argc==2 ){
    if( undo_available!=2 ){
      fossil_fatal("no undone update or merge operation is available to redo");
      if( nChng==0 ){
        printf("No file changes would occur with this undo/redo.\n");
      }
    }
  }else if( g.argc==2 ){
    if( undo_available!=(1+isRedo) ){
      fossil_fatal("nothing to %s", zCmd);
    }
    undo_all(1);
    db_lset_int("undo_available", 1);
    undo_all(isRedo);
    db_lset_int("undo_available", 2-isRedo);
  }else if( g.argc>=3 ){
    int i;
    if( undo_available==0 ){
      fossil_fatal("no update or merge operation is available to redo");
      fossil_fatal("nothing to %s", zCmd);
    }
    for(i=2; i<g.argc; i++){
      const char *zFile = g.argv[i];
      Blob path;
      file_tree_name(zFile, &path, 1);
      undo_one(blob_str(&path), 0);
      undo_one(blob_str(&path), isRedo);
      blob_reset(&path);
    }
  }
  db_end_transaction(0);
}