help-gnats
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: broken behavior from pr-edit


From: Dan Martinez
Subject: Re: broken behavior from pr-edit
Date: 12 Nov 2001 11:05:21 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Cuyahoga Valley)

Milan Zamazal wrote:

> >>>>> "DB" == Dirk Bergstrom <address@hidden> writes:
> 
>     DB> we've come across a problem with pr-edit.  it doesn't know how
>     DB> to deal with field that require a change-reason:
> 
>     DB> address@hidden:980$ echo closed | pr-edit --replace=state 1234
>     DB> pr-edit: cannot understand 213 `Ok, now send the field change reason.'
> 
>     DB> anyone feel like implementing a quick fix for this?  if not, i
>     DB> might take a whack at adding a --change-reason= option.
> 
> It would be nice if you did this.  I don't know about a better fix
> now.

Milan:

Below are diffs which hack this functionality into pr-edit.

Someone *may* want to consider integrating them into the Gnats
development tree, but this should be done only after due consideration
by someone who understands the possible architectural
implications. Being fairly new to Gnats, I'm not sure I do.

Highlights of the patches:

- get_reply() is now declared as returning int rather than void,
  recognizes the reply code CODE_SEND_CHANGE_REASON, and returns the
  reply code received from the server.
- netEditField() and handleNetworkEdit() now take an additional
  "reason" argument of type char *.
- If netEditField() receives a reply code of CODE_SEND_CHANGE_REASON
  after sending the new field value, if supplies the value of its
  "reason" argument to the server. If no reason argument was applied,
  the function prints an error message and exits.
- pr-edit takes an additional command-line argument: "reason",
  shortcut 'R', which is passed to handleNetworkEdit(), and from there
  to netEditField.

Please let me know what you think of these changes, and whether they
might have any unanticipated side-effects.

Thanks,
Dan

Index: client.c
===================================================================
RCS file: /cvs/gnats/gnats/gnats/client.c,v
retrieving revision 1.41
diff -u -r1.41 client.c
--- client.c    2001/04/15 18:11:51     1.41
+++ client.c    2001/11/12 18:36:25
@@ -265,11 +265,12 @@
 } 
 
 
-void
+int
 get_reply (FILE *outfp)
 {
   Reply *r;
   int done = 0;
+  int retval = 0;
 
   /* Make sure anything we've written has gone to them.  */
   if (fflush (serv_write) == EOF || ferror (serv_write))
@@ -300,9 +301,11 @@
            case CODE_OK:
            case CODE_SEND_PR:
            case CODE_SEND_TEXT:
+            case CODE_SEND_CHANGE_REASON:
            case CODE_INFORMATION_FILLER:
              break;
 
+
            case CODE_CLOSING:
              if (debug)
                {
@@ -331,6 +334,8 @@
              fprintf (outfp, "%s\n", r->text);
              break;
 
+
+
            case CODE_NONEXISTENT_PR:
            case CODE_UNREADABLE_PR:
            case CODE_LOCKED_PR:
@@ -388,6 +393,7 @@
              safe_exit ();
              break;
            }
+          retval = r->state;
 
          free_reply (r);
        }
@@ -398,9 +404,12 @@
              fprintf (stderr, "%s: null reply from the server\n",
                       program_name);
            }
+          retval = 0;
          done = 1;
        }
     }
+
+  return retval;
 }
 
 void
@@ -1231,10 +1240,11 @@
 
 void
 netEditField (FILE *fp, const char *prnum, const char *fieldname, 
-             const char *editEmailAddr, int append)
+             const char *editEmailAddr, int append, char *reason)
 {
   const char *cmd;
   char *line;
+  int reply;
 
   netSetEditEmailAddr (editEmailAddr);
   if (append)
@@ -1253,7 +1263,17 @@
       free (line);
     }
   fprintf (serv_write, ".\r\n");
-  get_reply (stdout);
+  /* Have to send the field-change reason here. */
+  reply = get_reply (stdout);
+  if (reply == CODE_SEND_CHANGE_REASON) {
+    if (reason)
+      fprintf (serv_write, "%s\r\n.\r\n", reason);
+    else {
+      fprintf (stderr, "%s: server wants a change-reason for %s,"
+               " but none was supplied.\n", program_name, fieldname);
+      safe_exit ();
+    }
+  }
 }
 
 void
Index: gnats.h
===================================================================
RCS file: /cvs/gnats/gnats/gnats/gnats.h,v
retrieving revision 1.47
diff -u -r1.47 gnats.h
--- gnats.h     2001/11/01 22:35:14     1.47
+++ gnats.h     2001/11/12 18:36:25
@@ -249,7 +249,7 @@
                                     unsigned int responseTimeInDays);
 
 /* in client.c */
-extern void get_reply (FILE *);
+extern int get_reply (FILE *);
 extern void client_exit (void);
 extern void safe_exit (void);
 extern void client_chdb (const char *database);
@@ -288,7 +288,8 @@
 
 extern void netEditField (FILE *fieldData, const char *prNum, 
                          const char *fieldName,
-                         const char *editUserEmailAddr, int appendToField);
+                         const char *editUserEmailAddr, int appendToField,
+                          char *reason);
 
 extern void netSubmitNewPR (FILE *file);
 extern void netModifyPR (FILE *file, const char *prNum,
Index: pr-edit.c
===================================================================
RCS file: /cvs/gnats/gnats/gnats/pr-edit.c,v
retrieving revision 1.34
diff -u -r1.34 pr-edit.c
--- pr-edit.c   2001/11/09 22:22:09     1.34
+++ pr-edit.c   2001/11/12 18:36:25
@@ -55,6 +55,7 @@
   {"submit", 0, NULL, 's'},
   {"append", 1, NULL, 'a'},
   {"replace", 1, NULL, 'r'},
+  {"reason", 1, NULL, 'R'},
   {"process", 1, NULL, 'p'},
   {"database", 1, NULL, 'd'},
   {"filename", 1, NULL, 'f'},
@@ -142,7 +143,8 @@
 
 static void
 handleNetworkEdit (int edit_options, FILE *fpin, char *prnum, char *username,
-                  char *editEmailAddr, char *processid, char *fieldname)
+                  char *editEmailAddr, char *processid, char *fieldname,
+                   char *reason)
 {
   int exitcode = 0;
 
@@ -155,10 +157,10 @@
       netUnlockPR (prnum);
       break;
     case APPEND:
-      netEditField (fpin, prnum, fieldname, editEmailAddr, 1);
+      netEditField (fpin, prnum, fieldname, editEmailAddr, 1, reason);
       break;
     case REPLACE:
-      netEditField (fpin, prnum, fieldname, editEmailAddr, 0);
+      netEditField (fpin, prnum, fieldname, editEmailAddr, 0, reason);
       break;
     case SUBMIT:
       {
@@ -212,6 +214,7 @@
   int port = -1;
   int networkmode = 0;
   char *editUserEmailAddr = NULL;
+  char *reason = NULL;
 
   program_name = basename (argv[0]);
   edit_options = MODIFY;
@@ -284,6 +287,10 @@
          fieldname = optarg;
          break;
 
+       case 'R':
+         reason = optarg;
+         break;
+
        case DELETE_PR_OPT:
          edit_options = DELETE;
          break;
@@ -390,7 +397,7 @@
          exit (3);
        }
       handleNetworkEdit (edit_options, fp, prnum, username, editUserEmailAddr,
-                        processid, fieldname);
+                        processid, fieldname, reason);
     }
 
   database = init_gnats (program_name, nameOfDatabase, &err);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]