[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: patch to display new PR number for new submissions
From: |
Andrew J. Gray |
Subject: |
Re: patch to display new PR number for new submissions |
Date: |
Sun, 9 Feb 2003 17:49:28 +1100 |
Thanks for your comments on my modifications.
> One small concern with the patch though...in get_reply you've made
> a change allowing for outfp to be NULL...
Actually, outfp was already allowed to be NULL in some cases,
get_reply is called passing NULL for outfp in a number of places in
client.c. It appears that the client code avoids referencing outfp
when it is NULL by relying on the server code to send the expected
responses.
> However, immediately above this code, there's another reference to
> 'outfp' which is unprotected....
>
> else
> {
> read_server (outfp);
> }
>
> I suggest that you put some checks for NULL around this too.
Thanks, that is a good idea.
> > -the database. A zero exit code is returned if the submission was
> > -successful. Otherwise, the reason(s) for the PR being rejected are
> > -printed to stdout, and a non-zero exit code is returned.
> > +the database. If the submission a zero exit code is returned.
> ^^^^^^
> I think you're missing 'is successful' in the above sentence.
Yes, thanks for picking up that error.
A new patch with changes to fix these issues is at the end of this
message.
> > Since this change is an enhancement and modifies the gnatsd command
> > protocol I am thinking it should not be included in GNATS 4.0 final,
> > but put on a 4.1 branch. What do people think?
>
> I'm in favour of rolling out 4.0 pretty soon....if you think putting
> this patch on a 4.1 branch would help this endevour, I'd suggest
> you do just that.
OK, I will hold this patch for when we create a 4.1 branch.
--
Andrew J. Gray
Index: doc/gnats.texi
===================================================================
RCS file: /cvsroot/gnats/gnats/doc/gnats.texi,v
retrieving revision 1.40
diff -u -p -r1.40 gnats.texi
--- doc/gnats.texi 25 Nov 2002 08:48:44 -0000 1.40
+++ doc/gnats.texi 9 Feb 2003 02:42:51 -0000
@@ -1386,8 +1386,9 @@ lock is cleared.
@code{211 (CODE_SEND_PR)}
@*The client should now transmit the new PR text using the normal
quoting mechanism. After the PR has been sent, the server will respond
-with either a @code{200 (CODE_OK)} response indicating that the new PR
-has been created (and mail sent to the appropriate persons), or one or
+with either @code{351 (CODE_INFORMATION_FILLER)} and
address@hidden (CODE_INFORMATION)} responses indicating that the new PR
+has been created and supplying the number assigned to it, or one or
more error codes listing problems with the new PR text.
@item CHDB @var{database}
Index: doc/p-admin.texi
===================================================================
RCS file: /cvsroot/gnats/gnats/doc/p-admin.texi,v
retrieving revision 1.34
diff -u -p -r1.34 p-admin.texi
--- doc/p-admin.texi 27 Nov 2002 22:04:38 -0000 1.34
+++ doc/p-admin.texi 9 Feb 2003 02:43:06 -0000
@@ -2083,7 +2083,7 @@ The usage for @code{pr-edit} is:
@smallexample
pr-edit [ -l @var{username} | address@hidden ] [ -u | --unlockdb ]
[ -L | --lockdb ] [ -U | --unlockdb ] [ -c | --check ]
- [ -C | --check-initial ] [ -s | --submit ]
+ [ -C | --check-initial ] [ -s | --submit [ --show-prnum ] ]
[ -a @var{field} | --append address@hidden ]
[ -r @var{field} | address@hidden ] [ --delete-pr ]
[ -R @var{reason} | address@hidden ]
@@ -2147,9 +2147,13 @@ rather than proposed edits of existing P
@itemx --submit
Used to submit a new PR to the database. The PR is read in and verified
for content; if the PR is valid as an initial PR, it is then added to
-the database. A zero exit code is returned if the submission was
-successful. Otherwise, the reason(s) for the PR being rejected are
-printed to stdout, and a non-zero exit code is returned.
+the database. If the submission is successful a zero exit code is
+returned. Otherwise, the reason(s) for the PR being rejected are
+printed, and a non-zero exit code is returned.
+
address@hidden --show-prnum
+This option is used with the @code{--submit} option to display the PR
+number associated with the submitted PR.
@end table
@noindent The following options require a PR number to be given.
Index: gnats/client.c
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/client.c,v
retrieving revision 1.46
diff -u -p -r1.46 client.c
--- gnats/client.c 25 Nov 2002 13:58:33 -0000 1.46
+++ gnats/client.c 9 Feb 2003 02:43:11 -0000
@@ -329,12 +329,20 @@ get_reply (FILE *outfp)
}
else
{
- read_server (outfp);
+ if (outfp != NULL)
+ read_server (outfp);
+ else
+ {
+ fprintf (stderr, "%s: unexpected %d received\n",
+ program_name, r->state);
+ safe_exit();
+ }
}
break;
case CODE_INFORMATION:
- fprintf (outfp, "%s\n", r->text);
+ if (outfp != NULL)
+ fprintf (outfp, "%s\n", r->text);
break;
case CODE_NONEXISTENT_PR:
@@ -1216,7 +1224,7 @@ netSetEditEmailAddr (const char *addr)
}
static void
-netSendPRCmd (const char *cmd, FILE *file)
+netSendPRCmd (const char *cmd, FILE *file, int show_information)
{
char *line;
if (debug)
@@ -1233,13 +1241,13 @@ netSendPRCmd (const char *cmd, FILE *fil
}
fprintf (serv_write, ".\r\n");
/* if get_reply finds errors it writes messages and doesn't return */
- get_reply (stdout);
+ get_reply (show_information ? stdout : NULL);
}
void
netCheckPR (FILE *file, int initial)
{
- netSendPRCmd (initial ? "CHEK INIT" : "CHEK", file);
+ netSendPRCmd (initial ? "CHEK INIT" : "CHEK", file, 1);
}
void
@@ -1298,9 +1306,9 @@ netEditField (FILE *fp, const char *prnu
}
void
-netSubmitNewPR (FILE *file)
+netSubmitNewPR (FILE *file, int show_prnum)
{
- netSendPRCmd ("SUBM", file);
+ netSendPRCmd ("SUBM", file, show_prnum);
}
void
@@ -1310,7 +1318,7 @@ netModifyPR (FILE *file, const char *prN
netSetEditEmailAddr (editEmailAddr);
asprintf (&buf, "EDIT %s", prNum);
- netSendPRCmd (buf, file);
+ netSendPRCmd (buf, file, 1);
free (buf);
}
Index: gnats/cmds.c
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- gnats/cmds.c 14 Oct 2002 11:42:25 -0000 1.70
+++ gnats/cmds.c 9 Feb 2003 02:43:17 -0000
@@ -478,6 +478,7 @@ GNATS_subm (int ac, char **av ATTRIBUTE_
char *tempfile;
FILE *fp;
ErrorDesc err;
+ int new_pr_num;
if (ac != 0)
{
@@ -507,9 +508,11 @@ GNATS_subm (int ac, char **av ATTRIBUTE_
{
if (daemon_lock_gnats (FALSE) == 0)
{
- if (submit_pr (currentDatabase, fp, &err) != 0)
+ if ((new_pr_num = submit_pr (currentDatabase, fp, &err)) != 0)
{
- printf ("%d PR added.\r\n", CODE_OK);
+ printf ("%d-The added PR number is:\r\n",
+ CODE_INFORMATION_FILLER);
+ printf ("%d %d\r\n", CODE_INFORMATION, new_pr_num);
fflush (stdout);
}
else
Index: gnats/file-pr.c
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/file-pr.c,v
retrieving revision 1.51
diff -u -p -r1.51 file-pr.c
--- gnats/file-pr.c 1 Nov 2002 11:37:51 -0000 1.51
+++ gnats/file-pr.c 9 Feb 2003 02:43:21 -0000
@@ -930,11 +930,13 @@ getBugNumber (const DatabaseInfo databas
return bug_number;
}
-/* Submit the PR whose contents are referred to by FP. */
+/* Submit the PR whose contents are referred to by FP.
+ * Return the new PR number if it's a new PR, or return the PR number of
+ * the PR which was appended to if it's an existing PR. */
int
submit_pr (const DatabaseInfo database, FILE *fp, ErrorDesc *err)
{
- int result;
+ int result, retval;
PR *pr = allocPR (database);
result = (read_header (pr, fp) >= 0);
@@ -956,10 +958,8 @@ submit_pr (const DatabaseInfo database,
}
else
{
- if (append_report (fp, pr, prID, err) != 0)
- {
- result = 0;
- }
+ retval = append_report (fp, pr, prID, err);
+ result = (retval == 0) ? atoi (prID) : 0;
free_pr (pr);
}
free (prID);
@@ -967,10 +967,8 @@ submit_pr (const DatabaseInfo database,
else
{
read_pr (pr, fp, 0);
- if (createNewPRFile (pr, createCategoryDirs (database), err) < 0)
- {
- result = 0;
- }
+ retval = createNewPRFile (pr, createCategoryDirs (database), err);
+ result = (retval < 0) ? 0 : retval;
}
}
else
Index: gnats/gnats.h
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/gnats.h,v
retrieving revision 1.52
diff -u -p -r1.52 gnats.h
--- gnats/gnats.h 31 Oct 2002 23:43:28 -0000 1.52
+++ gnats/gnats.h 9 Feb 2003 02:43:22 -0000
@@ -292,7 +292,7 @@ extern void netEditField (FILE *fieldDat
const char *editUserEmailAddr, int appendToField,
char *reason);
-extern void netSubmitNewPR (FILE *file);
+extern void netSubmitNewPR (FILE *file, int show_prnum);
extern void netModifyPR (FILE *file, const char *prNum,
const char *editUserEmailAddr);
extern void netLockDB (void);
Index: gnats/pr-edit.c
===================================================================
RCS file: /cvsroot/gnats/gnats/gnats/pr-edit.c,v
retrieving revision 1.37
diff -u -p -r1.37 pr-edit.c
--- gnats/pr-edit.c 1 Nov 2002 09:02:23 -0000 1.37
+++ gnats/pr-edit.c 9 Feb 2003 02:43:25 -0000
@@ -43,6 +43,7 @@ enum {
} edit_options;
#define DELETE_PR_OPT 256
+#define SHOW_PRNUM_OPT 257
struct option long_options[] =
{
@@ -61,6 +62,7 @@ struct option long_options[] =
{"filename", 1, NULL, 'f'},
{"version", 0, NULL, 'V'},
{"delete-pr", 0, NULL, DELETE_PR_OPT},
+ {"show-prnum", 0, NULL, SHOW_PRNUM_OPT},
{"help", 0, NULL, 'h'},
{"user", 1, NULL, 'v'},
{"passwd", 1, NULL, 'w'},
@@ -83,9 +85,10 @@ Modify database.\n\
-L --lockdb lock the whole database\n\
-U --unlockdb unlock the database\n\
-c --check check input for editting, don't change PR\n\
- -C --check-initial check input for submition, don't submit new PR\n\
+ -C --check-initial check input for submission, don't submit new PR\n\
-s --submit submit new PR\n",
"\
+ --show-prnum display the newly created PR number (for
--submit)\n\
-a --append=FIELDNAME append input to FIELDNAME\n\
-r --replace=FIELDNAME replace FIELDNAME with input\n\
--delete-pr delete PR from the database completely\n\
@@ -145,7 +148,7 @@ read_file (FILE *inp)
static void
handleNetworkEdit (int edit_options, FILE *fpin, char *prnum, char *username,
char *editEmailAddr, char *processid, char *fieldname,
- char *reason)
+ char *reason, int show_prnum)
{
int exitcode = 0;
@@ -165,7 +168,7 @@ handleNetworkEdit (int edit_options, FIL
break;
case SUBMIT:
{
- netSubmitNewPR (fpin);
+ netSubmitNewPR (fpin, show_prnum);
break;
}
case CHECK:
@@ -216,6 +219,7 @@ main (int argc, char **argv)
int networkmode = 0;
char *editUserEmailAddr = NULL;
char *reason = NULL;
+ int show_prnum = 0;
program_name = basename (argv[0]);
edit_options = MODIFY;
@@ -233,6 +237,10 @@ main (int argc, char **argv)
debug = 1;
break;
+ case SHOW_PRNUM_OPT:
+ show_prnum = 1;
+ break;
+
case 'f':
fp = fopen (optarg, "r");
/* If they gave a bogus argument, then exit right away; we don't
@@ -398,7 +406,7 @@ main (int argc, char **argv)
exit (3);
}
handleNetworkEdit (edit_options, fp, prnum, username, editUserEmailAddr,
- processid, fieldname, reason);
+ processid, fieldname, reason, show_prnum);
}
database = init_gnats (program_name, nameOfDatabase, &err);
@@ -467,6 +475,10 @@ main (int argc, char **argv)
case SUBMIT:
{
result = submit_pr (database, fp, &err);
+ if (show_prnum && result)
+ {
+ fprintf (stdout, "%d\n", result);
+ }
break;
}
case APPEND:
Index: send-pr/send-pr.sh
===================================================================
RCS file: /cvsroot/gnats/gnats/send-pr/send-pr.sh,v
retrieving revision 1.23
diff -u -p -r1.23 send-pr.sh
--- send-pr/send-pr.sh 29 Oct 2002 09:58:15 -0000 1.23
+++ send-pr/send-pr.sh 9 Feb 2003 02:43:28 -0000
@@ -536,8 +536,8 @@ do
echo "$COMMAND: problem report mailed"
xs=0; exit
else
- if $LIBEXECDIR/pr-edit --submit < $REF; then
- echo "$COMMAND: problem report filed"
+ if pr_num=`$LIBEXECDIR/pr-edit --submit --show-prnum < $REF` ; then
+ echo "$COMMAND: problem report $pr_num filed"
xs=0; exit
else
echo "$COMMAND: the problem report is not sent."