dbda8d6ce9 2007-07-21 drh: /* dbda8d6ce9 2007-07-21 drh: ** Copyright (c) 2007 D. Richard Hipp dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This program is free software; you can redistribute it and/or dbda8d6ce9 2007-07-21 drh: ** modify it under the terms of the GNU General Public dbda8d6ce9 2007-07-21 drh: ** License version 2 as published by the Free Software Foundation. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This program is distributed in the hope that it will be useful, dbda8d6ce9 2007-07-21 drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of dbda8d6ce9 2007-07-21 drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dbda8d6ce9 2007-07-21 drh: ** General Public License for more details. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** You should have received a copy of the GNU General Public dbda8d6ce9 2007-07-21 drh: ** License along with this library; if not, write to the dbda8d6ce9 2007-07-21 drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330, dbda8d6ce9 2007-07-21 drh: ** Boston, MA 02111-1307, USA. dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** Author contact information: dbda8d6ce9 2007-07-21 drh: ** drh@hwaci.com dbda8d6ce9 2007-07-21 drh: ** http://www.hwaci.com/drh/ dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ******************************************************************************* dbda8d6ce9 2007-07-21 drh: ** dbda8d6ce9 2007-07-21 drh: ** This file contains code used to check-out versions of the project dbda8d6ce9 2007-07-21 drh: ** from the local repository. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: #include "config.h" dbda8d6ce9 2007-07-21 drh: #include "add.h" dbda8d6ce9 2007-07-21 drh: #include <assert.h> dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: /* dbda8d6ce9 2007-07-21 drh: ** COMMAND: add dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Usage: %fossil add FILE... 6b85fd173e 2008-05-10 drh: ** 6b85fd173e 2008-05-10 drh: ** Make arrangements to add one or more files to the current checkout 6b85fd173e 2008-05-10 drh: ** at the next commit. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void add_cmd(void){ dbda8d6ce9 2007-07-21 drh: int i; dbda8d6ce9 2007-07-21 drh: int vid; dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: db_must_be_within_tree(); dbda8d6ce9 2007-07-21 drh: vid = db_lget_int("checkout",0); dbda8d6ce9 2007-07-21 drh: if( vid==0 ){ dbda8d6ce9 2007-07-21 drh: fossil_panic("no checkout to add to"); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: db_begin_transaction(); dbda8d6ce9 2007-07-21 drh: for(i=2; i<g.argc; i++){ dbda8d6ce9 2007-07-21 drh: char *zName; dbda8d6ce9 2007-07-21 drh: char *zPath; dbda8d6ce9 2007-07-21 drh: Blob pathname; dbda8d6ce9 2007-07-21 drh: int isDir; dbda8d6ce9 2007-07-21 drh: c7278fd013 2007-09-22 jnc: zName = mprintf("%/", g.argv[i]); dbda8d6ce9 2007-07-21 drh: isDir = file_isdir(zName); dbda8d6ce9 2007-07-21 drh: if( isDir==1 ) continue; dbda8d6ce9 2007-07-21 drh: if( isDir==0 ){ 20bcbcf2f2 2007-08-08 drh: fossil_fatal("not found: %s", zName); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: if( isDir==2 && access(zName, R_OK) ){ 20bcbcf2f2 2007-08-08 drh: fossil_fatal("cannot open %s", zName); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: file_tree_name(zName, &pathname); dbda8d6ce9 2007-07-21 drh: zPath = blob_str(&pathname); 20bcbcf2f2 2007-08-08 drh: if( strcmp(zPath, "manifest")==0 || strcmp(zPath, "_FOSSIL_")==0 ){ 20bcbcf2f2 2007-08-08 drh: fossil_fatal("cannot add %s", zPath); da9d38e2c3 2007-10-15 drh: } da9d38e2c3 2007-10-15 drh: if( !file_is_simple_pathname(zPath) ){ da9d38e2c3 2007-10-15 drh: fossil_fatal("filename contains illegal characters: %s", zPath); 20bcbcf2f2 2007-08-08 drh: } dbda8d6ce9 2007-07-21 drh: if( db_exists("SELECT 1 FROM vfile WHERE pathname=%Q", zPath) ){ dbda8d6ce9 2007-07-21 drh: db_multi_exec("UPDATE vfile SET deleted=0 WHERE pathname=%Q", zPath); dbda8d6ce9 2007-07-21 drh: }else{ dbda8d6ce9 2007-07-21 drh: db_multi_exec( dbda8d6ce9 2007-07-21 drh: "INSERT INTO vfile(vid,deleted,rid,mrid,pathname)" dbda8d6ce9 2007-07-21 drh: "VALUES(%d,0,0,0,%Q)", vid, zPath); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: blob_reset(&pathname); dbda8d6ce9 2007-07-21 drh: free(zName); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: db_end_transaction(0); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: /* dbda8d6ce9 2007-07-21 drh: ** COMMAND: rm dbda8d6ce9 2007-07-21 drh: ** COMMAND: del dbda8d6ce9 2007-07-21 drh: ** c9fdb846fb 2007-08-18 drh: ** Usage: %fossil rm FILE... c9fdb846fb 2007-08-18 drh: ** or: %fossil del FILE... dbda8d6ce9 2007-07-21 drh: ** Remove one or more files from the tree. dbda8d6ce9 2007-07-21 drh: */ dbda8d6ce9 2007-07-21 drh: void del_cmd(void){ dbda8d6ce9 2007-07-21 drh: int i; dbda8d6ce9 2007-07-21 drh: int vid; dbda8d6ce9 2007-07-21 drh: dbda8d6ce9 2007-07-21 drh: db_must_be_within_tree(); dbda8d6ce9 2007-07-21 drh: vid = db_lget_int("checkout", 0); dbda8d6ce9 2007-07-21 drh: if( vid==0 ){ dbda8d6ce9 2007-07-21 drh: fossil_panic("no checkout to remove from"); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: db_begin_transaction(); dbda8d6ce9 2007-07-21 drh: for(i=2; i<g.argc; i++){ dbda8d6ce9 2007-07-21 drh: char *zName; dbda8d6ce9 2007-07-21 drh: char *zPath; dbda8d6ce9 2007-07-21 drh: Blob pathname; dbda8d6ce9 2007-07-21 drh: c7278fd013 2007-09-22 jnc: zName = mprintf("%/", g.argv[i]); dbda8d6ce9 2007-07-21 drh: file_tree_name(zName, &pathname); dbda8d6ce9 2007-07-21 drh: zPath = blob_str(&pathname); dbda8d6ce9 2007-07-21 drh: if( !db_exists( dbda8d6ce9 2007-07-21 drh: "SELECT 1 FROM vfile WHERE pathname=%Q AND NOT deleted", zPath) ){ 20bcbcf2f2 2007-08-08 drh: fossil_fatal("not in the repository: %s", zName); dbda8d6ce9 2007-07-21 drh: }else{ dbda8d6ce9 2007-07-21 drh: db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zPath); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: blob_reset(&pathname); dbda8d6ce9 2007-07-21 drh: free(zName); dbda8d6ce9 2007-07-21 drh: } dbda8d6ce9 2007-07-21 drh: db_multi_exec("DELETE FROM vfile WHERE deleted AND rid=0"); dbda8d6ce9 2007-07-21 drh: db_end_transaction(0); dbda8d6ce9 2007-07-21 drh: }