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

Diff for /src/usr.bin/cvs/release.c between version 1.21 and 1.22

version 1.21, 2005/08/10 14:49:20 version 1.22, 2005/09/21 16:55:28
Line 54 
Line 54 
         "[-d]",          "[-d]",
         "d",          "d",
         NULL,          NULL,
         0,          CF_NOFILES,
         cvs_release_init,          cvs_release_init,
         cvs_release_pre_exec,          cvs_release_pre_exec,
         cvs_release_dir,          cvs_release_dir,
Line 138 
Line 138 
 {  {
         FILE *fp;          FILE *fp;
         int j, l;          int j, l;
         size_t len;  
         char *wdir, cwd[MAXPATHLEN];          char *wdir, cwd[MAXPATHLEN];
         char cdpath[MAXPATHLEN], dpath[MAXPATHLEN];          char buf[256], dpath[MAXPATHLEN], updcmd[1024];
         char buf[256], updcmd[1024];  
         struct stat st;          struct stat st;
         struct cvsroot *root;          struct cvsroot *root;
   
         j = 0;          /* number of altered files in the working copy */          j = 0;
   
         root = CVS_DIR_ROOT(cf);          root = CVS_DIR_ROOT(cf);
   
           /* XXX kept for compat reason of `cvs update' output */
           /* save current working directory for further use */
           if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL) {
                   cvs_log(LP_ERRNO, "cannot get current dir");
                   return (CVS_EX_FILE);
           }
   
         cvs_file_getpath(cf, dpath, sizeof(dpath));          cvs_file_getpath(cf, dpath, sizeof(dpath));
   
         len = cvs_path_cat(dpath, CVS_PATH_CVSDIR, cdpath, sizeof(cdpath));  
         if (len >= sizeof(cdpath))  
                 return (CVS_EX_DATA);  
   
         if (cf->cf_type == DT_DIR) {          if (cf->cf_type == DT_DIR) {
                 if (!strcmp(cf->cf_name, "."))                  if (!strcmp(cf->cf_name, "."))
                         return (0);                          return (0);
                 else {  
                         /* test if dir has CVS/ directory */                  /* chdir before running the `cvs update' command */
                         if (stat(cdpath, &st) == -1) {                  if (cvs_chdir(dpath) == -1)
                                 if (verbosity > 0)                          return (CVS_EX_FILE);
                                         cvs_log(LP_ERR,  
                                             "no repository directory: %s",                  /* test if dir has CVS/ directory */
                                             dpath);                  if (stat(CVS_PATH_CVSDIR, &st) == -1) {
                                 return (0);                          if (verbosity > 0)
                         }                                  cvs_log(LP_ERR,
                                       "no repository directory: %s", dpath);
                           return (0);
                 }                  }
           } else {
                   if (verbosity > 0)
                           cvs_log(LP_ERR, "no such directory: %s", dpath);
                   return (0);
           }
   
                 if (root->cr_method != CVS_METHOD_LOCAL) {          /* construct `cvs update' command */
                         /* XXX kept for compat reason of `cvs update' output */          l = snprintf(updcmd, sizeof(updcmd), "%s %s %s update",
                         /* save current working directory for further use */              __progname, UPDCMD_FLAGS, root->cr_str);
                         if ((wdir = getcwd(cwd, sizeof(cwd))) == NULL)          if (l == -1 || l >= (int)sizeof(updcmd))
                                 cvs_log(LP_ERRNO, "cannot get current dir");                  return (CVS_EX_DATA);
   
                         /* change dir before running the `cvs update' command */          /* XXX we should try to avoid a new connection ... */
                         if (cvs_chdir(dpath) == -1)          cvs_log(LP_TRACE, "cvs_release_dir() popen(%s,r)", updcmd);
                                 return (CVS_EX_FILE);          if ((fp = popen(updcmd, "r")) == NULL) {
                   cvs_log(LP_ERR, "cannot run command `%s'", updcmd);
                   return (CVS_EX_DATA);
           }
   
                         /* construct `cvs update' command */          while (fgets(buf, (int)sizeof(buf), fp) != NULL) {
                         l = snprintf(updcmd, sizeof(updcmd), "%s %s %s update",                  if (strchr("ACMPRU", buf[0]))
                             __progname, UPDCMD_FLAGS, root->cr_str);                          j++;
                         if (l == -1 || l >= (int)sizeof(updcmd))                  (void)fputs(buf, stdout);
                                 return (CVS_EX_DATA);          }
   
                         /* XXX we should try to avoid a new connection ... */          if (pclose(fp) != 0) {
                         if ((fp = popen(updcmd, "r")) == NULL) {                  cvs_log(LP_ERR, "unable to release `%s'", dpath);
                                 cvs_log(LP_ERR, "cannot run command `%s'",  
                                     updcmd);  
                                 return (CVS_EX_DATA);  
                         }  
   
                         while (fgets(buf, (int)sizeof(buf), fp) != NULL) {                  /* change back to original working dir */
                                 if (strchr("ACMPRU", buf[0]))                  if (cvs_chdir(wdir) == -1)
                                         j++;                          return (CVS_EX_FILE);
                                 (void)fputs(buf, stdout);          }
                         }  
   
                         if (pclose(fp) != 0) {          printf("You have [%d] altered file%s in this repository.\n",
                                 cvs_log(LP_ERR, "unable to release `%s'",              j, j > 1 ? "s" : "");
                                     dpath);          while (fgets(buf, (int)sizeof(buf), fp) != NULL) {
                                 return (CVS_EX_DATA);                  if (strchr("ACMPRU", buf[0]))
                         }                          j++;
                   (void)fputs(buf, stdout);
           }
   
                         printf("You have [%d] altered file%s in this "          printf("Are you sure you want to release %sdirectory `%s': ",
                             "repository.\n", j, j > 1 ? "s" : "");              dflag ? "(and delete) " : "", dpath);
   
                         printf("Are you sure you want to release "          if (cvs_release_yesno() == -1) {        /* No */
                             "%sdirectory `%s': ",                  fprintf(stderr,
                             dflag ? "(and delete) " : "", dpath);                      "** `%s' aborted by user choice.\n", cvs_command);
   
                         if (cvs_release_yesno() == -1) {        /* No */                  /* change back to original working dir */
                                 (void)fprintf(stderr,                  if (cvs_chdir(wdir) == -1)
                                     "** `%s' aborted by user choice.\n",                          return (CVS_EX_FILE);
                                     cvs_command);  
                                 return (-1);  
                         }  
   
                         /* change back to original working dir */                  return (-1);
                         if (cvs_chdir(wdir) == -1)          }
                                 return (CVS_EX_FILE);  
   
                         if (dflag == 1) {          /* change back to original working dir */
                                 if (cvs_rmdir(dpath) != 0)          if (cvs_chdir(wdir) == -1)
                                         return (CVS_EX_FILE);                  return (CVS_EX_FILE);
                         }  
                 }          if (dflag == 1) {
         } else {                  if (cvs_rmdir(dpath) != 0)
                 if (verbosity > 0)                          return (CVS_EX_FILE);
                         cvs_log(LP_ERR, "no such directory: %s", dpath);  
                 return (CVS_EX_DATA);  
         }          }
   
         return (0);          return (0);

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22