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

Diff for /src/usr.bin/cvs/commit.c between version 1.4 and 1.5

version 1.4, 2004/11/09 21:11:37 version 1.5, 2004/11/09 22:22:47
Line 37 
Line 37 
   
 #include "cvs.h"  #include "cvs.h"
 #include "log.h"  #include "log.h"
   #include "buf.h"
 #include "proto.h"  #include "proto.h"
   
   
 #define CVS_COMMIT_BIGMSG     8000  #define CVS_COMMIT_BIGMSG     32000
 #define CVS_COMMIT_FTMPL      "/tmp/cvsXXXXXXXXXX"  #define CVS_COMMIT_FTMPL      "/tmp/cvsXXXXXXXXXX"
 #define CVS_COMMIT_LOGPREFIX  "CVS:"  #define CVS_COMMIT_LOGPREFIX  "CVS:"
 #define CVS_COMMIT_LOGLINE \  #define CVS_COMMIT_LOGLINE \
Line 68 
Line 69 
         mfile = NULL;          mfile = NULL;
         msg = NULL;          msg = NULL;
   
 #if 0  
         cvs_commit_getmsg(".");          cvs_commit_getmsg(".");
 #endif  
   
         while ((ch = getopt(argc, argv, "F:flm:R")) != -1) {          while ((ch = getopt(argc, argv, "F:flm:R")) != -1) {
                 switch (ch) {                  switch (ch) {
Line 121 
Line 120 
 static char*  static char*
 cvs_commit_openmsg(const char *path)  cvs_commit_openmsg(const char *path)
 {  {
         int fd, ch;          int ch;
         size_t sz;          size_t len;
         char buf[32], *msg;          char lbuf[256], *msg;
         struct stat st;          struct stat st;
           FILE *fp;
           BUF *bp;
   
         if (stat(path, &st) == -1) {          if (stat(path, &st) == -1) {
                 cvs_log(LP_ERRNO, "failed to stat `%s'", path);                  cvs_log(LP_ERRNO, "failed to stat `%s'", path);
Line 141 
Line 142 
                         fprintf(stderr,                          fprintf(stderr,
                             "The specified message file seems big.  "                              "The specified message file seems big.  "
                             "Proceed anyways? (y/n) ");                              "Proceed anyways? (y/n) ");
                         if (fgets(buf, sizeof(buf), stdin) == NULL) {                          if (fgets(lbuf, sizeof(lbuf), stdin) == NULL) {
                                 cvs_log(LP_ERRNO,                                  cvs_log(LP_ERRNO,
                                     "failed to read from standard input");                                      "failed to read from standard input");
                                 return (NULL);                                  return (NULL);
                         }                          }
   
                         sz = strlen(buf);                          len = strlen(lbuf);
                         if ((sz == 0) || (sz > 2) ||                          if ((len == 0) || (len > 2) ||
                             ((buf[sz] != 'y') && (buf[sz] != 'n'))) {                              ((lbuf[0] != 'y') && (lbuf[0] != 'n'))) {
                                 fprintf(stderr, "invalid input\n");                                  fprintf(stderr, "invalid input\n");
                                 continue;                                  continue;
                         }                          }
                         else if (buf[sz] == 'y')                          else if (lbuf[0] == 'y')
                                 break;                                  break;
                         else if (buf[sz] == 'n') {                          else if (lbuf[0] == 'n') {
                                 cvs_log(LP_ERR, "aborted by user");                                  cvs_log(LP_ERR, "aborted by user");
                                 return (NULL);                                  return (NULL);
                         }                          }
Line 163 
Line 164 
                 } while (1);                  } while (1);
         }          }
   
         sz = st.st_size + 1;          if ((fp = fopen(path, "r")) == NULL) {
                   cvs_log(LP_ERRNO, "failed to open message file `%s'", path);
         msg = (char *)malloc(sz);  
         if (msg == NULL) {  
                 cvs_log(LP_ERRNO, "failed to allocate message buffer");  
                 return (NULL);                  return (NULL);
         }          }
   
         fd = open(path, O_RDONLY, 0);          bp = cvs_buf_alloc(128, BUF_AUTOEXT);
         if (fd == -1) {          if (bp == NULL) {
                 cvs_log(LP_ERRNO, "failed to open message file `%s'", path);  
                 return (NULL);                  return (NULL);
         }          }
   
         if (read(fd, msg, sz - 1) == -1) {          while (fgets(lbuf, sizeof(lbuf), fp) != NULL) {
                 cvs_log(LP_ERRNO, "failed to read CVS commit message");                  len = strlen(lbuf);
                 return (NULL);                  if (len == 0)
                           continue;
   
                   /* skip lines starting with the prefix */
                   if (strncmp(lbuf, CVS_COMMIT_LOGPREFIX,
                       strlen(CVS_COMMIT_LOGPREFIX)) == 0)
                           continue;
   
                   cvs_buf_append(bp, lbuf, strlen(lbuf));
         }          }
         msg[sz - 1] = '\0';          cvs_buf_putc(bp, '\0');
   
           msg = (char *)cvs_buf_release(bp);
   
         return (msg);          return (msg);
 }  }
   
Line 199 
Line 206 
 cvs_commit_getmsg(const char *dir)  cvs_commit_getmsg(const char *dir)
 {  {
         int ret, fd, argc, fds[3];          int ret, fd, argc, fds[3];
         char *argv[4], path[MAXPATHLEN], *msg;          size_t len;
           char *argv[4], buf[16], path[MAXPATHLEN], *msg;
         FILE *fp;          FILE *fp;
           struct stat st1, st2;
   
           msg = NULL;
         fds[0] = -1;          fds[0] = -1;
         fds[1] = -1;          fds[1] = -1;
         fds[2] = -1;          fds[2] = -1;
Line 219 
Line 229 
         fp = fdopen(fd, "w");          fp = fdopen(fd, "w");
         if (fp == NULL) {          if (fp == NULL) {
                 cvs_log(LP_ERRNO, "failed to fdopen");                  cvs_log(LP_ERRNO, "failed to fdopen");
                 exit(1);  
         } else {          } else {
                 fprintf(fp,                  fprintf(fp,
                     "\n%s %s\n%s Enter Log.  Lines beginning with `%s' are "                      "\n%s %s\n%s Enter Log.  Lines beginning with `%s' are "
Line 236 
Line 245 
                     CVS_COMMIT_LOGLINE);                      CVS_COMMIT_LOGLINE);
         }          }
         (void)fflush(fp);          (void)fflush(fp);
         (void)fclose(fp);  
   
         do {          if (fstat(fd, &st1) == -1) {
                 ret = cvs_exec(argc, argv, fds);                  cvs_log(LP_ERRNO, "failed to stat log message file");
                 if (ret == -1) {  
                         fprintf(stderr,  
                             "Log message unchanged or not specified\n"  
                             "a)bort, c)ontinue, e)dit, !)reuse this message "  
                             "unchanged for remaining dirs\nAction: () ");  
   
                         ret = getchar();                  (void)fclose(fp);
                         if (ret == 'a') {                  if (unlink(path) == -1)
                                 cvs_log(LP_ERR, "aborted by user");                          cvs_log(LP_ERRNO, "failed to unlink log file %s", path);
                                 break;                  return (NULL);
                         } else if (ret == 'c') {          }
                         } else if (ret == 'e') {  
                         } else if (ret == '!') {          for (;;) {
                         }                  ret = cvs_exec(argc, argv, fds);
                   if (ret == -1)
                           break;
                   if (fstat(fd, &st2) == -1) {
                           cvs_log(LP_ERRNO, "failed to stat log message file");
                           break;
                 }                  }
         } while (0);  
   
         (void)close(fd);                  if (st2.st_mtime != st1.st_mtime)
                           break;
   
         return (msg);                  /* nothing was entered */
 }                  fprintf(stderr,
                       "Log message unchanged or not specified\na)bort, "
                       "c)ontinue, e)dit, !)reuse this message unchanged "
                       "for remaining dirs\nAction: (continue) ");
   
                   if (fgets(buf, sizeof(buf), stdin) == NULL) {
                           cvs_log(LP_ERRNO, "failed to read from standard input");
                           break;
                   }
   
 /*                  len = strlen(buf);
  * cvs_commit_gettmpl()                  if ((len == 0) || (len > 2)) {
  *                          fprintf(stderr, "invalid input\n");
  * Get the template to display when invoking the editor to get a commit                          continue;
  * message.                  }
  */                  else if (buf[0] == 'a') {
                           cvs_log(LP_ERR, "aborted by user");
                           break;
                   } else if ((buf[0] == '\n') || (buf[0] == 'c')) {
                           /* empty message */
                           msg = strdup("");
                           break;
                   } else if (ret == 'e')
                           continue;
                   else if (ret == '!') {
                           /* XXX do something */
                   }
           }
   
 cvs_commit_gettmpl(void)          (void)fclose(fp);
 {          (void)close(fd);
   
           if (unlink(path) == -1)
                   cvs_log(LP_ERRNO, "failed to unlink log file %s", path);
   
           return (msg);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5