Check cvs commit's -m argument for being a filename and ask the user
[dragonfly.git] / gnu / usr.bin / cvs / cvs / commit.c.patch
1 $DragonFly: src/gnu/usr.bin/cvs/cvs/Attic/commit.c.patch,v 1.1 2006/05/27 11:59:44 corecode Exp $
2 Index: src/commit.c
3 ===================================================================
4 RCS file: /cvs/src/contrib/cvs-1.12/src/commit.c,v
5 retrieving revision 1.1.1.1
6 diff -u -r1.1.1.1 commit.c
7 --- src/commit.c        7 Dec 2005 00:15:16 -0000       1.1.1.1
8 +++ src/commit.c        27 May 2006 09:20:10 -0000
9 @@ -443,6 +443,58 @@
10             ++saved_tag;
11      }
12  
13 +    /* Check if the user passed -m, but wanted -F */
14 +    if (saved_message)
15 +    {
16 +       int fd;
17 +
18 +       fd = open(saved_message, O_RDONLY);
19 +       /* valid fd -> possibly wrong flag? */
20 +       if (fd >= 0)
21 +       {
22 +           char *line = NULL;
23 +           size_t line_alloced = 0;
24 +           int line_len;
25 +
26 +           close(fd);
27 +
28 +           for (;;) {
29 +               printf("The message you passed exists as a file\n");
30 +               printf("a)bort, c)ontinue, treat as f)ile name\n");
31 +               printf("Action: (abort) ");
32 +               fflush(stdout);
33 +               line_len = getline(&line, &line_alloced, stdin);
34 +               if (line_len < 0)
35 +               {
36 +                   error(0, errno, "cannot read from stdin");
37 +                   error(1, 0, "aborting");
38 +               }
39 +               else if (line_len == 0 || *line == '\n' || *line == 'a' || *line == 'A')
40 +               {
41 +                   error(1, 0, "aborted by user");
42 +               }
43 +               else if (*line == 'c' || *line == 'C')
44 +               {
45 +                   break;
46 +               }
47 +               else if (*line == 'f' || *line == 'F')
48 +               {
49 +                   /*
50 +                    * We are leaking the memory for the file name,
51 +                    * but who really cares?
52 +                    */
53 +                   logfile = saved_message;
54 +                   saved_message = NULL;
55 +                   break;
56 +               }
57 +               printf("Unknown input\n");
58 +           }
59 +
60 +           if (line != NULL)
61 +               free(line);
62 +       }
63 +    }
64 +
65      /* some checks related to the "-F logfile" option */
66      if (logfile)
67      {