Overview
SHA1 Hash: | 7b82a73bd39b7f864d69978bd1fbfbfadb6339c7 |
---|---|
Date: | 2009-12-17 21:22:52 |
User: | drh |
Comment: | Remove the --yes option from the "revert" command. In its place, make the "revert" opration undoable. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/diffcmd.c from [20363d7b42] to [88a94ee318].
@@ -190,11 +190,11 @@ */ static void diff_one_against_disk(const char *zFrom, const char *zDiffCmd){ Blob fname; Blob content; file_tree_name(g.argv[2], &fname, 1); - historical_version_of_file(zFrom, blob_str(&fname), &content); + historical_version_of_file(zFrom, blob_str(&fname), &content, 0); diff_file(&content, g.argv[2], g.argv[2], zDiffCmd); blob_reset(&content); blob_reset(&fname); } @@ -295,12 +295,12 @@ char *zName; Blob fname; Blob v1, v2; file_tree_name(g.argv[2], &fname, 1); zName = blob_str(&fname); - historical_version_of_file(zFrom, zName, &v1); - historical_version_of_file(zTo, zName, &v2); + historical_version_of_file(zFrom, zName, &v1, 0); + historical_version_of_file(zTo, zName, &v2, 0); diff_file_mem(&v1, &v2, zName, zDiffCmd); blob_reset(&v1); blob_reset(&v2); blob_reset(&fname); }
Modified src/undo.c from [e141d7b88f] to [0d2cc71745].
@@ -189,13 +189,13 @@ /* ** COMMAND: undo ** ** Usage: %fossil undo ?FILENAME...? ** -** Undo the most recent update or merge operation. If FILENAME is +** 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 in effect. +** leave the update or merge or revert in effect. ** ** A single level of undo/redo is supported. The undo/redo stack ** is cleared by the commit and checkout commands. */ void undo_cmd(void){ @@ -228,12 +228,12 @@ /* ** COMMAND: redo ** ** Usage: %fossil redo ?FILENAME...? ** -** Redo the an update or merge operation that has been undone by the -** undo command. If FILENAME is specified then restore the changes +** Redo the 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.
Modified src/update.c from [b8775abaa9] to [9671f6cd74].
@@ -253,11 +253,12 @@ ** Get the contents of a file within a given revision. */ int historical_version_of_file( const char *revision, /* The baseline name containing the file */ const char *file, /* Full treename of the file */ - Blob *content /* Put the content here */ + Blob *content, /* Put the content here */ + int errCode /* Error code if file not found. Panic if 0. */ ){ Blob mfile; Manifest m; int i, rid=0; @@ -265,10 +266,11 @@ rid = name_to_rid(revision); }else{ rid = db_lget_int("checkout", 0); } if( !is_a_version(rid) ){ + if( errCode>0 ) return errCode; fossil_fatal("no such check-out: %s", revision); } content_get(rid, &mfile); if( manifest_parse(&m, &mfile) ){ @@ -276,82 +278,76 @@ if( strcmp(m.aFile[i].zName, file)==0 ){ rid = uuid_to_rid(m.aFile[i].zUuid, 0); return content_get(rid, content); } } - fossil_fatal("file %s does not exist in baseline: %s", file, revision); - }else{ + if( errCode<=0 ){ + fossil_fatal("file %s does not exist in baseline: %s", file, revision); + } + }else if( errCode<=0 ){ fossil_panic("could not parse manifest for baseline: %s", revision); } - return 0; + return errCode; } /* ** COMMAND: revert ** -** Usage: %fossil revert ?--yes? ?-r REVISION? FILE ... +** 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. This command will confirm your operation unless the -** file is missing or the --yes option is used. -**/ +** appears. +** +** If a file is reverted accidently, it can be restored using +** the "fossil undo" command. +*/ void revert_cmd(void){ char *zFile; const char *zRevision; Blob fname; Blob record; - Blob ans; int i; + int errCode; int rid = 0; - int yesFlag; - int yesRevert; - - yesFlag = find_option("yes", "y", 0)!=0; + zRevision = find_option("revision", "r", 1); verify_all_options(); if( g.argc<3 ){ - usage("?OPTIONS FILE ..."); + usage("?OPTIONS? FILE ..."); } db_must_be_within_tree(); + db_begin_transaction(); + undo_begin(); for(i=2; i<g.argc; i++){ zFile = mprintf("%/", g.argv[i]); file_tree_name(zFile, &fname, 1); - yesRevert = yesFlag; - if( !yesRevert && access(zFile, 0) ) yesRevert = 1; - if( yesRevert==0 ){ - char *prompt = mprintf("revert file %B? this will" - " destroy local changes (y/N)? ", - &fname); - blob_zero(&ans); - prompt_user(prompt, &ans); - free( prompt ); - if( blob_str(&ans)[0]=='y' ){ - yesRevert = 1; - } - blob_reset(&ans); + + if( zRevision!=0 ){ + errCode = historical_version_of_file(zRevision, blob_str(&fname), + &record, 2); + }else{ + rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); + if( rid==0 ){ + errCode = 2; + }else{ + content_get(rid, &record); + errCode = 0; + } } - if( yesRevert==1 && zRevision!=0 ){ - historical_version_of_file(zRevision, zFile, &record); - }else if( yesRevert==1 ){ - rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); - if( rid==0 ){ - fossil_panic("no history for file: %b", &fname); - } - content_get(rid, &record); - } - - if( yesRevert==1 ){ + if( errCode==2 ){ + fossil_warning("file not in repository: %s", zFile); + }else{ + undo_save(blob_str(&fname)); blob_write_to_file(&record, zFile); printf("%s reverted\n", zFile); - blob_reset(&record); - blob_reset(&fname); - }else{ - printf("revert canceled\n"); } + blob_reset(&record); + blob_reset(&fname); free(zFile); } + db_end_transaction(0); }