[BACK]Return to import.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Diff for /src/usr.bin/cvs/import.c between version 1.2 and 1.3

version 1.2, 2004/12/07 17:10:56 version 1.3, 2005/01/06 19:56:38
Line 36 
Line 36 
 #include <string.h>  #include <string.h>
 #include <sysexits.h>  #include <sysexits.h>
   
 #include "cvs.h"  
 #include "log.h"  #include "log.h"
 #include "file.h"  #include "file.h"
   #include "cvs.h"
 #include "proto.h"  #include "proto.h"
   
 static int do_import(struct cvsroot *, char **);  
 static int cvs_import_dir(struct cvsroot *, char *, char *);  
 static int cvs_import_file(struct cvsroot *, CVSFILE *);  
   
   #define CVS_IMPORT_DEFBRANCH    "1.1.1"
   
   
   
   int cvs_import_file(CVSFILE *, void *);
   char repo[MAXPATHLEN];
   
 /*  /*
  * cvs_import()   * cvs_import()
  *   *
Line 54 
Line 58 
 cvs_import(int argc, char **argv)  cvs_import(int argc, char **argv)
 {  {
         int ch, flags;          int ch, flags;
         char *repo, *vendor, *release;          char *branch, *ep;
         struct cvsroot *root;          struct cvsroot *root;
           RCSNUM *bnum;
   
         flags = CF_IGNORE|CF_NOSYMS;          branch = CVS_IMPORT_DEFBRANCH;
           flags = CF_RECURSE | CF_IGNORE | CF_NOSYMS;
   
         while ((ch = getopt(argc, argv, "b:dI:k:m:")) != -1) {          while ((ch = getopt(argc, argv, "b:dI:k:m:")) != -1) {
                 switch (ch) {                  switch (ch) {
                 case 'b':                  case 'b':
                           branch = optarg;
                           if ((bnum = rcsnum_alloc()) == NULL)
                                   return (-1);
                           if ((rcsnum_aton(branch, &ep, bnum) < 0) ||
                               (*ep != '\0')) {
                                   cvs_log(LP_ERR, "%s is not a numeric branch",
                                       branch);
                                   return (EX_USAGE);
                           }
                           break;
                 case 'd':                  case 'd':
                         break;                          break;
                 case 'I':                  case 'I':
Line 91 
Line 107 
                 return (EX_DATAERR);                  return (EX_DATAERR);
   
         root = CVS_DIR_ROOT(cvs_files);          root = CVS_DIR_ROOT(cvs_files);
         if (root->cr_method != CVS_METHOD_LOCAL) {          if (root == NULL) {
                 cvs_connect(root);                  cvs_log(LP_ERR,
                       "No CVSROOT specified!  Please use the `-d' option");
                 /* Do it */                  cvs_log(LP_ERR,
                 do_import(root, argv);                      "or set the CVSROOT environment variable.");
                   return (EX_USAGE);
                 cvs_disconnect(root);  
         }          }
   
         return (0);          if ((cvs_msg == NULL) &&
 }              (cvs_msg = cvs_logmsg_get(NULL, NULL, NULL, NULL)) == NULL)
   
 /*  
  * Import a module using a server  
  */  
 static int  
 do_import(struct cvsroot *root, char **argv)  
 {  
         char repository[MAXPATHLEN];  
   
         /* XXX temporary */  
         if (cvs_sendarg(root, "-m testlog", 0) < 0) {  
                 cvs_log(LP_ERR, "failed to send temporary logmessage");  
                 return (-1);                  return (-1);
         }  
   
         /* send arguments */          if (root->cr_method != CVS_METHOD_LOCAL) {
         if (cvs_sendarg(root, argv[0], 0) < 0 ||                  if ((cvs_connect(root) < 0) ||
             cvs_sendarg(root, argv[1], 0) < 0 ||                      (cvs_sendarg(root, "-b", 0) < 0) ||
             cvs_sendarg(root, argv[2], 0) < 0) {                      (cvs_sendarg(root, branch, 0) < 0) ||
                 cvs_log(LP_ERR, "failed to send arguments");                      (cvs_logmsg_send(root, cvs_msg) < 0) ||
                 return (-1);                      (cvs_sendarg(root, argv[0], 0) < 0) ||
                       (cvs_sendarg(root, argv[1], 0) < 0) ||
                       (cvs_sendarg(root, argv[2], 0) < 0))
                           return (EX_PROTOCOL);
         }          }
   
         /* create the repository name */          snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, argv[0]);
         snprintf(repository, sizeof(repository), "%s/%s",          cvs_file_examine(cvs_files, cvs_import_file, NULL);
             root->cr_dir, argv[0]);  
   
         cvs_files = cvs_file_get(".", 0);          if (root->cr_method != CVS_METHOD_LOCAL) {
         if (cvs_files == NULL) {                  if (cvs_senddir(root, cvs_files) < 0 ||
                 cvs_log(LP_ERR, "failed to obtain info on root");                      cvs_sendreq(root, CVS_REQ_IMPORT, NULL) < 0)
                 return (-1);                          return (EX_PROTOCOL);
         }          }
   
         /* walk the root directory */  
         cvs_import_dir(root, ".", repository);  
   
         /* send import request */  
         if (cvs_senddir(root, cvs_files) < 0 ||  
             cvs_sendraw(root, repository, strlen(repository) < 0 ||  
             cvs_sendraw(root, "\n", 1) < 0 ||  
             cvs_sendreq(root, CVS_REQ_IMPORT, NULL) < 0))  
                 cvs_log(LP_ERR, "failed to import repository %s",  
                     repository);  
   
   
         /* done */  
         return (0);          return (0);
 }  }
   
 static int  /*
 cvs_import_dir(struct cvsroot *root, char *dirname, char *repo)   * cvs_import_file()
    *
    * Perform the import of a single file or directory.
    */
   int
   cvs_import_file(CVSFILE *cfp, void *arg)
 {  {
         char *cwd;          int ret;
         char *basedir;          struct cvsroot *root;
         char cvsdir[MAXPATHLEN];          char fpath[MAXPATHLEN], repodir[MAXPATHLEN];
         CVSFILE *parent, *fp;  
   
         if ((basedir = strrchr(dirname, '/')) != NULL)          root = CVS_DIR_ROOT(cfp);
                 basedir++;  
         else  
                 basedir = dirname;  
   
         /* save current directory */          cvs_file_getpath(cfp, fpath, sizeof(fpath));
         if ((cwd = getcwd(NULL, MAXPATHLEN)) == NULL) {          printf("Importing %s\n", fpath);
                 cvs_log(LP_ERR, "couldn't save current directory");  
                 return (-1);  
         }  
   
         /* Switch to the new directory */          if (cfp->cf_type == DT_DIR) {
         if (chdir(basedir) < 0) {                  if (!strcmp(CVS_FILE_NAME(cfp), "."))
                 cvs_log(LP_ERR, "failed to switch to directory %s", dirname);                          strlcpy(repodir, repo, sizeof(repodir));
                 return (-1);  
         }  
   
         if (!strcmp(dirname, "."))  
                 strlcpy(cvsdir, repo, sizeof(cvsdir));  
         else  
                 snprintf(cvsdir, sizeof(cvsdir), "%s/%s", repo, dirname);  
   
         /* Obtain information about the directory */  
         parent = cvs_file_get(".", CF_SORT|CF_RECURSE|CF_IGNORE);  
         if (parent == NULL) {  
                 cvs_log(LP_ERR, "couldn't obtain info on %s", dirname);  
                 return (-1);  
         }  
   
         if (cvs_sendreq(root, CVS_REQ_DIRECTORY, dirname) < 0 ||  
             cvs_sendraw(root, cvsdir, strlen(cvsdir)) < 0 ||  
             cvs_sendraw(root, "\n", 1) < 0)  
                 return (-1);  
   
         printf("Importing %s\n", dirname);  
   
         /* Walk the directory */  
         TAILQ_FOREACH(fp, &(parent->cf_ddat->cd_files), cf_list) {  
                 /* If we have a sub directory, skip it for now */  
                 if (fp->cf_type == DT_DIR)  
                         continue;  
   
                 /* Import the file */  
                 if (cvs_import_file(root, fp) < 0)  
 #if 0  
                         cvs_log(LP_ERR, "failed to import %s", fp->cf_path);  
 #else  
                         cvs_log(LP_ERR, "failed to import %s", NULL);  
 #endif  
         }  
   
         /* Walk the subdirectories */  
         TAILQ_FOREACH(fp, &(parent->cf_ddat->cd_files), cf_list) {  
                 if (fp->cf_type != DT_DIR)  
                         continue;  
                 if (!strcmp(CVS_FILE_NAME(fp), ".") ||  
                     !strcmp(CVS_FILE_NAME(fp), ".."))  
                         continue;  
   
                 if (strcmp(dirname, "."))  
                         snprintf(cvsdir, sizeof(cvsdir), "%s/%s",  
                             dirname, CVS_FILE_NAME(fp));  
                 else                  else
                         strlcpy(cvsdir, CVS_FILE_NAME(fp), sizeof(cvsdir));                          snprintf(repodir, sizeof(repodir), "%s/%s", repo, fpath);
                 if (cvs_import_dir(root, cvsdir, repo) < 0)                  if (root->cr_method != CVS_METHOD_LOCAL) {
                         cvs_log(LP_ERR, "failed to import directory %s",                          ret = cvs_sendreq(root, CVS_REQ_DIRECTORY, fpath);
                             CVS_FILE_NAME(fp));                          if (ret == 0)
         }                                  ret = cvs_sendln(root, repodir);
                   } else {
                           /* create the directory */
                   }
   
         cvs_file_free(parent);                  return (0);
   
         /* restore working directory */  
         if (chdir(cwd) < 0) {  
                 cvs_log(LP_ERR, "failed to restore directory %s", cwd);  
                 return (-1);  
         }          }
   
         return (0);          if (root->cr_method != CVS_METHOD_LOCAL) {
 }                  if (cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cfp)) < 0)
                           return (-1);
 /*                  if (cvs_sendfile(root, fpath) < 0)
  * Import a file                          return (-1);
  */          } else {
 static int                  /* local import */
 cvs_import_file(struct cvsroot *root, CVSFILE *fp)          }
 {  
         /* Send a Modified response follwed by the  
          * file's mode, length and contents  
          */  
         if (cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(fp)) < 0)  
                 return (-1);  
         if (cvs_sendfile(root, CVS_FILE_NAME(fp)) < 0)  
                 return (-1);  
   
         return (0);          return (0);
 }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3