Fossil

Changes On Branch revert-dir
Login

Changes On Branch revert-dir

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch revert-dir Excluding Merge-Ins

This is equivalent to a diff from a8098efebf to 0ad3e06bd2

2020-06-04
20:51
revert: Allow reverting of current changes for the whole directory tree. ... (check-in: a8bb08697a user: ashepilko tags: trunk)
2020-05-21
13:00
Fix the URL on some Download submenu links. ... (check-in: 9d18585d54 user: drh tags: trunk)
2020-05-19
18:31
Merge in trunk. ... (Closed-Leaf check-in: 0ad3e06bd2 user: ashepilko tags: revert-dir)
16:51
Update the built-in SQLite to the third beta for 3.32.0. ... (check-in: a8098efebf user: drh tags: trunk)
2020-05-18
11:48
When compiling with older versions of OpenSSL that do not support SHA256, hash certs using SHA1 instead. ... (check-in: 64d79ad457 user: drh tags: trunk)
2020-05-11
04:17
Merge in trunk. ... (check-in: 09239396ae user: ashepilko tags: revert-dir)

Changes to src/update.c.

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777



778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794
795
796
797
798


799
800
801
802
803
804
805
806
807
808

809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825






















826











827
828
829
830
831
832
833

834
835
836









837
838
839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
  /* Return 1 on success and (assuming fatal is not set) 0 if not found. */
  return result;
}

/*
** COMMAND: revert
**
** Usage: %fossil revert ?-r REVISION? ?FILE ...?
**
** Revert to the current repository version of FILE, or to
** the version associated with baseline REVISION if the -r flag
** appears.
**
** If FILE was part of a rename operation, both the original file
** and the renamed file are reverted.



**
** Revert all files if no file name is provided.
**
** If a file is reverted accidentally, it can be restored using
** the "fossil undo" command.
**
** Options:
**   -r REVISION    revert given FILE(s) back to given REVISION

**
** See also: redo, undo, update
*/
void revert_cmd(void){
  Manifest *pCoManifest;          /* Manifest of current checkout */
  Manifest *pRvManifest;          /* Manifest of selected revert version */
  ManifestFile *pCoFile;          /* File within current checkout manifest */
  ManifestFile *pRvFile;          /* File within revert version manifest */
  const char *zFile;              /* Filename relative to checkout root */
  const char *zRevision;          /* Selected revert version, NULL if current */
  Blob record = BLOB_INITIALIZER; /* Contents of each reverted file */
  int i;
  Stmt q;



  undo_capture_command_line();
  zRevision = find_option("revision", "r", 1);
  verify_all_options();

  if( g.argc<2 ){
    usage("?OPTIONS? [FILE] ...");
  }
  if( zRevision && g.argc<3 ){
    fossil_fatal("the --revision option does not work for the entire tree");

  }
  db_must_be_within_tree();

  /* Get manifests of revert version and (if different) current checkout. */
  pRvManifest = historical_manifest(zRevision);
  pCoManifest = zRevision ? historical_manifest(0) : 0;

  db_begin_transaction();
  undo_begin();
  db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");

  if( g.argc>2 ){
    for(i=2; i<g.argc; i++){
      Blob fname;
      zFile = mprintf("%/", g.argv[i]);
      blob_zero(&fname);
      file_tree_name(zFile, &fname, 0, 1);






















      db_multi_exec(











        "REPLACE INTO torevert VALUES(%B);"
        "INSERT OR IGNORE INTO torevert"
        " SELECT pathname"
        "   FROM vfile"
        "  WHERE origname=%B;",
        &fname, &fname
      );

      blob_reset(&fname);
    }
  }else{









    int vid;
    vid = db_lget_int("checkout", 0);
    vfile_check_signature(vid, 0);
    db_multi_exec(
      "DELETE FROM vmerge;"
      "INSERT OR IGNORE INTO torevert "
      " SELECT pathname"
      "   FROM vfile "
      "  WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
    );
  }

  db_multi_exec(
    "INSERT OR IGNORE INTO torevert"
    " SELECT origname"
    "   FROM vfile"
    "  WHERE origname!=pathname AND pathname IN (SELECT name FROM torevert);"
  );
  blob_zero(&record);







|


|
<



>
>
>







|
>

|











>
>









|
>

















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
>



>
>
>
>
>
>
>
>
>











>







763
764
765
766
767
768
769
770
771
772
773

774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
  /* Return 1 on success and (assuming fatal is not set) 0 if not found. */
  return result;
}

/*
** COMMAND: revert
**
** Usage: %fossil revert ?OPTIONS? ?FILE ...?
**
** Revert to the current repository version of FILE, or to
** the baseline VERSION specified with -r flag.

**
** If FILE was part of a rename operation, both the original file
** and the renamed file are reverted.
**
** Using a directory name for any of the FILE arguments is the same
** as using every subdirectory and file beneath that directory.
**
** Revert all files if no file name is provided.
**
** If a file is reverted accidentally, it can be restored using
** the "fossil undo" command.
**
** Options:
**   -r|--revision VERSION    Revert given FILE(s) back to given
**                            VERSION
**
** See also: redo, undo, checkout, update
*/
void revert_cmd(void){
  Manifest *pCoManifest;          /* Manifest of current checkout */
  Manifest *pRvManifest;          /* Manifest of selected revert version */
  ManifestFile *pCoFile;          /* File within current checkout manifest */
  ManifestFile *pRvFile;          /* File within revert version manifest */
  const char *zFile;              /* Filename relative to checkout root */
  const char *zRevision;          /* Selected revert version, NULL if current */
  Blob record = BLOB_INITIALIZER; /* Contents of each reverted file */
  int i;
  Stmt q;
  int revertAll = 0;
  int revisionOptNotSupported = 0;

  undo_capture_command_line();
  zRevision = find_option("revision", "r", 1);
  verify_all_options();

  if( g.argc<2 ){
    usage("?OPTIONS? [FILE] ...");
  }
  if( zRevision && g.argc<3 ){
    fossil_fatal("directories or the entire tree can only be reverted"
                 " back to current version");
  }
  db_must_be_within_tree();

  /* Get manifests of revert version and (if different) current checkout. */
  pRvManifest = historical_manifest(zRevision);
  pCoManifest = zRevision ? historical_manifest(0) : 0;

  db_begin_transaction();
  undo_begin();
  db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");

  if( g.argc>2 ){
    for(i=2; i<g.argc; i++){
      Blob fname;
      zFile = mprintf("%/", g.argv[i]);
      blob_zero(&fname);
      file_tree_name(zFile, &fname, 0, 1);
      if( blob_eq(&fname, ".") ){
        if( zRevision ){
          revisionOptNotSupported = 1;
          break;
        }
        revertAll = 1;
        break;
      }else if( db_exists(
        "SELECT pathname"
        "  FROM vfile"
        " WHERE (substr(pathname,1,length('%q/'))='%q/'"
        "    OR  substr(origname,1,length('%q/'))='%q/');",
        blob_str(&fname), blob_str(&fname),
        blob_str(&fname), blob_str(&fname)) ){
        int vid;
        vid = db_lget_int("checkout", 0);
        vfile_check_signature(vid, 0);

        if( zRevision ){
          revisionOptNotSupported = 1;
          break;
        }
        db_multi_exec(
          "INSERT OR IGNORE INTO torevert"
          " SELECT pathname"
          "   FROM vfile"
          "  WHERE (substr(pathname,1,length('%q/'))='%q/'"
          "     OR  substr(origname,1,length('%q/'))='%q/')"
          "    AND (chnged OR deleted OR rid=0 OR pathname!=origname);",
          blob_str(&fname), blob_str(&fname),
          blob_str(&fname), blob_str(&fname)
        );
      }else{
        db_multi_exec(
          "REPLACE INTO torevert VALUES(%B);"
          "INSERT OR IGNORE INTO torevert"
          " SELECT pathname"
          "   FROM vfile"
          "  WHERE origname=%B;",
          &fname, &fname
        );
      }
      blob_reset(&fname);
    }
  }else{
    revertAll = 1;
  }

  if( revisionOptNotSupported ){
    fossil_fatal("directories or the entire tree can only be reverted"
                 " back to current version");
  }

  if ( revertAll ){
    int vid;
    vid = db_lget_int("checkout", 0);
    vfile_check_signature(vid, 0);
    db_multi_exec(
      "DELETE FROM vmerge;"
      "INSERT OR IGNORE INTO torevert "
      " SELECT pathname"
      "   FROM vfile "
      "  WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
    );
  }

  db_multi_exec(
    "INSERT OR IGNORE INTO torevert"
    " SELECT origname"
    "   FROM vfile"
    "  WHERE origname!=pathname AND pathname IN (SELECT name FROM torevert);"
  );
  blob_zero(&record);

Changes to test/revert.test.

184
185
186
187
188
189
190




































































































































































191
192
193
194
fossil mv --soft f1 f1new
test 3-mv-1 {[file exists f1]}
test 3-mv-2 {![file exists f1new]}
revert-test 3-1 {} {
  REVERT f1
  DELETE f1new
} -exists {f1} -notexists {f1n}





































































































































































###############################################################################

test_cleanup







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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
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
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
fossil mv --soft f1 f1new
test 3-mv-1 {[file exists f1]}
test 3-mv-2 {![file exists f1new]}
revert-test 3-1 {} {
  REVERT f1
  DELETE f1new
} -exists {f1} -notexists {f1n}


# Test reverting of files under a sub-directory
test_setup
file mkdir d
write_file d/f1 "d/f1"
write_file d/f2 "d/f2"
write_file d/f3 "d/f3"
write_file d/f4 "d/f4"

fossil add d
fossil delete d/f1
fossil commit -m "d/f2 d/f3 d/f4"

## Changes to revert
fossil add d/f1
write_file d/f2 "4-1:d/f2"
fossil changes d/f2
fossil delete --soft d/f3

revert-test 4-1 {d/f1} {
  UNMANAGE   d/f1
} -changes {
  EDITED  d/f2
  DELETED d/f3
} -addremove {
  ADDED   d/f1
} -exists {d/f1 d/f2 d/f3}

revert-test 4-2 {d/f2} {
  REVERT  d/f2
} -changes {
  ADDED   d/f1
  DELETED d/f3
} -exists {d/f1 d/f2 d/f3}

revert-test 4-3 {d/f3} {
  REVERT   d/f3
} -changes {
  ADDED   d/f1
  EDITED  d/f2
} -exists {d/f1 d/f2 d/f3}

fossil mv --soft d/f4 d/f4new
test 4-4-mv-1 {[file exists d/f4]}
test 4-4-mv-2 {![file exists d/f4new]}
revert-test 4-4 {d/f4} {
  DELETE   d/f4new
  REVERT   d/f4
} -changes {
  ADDED   d/f1
  EDITED  d/f2
  DELETED d/f3
} -exists {d/f4} -notexists {d/f4new}

## Commit changes before testing reverting of directory rename,
## otherwise there're could be sequencing issues
fossil redo
fossil commit -m "4-5:setup"

fossil mv --soft d dnew
revert-test 4-5 {d/f1 d/f2 d/f3 d/f4} {
  REVERT   d/f1
  REVERT   d/f2
  UNMANAGE d/f3
  REVERT   d/f4
  DELETE   dnew/f1
  DELETE   dnew/f2
  DELETE   dnew/f4
} -addremove {
  ADDED    d/f3
} -exists {d/f1 d/f2 d/f3 d/f4} -notexists {dnew}


## Test reverting of changes in whole sub-directory tree
test_setup
file mkdir d
write_file f0 "f0"
write_file d/f1 "d/f1"
write_file d/f2 "d/f2"
write_file d/f3 "d/f3"
write_file d/f4 "d/f4"

fossil add f0 d
fossil delete d/f1
fossil commit -m "f0 d/f2 d/f3 d/f4"

## Changes to revert
fossil add d/f1
write_file d/f2 "5-1:d/f2"
fossil changes d/f2
fossil delete --soft d/f3

revert-test 5-1 {d} {
  UNMANAGE d/f1
  REVERT   d/f2
  REVERT   d/f3
} -addremove {
  ADDED    d/f1
} -exists {f0 d/f1 d/f2 d/f3}

write_file f0 "5-2:f0"
fossil changes f0
revert-test 5-2 {f0 d} {
  UNMANAGE d/f1
  REVERT   d/f2
  REVERT   d/f3
  REVERT   f0
} -addremove {
  ADDED    d/f1
} -exists {f0 d/f1 d/f2 d/f3}

## Commit changes before testing the revert of directory rename,
## otherwise there're could be sequencing issues
fossil commit -m "5-3:setup"

fossil changes

fossil mv --soft d dnew
revert-test 5-3 {d} {
  REVERT   d/f1
  REVERT   d/f2
  REVERT   d/f4
  DELETE   dnew/f1
  DELETE   dnew/f2
  DELETE   dnew/f4
} -addremove {
  ADDED    d/f3
} -exists {f0 d/f1 d/f2 d/f3 d/f4} -notexists {dnew}

## Reset/redo the undone results of revert to get to a clean checkout
fossil redo

file mkdir d/e
file mkdir d/e/f
write_file d/e/fe1 "d/e/fe1"
write_file d/e/f/ff1 "d/e/f/ff1"

file mkdir d1
file mkdir d1/e
write_file d1/e/fe1 "d1/e/fe1"
write_file d1/e/fe2 "d1/e/fe2"

fossil add d1/e/fe1
fossil commit d1/e/fe1 -m "d1/e/fe1"

write_file d1/e/fe1 "5-4:d1/e/fe1"
fossil changes d1/e/fe1
fossil add d d1

revert-test 5-4 {d d1} {
  UNMANAGE d/f3
  UNMANAGE d/e/fe1
  UNMANAGE d/e/f/ff1
  REVERT   d1/e/fe1
  UNMANAGE d1/e/fe2
} -addremove {
  ADDED    d/f3
  ADDED    d/e/fe1
  ADDED    d/e/f/ff1
  ADDED    d1/e/fe2
} -exists {d/f1 d/f2 d/f3 d/f4 d/e/fe1 d/e/fe1 d/e/f/ff1
           d1/e/fe1 d1/e/fe2}


###############################################################################

test_cleanup