00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include <stdlib.h>
00010 #include <fcntl.h>
00011 #include <unistd.h>
00012 #include <time.h>
00013 #include <ctype.h>
00014 #include <sys/select.h>
00015 
00016 #include "url.h"
00017 #include "waa.h"
00018 #include "helper.h"
00019 #include "commit.h"
00020 #include "export.h"
00021 
00022 
00068 int co__work(struct estat *root, int argc, char *argv[])
00069 {
00070     int status;
00071     int l;
00072     char *path;
00073     time_t delay_start;
00074 
00075 
00076     path=NULL;
00077 
00078     
00079     STOPIF( url__allocate(argc+1), NULL);
00080     
00081     for(l=0; l<argc; l++)
00082     {
00083         DEBUGP("parsing %s into %d", argv[l], urllist_count);
00084         
00085         
00086 
00087         make_STOP_silent++;
00088         status=url__insert_or_replace(argv[l], NULL, NULL);
00089         make_STOP_silent--;
00090         if (status == EINVAL)
00091         {
00092             
00093             STOPIF_CODE_ERR(path, EINVAL,
00094                     "!Two non-URLs were given:\n"
00095                     "  %s\n"
00096                     "and\n"
00097                     "  %s\n"
00098                     "but this action accepts only a single path.",
00099                     path, argv[l]);
00100 
00101             path=argv[l];
00102         }
00103     }
00104 
00105     STOPIF_CODE_ERR( urllist_count==0, EINVAL,
00106             "!Need at least a single URL to checkout from.");
00107 
00108     if (path)
00109         STOPIF_CODE_ERR( chdir(path)==-1, errno,
00110                 "!Cannot use the directory \"%s\";\nmaybe you meant to give an URL?", path);
00111 
00112 
00113     root->arg=path ? path : ".";
00114 
00115     STOPIF( waa__save_cwd( &path, NULL, 0), NULL);
00116     STOPIF( waa__create_working_copy(path), NULL);
00117     free(path);
00118 
00119     
00120 
00121     for(l=0; l<urllist_count; l++)
00122     {
00123         STOPIF( exp__do(root, urllist[l]), NULL);
00124 
00125         urllist[l]->current_rev = target_revision;
00126         STOPIF( ci__set_revision(root, target_revision), NULL);
00127         printf("Checked out %s at revision\t%ld.\n", 
00128                 urllist[l]->url, urllist[l]->current_rev);
00129     }
00130 
00131     
00132     delay_start=time(NULL);
00133     STOPIF( url__output_list(), NULL);
00134     STOPIF( waa__output_tree(root), NULL);
00135     STOPIF( hlp__delay(delay_start, DELAY_CHECKOUT), NULL);
00136 
00137 ex:
00138     return status;
00139 }
00140 
00141