Overview
SHA1 Hash: | 574763bab9eb73a4cdf733c331bc596866d53c7c |
---|---|
Date: | 2007-09-26 03:37:12 |
User: | jnc |
Comment: | Added revision support to diff and revert |
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/content.c from [310f7c7a1f] to [02e1a3dfd6].
@@ -73,10 +73,36 @@ rc = 1; } db_finalize(&q); } return rc; +} + +/* +** Get the contents of a file within a given revision. +*/ +int content_get_historical_file(const char *revision, const char *file, Blob *content){ + Blob mfile; + Manifest m; + int i, rid=0; + + rid = name_to_rid(revision); + content_get(rid, &mfile); + + if( manifest_parse(&m, &mfile) ){ + for(i=0; i<m.nFile; i++){ + if( strcmp(m.aFile[i].zName, file)==0 ){ + rid = uuid_to_rid(m.aFile[i].zUuid, 0); + return content_get(rid, content); + } + } + fossil_panic("file: %s does not exist in revision: %s", file, revision); + }else{ + fossil_panic("could not parse manifest for revision: %s", revision); + } + + return 0; } /* ** COMMAND: test-content-get **
Modified src/diffcmd.c from [4af4f0ff55] to [e546baef8b].
@@ -44,11 +44,11 @@ /* ** COMMAND: diff ** COMMAND: gdiff ** -** Usage: %fossil diff|gdiff ?-i FILE... +** Usage: %fossil diff|gdiff ?-i ?-r REVISION FILE... ** ** Show the difference between the current version of a file (as it ** exists on disk) and that same file as it was checked out. ** ** diff will show a textual diff while gdiff will attempt to run a @@ -69,18 +69,20 @@ ** %fossil config gdiff-command=meld ** %fossil config gdiff-command=xxdiff ** %fossil config gdiff-command=kdiff3 */ void diff_cmd(void){ - const char *zFile; + const char *zFile, *zRevision; Blob cmd; Blob fname; - int i, internalDiff; - char *zV1 = 0; - char *zV2 = 0; + Blob vname; + Blob record; + int cnt=0,internalDiff; internalDiff = find_option("internal","i",0)!=0; + zRevision = find_option("revision", "r", 1); + verify_all_options(); if( g.argc<3 ){ usage("?OPTIONS? FILE"); } db_must_be_within_tree(); @@ -96,66 +98,48 @@ internalDiff=1; } blob_zero(&cmd); blob_appendf(&cmd, "%s ", zExternalCommand); } - for(i=2; i<g.argc-1; i++){ - const char *z = g.argv[i]; - if( (strcmp(z,"-v")==0 || strcmp(z,"--version")==0) && i<g.argc-2 ){ - if( zV1==0 ){ - zV1 = g.argv[i+1]; - }else if( zV2==0 ){ - zV2 = g.argv[i+1]; - }else{ - fossil_panic("too many versions"); - } - }else{ - if( internalDiff==0 ){ - blob_appendf(&cmd, "%s ", z); - } - } - } zFile = g.argv[g.argc-1]; if( !file_tree_name(zFile, &fname) ){ fossil_panic("unknown file: %s", zFile); } - if( zV1==0 ){ - int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); - Blob record; - Blob vname; - int cnt = 0; + + blob_zero(&vname); + do{ + blob_reset(&vname); + blob_appendf(&vname, "%s~%d", zFile, cnt++); + }while( access(blob_str(&vname),0)==0 ); + if( zRevision==0 ){ + int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); if( rid==0 ){ fossil_panic("no history for file: %b", &fname); } - blob_zero(&vname); - do{ - blob_reset(&vname); - blob_appendf(&vname, "%s~%d", zFile, cnt++); - }while( access(blob_str(&vname),0)==0 ); content_get(rid, &record); - if( internalDiff==1 ){ - Blob current; - Blob out; - blob_zero(¤t); - blob_read_from_file(¤t, zFile); - blob_zero(&out); - unified_diff(&record, ¤t, 5, &out); - printf("%s\n", blob_str(&out)); - blob_reset(¤t); - blob_reset(&out); - }else{ - blob_write_to_file(&record, blob_str(&vname)); - blob_reset(&record); - shell_escape(&cmd, blob_str(&vname)); - blob_appendf(&cmd, " "); - shell_escape(&cmd, zFile); - system(blob_str(&cmd)); - unlink(blob_str(&vname)); - blob_reset(&vname); - blob_reset(&cmd); - } + }else{ + content_get_historical_file(zRevision, zFile, &record); + } + if( internalDiff==1 ){ + Blob out; + Blob current; + blob_zero(¤t); + blob_read_from_file(¤t, zFile); + blob_zero(&out); + unified_diff(&record, ¤t, 5, &out); + printf("%s\n", blob_str(&out)); + blob_reset(¤t); + blob_reset(&out); }else{ - fossil_panic("not yet implemented"); + blob_write_to_file(&record, blob_str(&vname)); + blob_reset(&record); + shell_escape(&cmd, blob_str(&vname)); + blob_appendf(&cmd, " "); + shell_escape(&cmd, zFile); + system(blob_str(&cmd)); + unlink(blob_str(&vname)); + blob_reset(&vname); + blob_reset(&cmd); } blob_reset(&fname); }
Modified src/update.c from [38dd8e9b10] to [1e8d7a1bd1].
@@ -221,39 +221,37 @@ } /* ** COMMAND: revert ** -** Usage: %fossil revert ?-yes FILE +** Usage: %fossil revert ?-yes ?-r REVISION FILE ** ** Revert to the current repository version of FILE. This ** command will confirm your operation, unless you do so ** at the command line via the -yes option. **/ void revert_cmd(void){ const char *zFile; + const char *zRevision; Blob fname; Blob record; Blob ans; - int rid, yesRevert; + int rid = 0, yesRevert; - yesRevert = find_option("yes","y", 0)!=0; + yesRevert = find_option("yes", "y", 0)!=0; + zRevision = find_option("revision", "r", 1); verify_all_options(); if( g.argc<3 ){ usage("?OPTIONS FILE"); } db_must_be_within_tree(); zFile = g.argv[g.argc-1]; + if( !file_tree_name(zFile, &fname) ){ fossil_panic("unknown file: %s", zFile); - } - rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); - - if( rid==0 ){ - fossil_panic("no history for file: %b", &fname); } if( yesRevert==0 ){ char *prompt = mprintf("revert file %B? this will destroy local changes [y/N]? ", &fname); @@ -261,15 +259,25 @@ prompt_user(prompt, &ans); if( blob_str(&ans)[0]=='y' ){ yesRevert = 1; } } - if( yesRevert==1 ){ + + if( yesRevert==1 && zRevision!=0 ){ + content_get_historical_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 ){ blob_write_to_file(&record, blob_str(&fname)); printf("%s reverted\n", blob_str(&fname)); blob_reset(&record); blob_reset(&fname); }else{ printf("revert canceled\n"); } }