[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.14 and 1.15

version 1.14, 2005/05/20 20:00:53 version 1.15, 2005/05/24 04:12:25
Line 25 
Line 25 
  */   */
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/queue.h>  #include <sys/stat.h>
   
 #include <err.h>  
 #include <dirent.h>  
 #include <errno.h>  #include <errno.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 43 
Line 41 
   
 #define CVS_IMPORT_DEFBRANCH    "1.1.1"  #define CVS_IMPORT_DEFBRANCH    "1.1.1"
   
 int cvs_import_options(char *, int, char **, int *);  static int cvs_import_init     (struct cvs_cmd *, int, char **, int *);
 int cvs_import_sendflags(struct cvsroot *);  static int cvs_import_pre_exec (struct cvsroot *);
 int cvs_import_file(CVSFILE *, void *);  static int cvs_import_remote   (CVSFILE *, void *);
   static int cvs_import_local    (CVSFILE *, void *);
   
 static RCSNUM *bnum;  static RCSNUM *bnum;
 static char *branch, *module, *vendor, *release;  static char *branch, *module, *vendor, *release;
   
 struct cvs_cmd_info cvs_import = {  struct cvs_cmd cvs_cmd_import = {
         cvs_import_options,          CVS_OP_IMPORT, CVS_REQ_IMPORT, "import",
         cvs_import_sendflags,          { "im", "imp" },
         cvs_import_file,          "Import sources into CVS, using vendor branches",
         NULL, NULL,          "[-d] [-b branch] [-I ign] [-k subst] [-m msg] repository "
           "vendor-tag release-tags ...",
           "b:dI:k:m:",
           NULL,
         CF_RECURSE | CF_IGNORE | CF_NOSYMS,          CF_RECURSE | CF_IGNORE | CF_NOSYMS,
         CVS_REQ_IMPORT,          cvs_import_init,
           cvs_import_pre_exec,
           cvs_import_remote,
           cvs_import_local,
           NULL,
           NULL,
         CVS_CMD_SENDDIR          CVS_CMD_SENDDIR
 };  };
   
 int  static int
 cvs_import_options(char *opt, int argc, char **argv, int *arg)  cvs_import_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
 {  {
         int ch;          int ch;
   
         branch = CVS_IMPORT_DEFBRANCH;          branch = CVS_IMPORT_DEFBRANCH;
   
         while ((ch = getopt(argc, argv, opt)) != -1) {          while ((ch = getopt(argc, argv, cmd->cmd_opts)) != -1) {
                 switch (ch) {                  switch (ch) {
                 case 'b':                  case 'b':
                         branch = optarg;                          branch = optarg;
Line 103 
Line 110 
   
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
         *arg = optind;  
   
         if (argc > 4)          if (argc != 3)
                 return (CVS_EX_USAGE);                  return (CVS_EX_USAGE);
   
         module = argv[0];          module = argv[0];
         vendor = argv[1];          vendor = argv[1];
         release = argv[2];          release = argv[2];
   
           *arg = optind + 3;
   
           cvs_msg = "test\n";
   #if 0
         if ((cvs_msg == NULL) &&          if ((cvs_msg == NULL) &&
             (cvs_msg = cvs_logmsg_get(NULL, NULL, NULL, NULL)) == NULL)              (cvs_msg = cvs_logmsg_get(NULL, NULL, NULL, NULL)) == NULL)
                 return (CVS_EX_DATA);                  return (CVS_EX_DATA);
   #endif
   
         return (0);          return (0);
 }  }
   
 int  static int
 cvs_import_sendflags(struct cvsroot *root)  cvs_import_pre_exec(struct cvsroot *root)
 {  {
         if ((cvs_sendarg(root, "-b", 0) < 0) ||          char repodir[MAXPATHLEN];
             (cvs_sendarg(root, branch, 0) < 0) ||  
             (cvs_logmsg_send(root, cvs_msg) < 0) ||  
             (cvs_sendarg(root, module, 0) < 0) ||  
             (cvs_sendarg(root, vendor, 0) < 0) ||  
             (cvs_sendarg(root, release, 0) < 0))  
                 return (CVS_EX_PROTO);  
   
           if (root->cr_method == CVS_METHOD_LOCAL) {
                   snprintf(repodir, sizeof(repodir), "%s/%s", root->cr_dir,
                       module);
                   mkdir(repodir, 0700);
           } else {
                   if ((cvs_sendarg(root, "-b", 0) < 0) ||
                       (cvs_sendarg(root, branch, 0) < 0) ||
                       (cvs_logmsg_send(root, cvs_msg) < 0) ||
                       (cvs_sendarg(root, module, 0) < 0) ||
                       (cvs_sendarg(root, vendor, 0) < 0) ||
                       (cvs_sendarg(root, release, 0) < 0))
                           return (CVS_EX_PROTO);
           }
   
         return (0);          return (0);
 }  }
   
 /*  /*
  * cvs_import_file()   * cvs_import_remote()
  *   *
  * Perform the import of a single file or directory.   * Perform the import of a single file or directory.
  */   */
 int  static int
 cvs_import_file(CVSFILE *cfp, void *arg)  cvs_import_remote(CVSFILE *cf, void *arg)
 {  {
         int l;          int len;
         struct cvsroot *root;          struct cvsroot *root;
         char fpath[MAXPATHLEN], repodir[MAXPATHLEN];          char fpath[MAXPATHLEN], repodir[MAXPATHLEN];
         char repo[MAXPATHLEN];          char repo[MAXPATHLEN];
   
         root = CVS_DIR_ROOT(cfp);          root = CVS_DIR_ROOT(cf);
         l = snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, module);          len = snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, module);
         if (l == -1 || l >= (int)sizeof(repo)) {          if (len == -1 || len >= (int)sizeof(repo)) {
                 errno = ENAMETOOLONG;                  errno = ENAMETOOLONG;
                 cvs_log(LP_ERRNO, "%s", repo);                  cvs_log(LP_ERRNO, "%s", repo);
                 return (CVS_EX_DATA);                  return (CVS_EX_DATA);
         }          }
   
         cvs_file_getpath(cfp, fpath, sizeof(fpath));          cvs_file_getpath(cf, fpath, sizeof(fpath));
         printf("Importing %s\n", fpath);  
   
         if (cfp->cf_type == DT_DIR) {          if (cf->cf_type == DT_DIR) {
                 if (!strcmp(CVS_FILE_NAME(cfp), "."))                  if (!strcmp(cf->cf_name, "."))
                         strlcpy(repodir, repo, sizeof(repodir));                          strlcpy(repodir, repo, sizeof(repodir));
                 else {                  else {
                         l = snprintf(repodir, sizeof(repodir), "%s/%s",                          len = snprintf(repodir, sizeof(repodir), "%s/%s",
                             repo, fpath);                              repo, fpath);
                         if (l == -1 || l >= (int)sizeof(repodir)) {                          if (len == -1 || len >= (int)sizeof(repodir)) {
                                 errno = ENAMETOOLONG;                                  errno = ENAMETOOLONG;
                                 cvs_log(LP_ERRNO, "%s", repodir);                                  cvs_log(LP_ERRNO, "%s", repodir);
                                 return (CVS_EX_DATA);                                  return (CVS_EX_DATA);
                         }                          }
                 }                  }
                 if (root->cr_method != CVS_METHOD_LOCAL) {  
                         if (cvs_sendreq(root, CVS_REQ_DIRECTORY, fpath) < 0)                  if (cvs_sendreq(root, CVS_REQ_DIRECTORY, fpath) < 0)
                                 return (CVS_EX_PROTO);                          return (CVS_EX_PROTO);
                         if (cvs_sendln(root, repodir) < 0)                  if (cvs_sendln(root, repodir) < 0)
                                 return (CVS_EX_PROTO);                          return (CVS_EX_PROTO);
                 } else {                  return (0);
                         /* create the directory */          }
   
           if (cvs_sendreq(root, CVS_REQ_MODIFIED, cf->cf_name) < 0)
                   return (CVS_EX_PROTO);
           if (cvs_sendfile(root, fpath) < 0)
                   return (CVS_EX_PROTO);
   
           return (0);
   }
   
   
   /*
    * cvs_import_local()
    *
    */
   static int
   cvs_import_local(CVSFILE *cf, void *arg)
   {
           int len;
           struct cvsroot *root;
           char fpath[MAXPATHLEN], rpath[MAXPATHLEN], repo[MAXPATHLEN];
           RCSFILE *rf;
   
           root = CVS_DIR_ROOT(cf);
           len = snprintf(repo, sizeof(repo), "%s/%s", root->cr_dir, module);
           if (len == -1 || len >= (int)sizeof(repo)) {
                   errno = ENAMETOOLONG;
                   cvs_log(LP_ERRNO, "%s", repo);
                   return (CVS_EX_DATA);
           }
   
           cvs_file_getpath(cf, fpath, sizeof(fpath));
   
           if (cf->cf_type == DT_DIR) {
                   if (!strcmp(cf->cf_name, "."))
                           strlcpy(rpath, repo, sizeof(rpath));
                   else {
                           len = snprintf(rpath, sizeof(rpath), "%s/%s",
                               repo, fpath);
                           if (len == -1 || len >= (int)sizeof(rpath)) {
                                   errno = ENAMETOOLONG;
                                   cvs_log(LP_ERRNO, "%s", rpath);
                                   return (CVS_EX_DATA);
                           }
   
                           cvs_printf("Importing %s\n", rpath);
                           if (mkdir(rpath, 0700) == -1) {
                                   cvs_log(LP_ERRNO, "failed to create %s",
                                       rpath);
                           }
                 }                  }
   
                 return (0);                  return (0);
         }          }
   
         if (root->cr_method != CVS_METHOD_LOCAL) {          snprintf(rpath, sizeof(rpath), "%s/%s%s",
                 if (cvs_sendreq(root, CVS_REQ_MODIFIED, CVS_FILE_NAME(cfp)) < 0)              repo, fpath, RCS_FILE_EXT);
                         return (CVS_EX_PROTO);  
                 if (cvs_sendfile(root, fpath) < 0)          printf("importing file in %s\n", rpath);
                         return (CVS_EX_PROTO);          cvs_printf("N %s\n", fpath);
         } else {  
                 /* local import */          rf = rcs_open(rpath, RCS_RDWR|RCS_CREATE);
           if (rf == NULL) {
         }          }
   
         return (0);          rcs_close(rf);
   
           return (CVS_EX_OK);
 }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15