~ubuntu-branches/ubuntu/lucid/patch/lucid

« back to all changes in this revision

Viewing changes to debian/patches/20_global-reject-file

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2009-12-02 10:25:26 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091202102526-5luk0zsqhghu58l2
Tags: 2.6-2
* Update watch file.
* Section: vcs.
* Suggests: diffutils-doc instead of diff-doc, thanks Christoph Anton
  Mitterer for spotting. Closes: #558974.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Generate a global reject file
2
 
 
3
 
diff -urNad patch~/patch.c patch/patch.c
4
 
--- patch~/patch.c      2006-01-28 19:20:06.725012144 +0100
5
 
+++ patch/patch.c       2006-01-28 19:22:34.100607648 +0100
6
 
@@ -67,6 +67,7 @@
7
 
 static bool spew_output (struct outstate *);
8
 
 static char const *make_temp (char);
9
 
 static int numeric_string (char const *, bool, char const *);
10
 
+static void reject_header (const char *filename);
11
 
 static void abort_hunk (void);
12
 
 static void cleanup (void);
13
 
 static void get_some_switches (void);
14
 
@@ -98,6 +99,7 @@
15
 
 static char * const *Argv;
16
 
 
17
 
 static FILE *rejfp;  /* reject file pointer */
18
 
+static char *global_reject;
19
 
 
20
 
 static char const *patchname;
21
 
 static char *rejname;
22
 
@@ -172,6 +174,10 @@
23
 
     /* Make sure we clean up in case of disaster.  */
24
 
     set_signals (false);
25
 
 
26
 
+    /* initialize global reject file */
27
 
+    if (global_reject)
28
 
+      init_reject ();
29
 
+
30
 
     for (
31
 
        open_patch_file (patchname);
32
 
        there_is_another_patch();
33
 
@@ -208,8 +214,9 @@
34
 
            init_output (TMPOUTNAME, exclusive, &outstate);
35
 
          }
36
 
 
37
 
-       /* initialize reject file */
38
 
-       init_reject ();
39
 
+       /* initialize per-patch reject file */
40
 
+       if (!global_reject)
41
 
+         init_reject ();
42
 
 
43
 
        /* find out where all the lines are */
44
 
        if (!skip_rest_of_patch)
45
 
@@ -278,6 +285,8 @@
46
 
 
47
 
            newwhere = pch_newfirst() + last_offset;
48
 
            if (skip_rest_of_patch) {
49
 
+               if (!failed)
50
 
+                 reject_header(outname);
51
 
                abort_hunk();
52
 
                failed++;
53
 
                if (verbosity == VERBOSE)
54
 
@@ -292,6 +301,8 @@
55
 
                  say ("Patch attempted to create file %s, which already exists.\n",
56
 
                       quotearg (inname));
57
 
 
58
 
+               if (!failed)
59
 
+                 reject_header(outname);
60
 
                abort_hunk();
61
 
                failed++;
62
 
                if (verbosity != SILENT)
63
 
@@ -299,6 +310,8 @@
64
 
                       format_linenum (numbuf, newwhere));
65
 
            }
66
 
            else if (! apply_hunk (&outstate, where)) {
67
 
+               if (!failed)
68
 
+                 reject_header(outname);
69
 
                abort_hunk ();
70
 
                failed++;
71
 
                if (verbosity != SILENT)
72
 
@@ -332,7 +345,8 @@
73
 
                    fclose (outstate.ofp);
74
 
                    outstate.ofp = 0;
75
 
                  }
76
 
-               fclose (rejfp);
77
 
+               if (!global_reject)
78
 
+                 fclose (rejfp);
79
 
                continue;
80
 
              }
81
 
 
82
 
@@ -412,13 +426,13 @@
83
 
            }
84
 
       }
85
 
       if (diff_type != ED_DIFF) {
86
 
-       if (fclose (rejfp) != 0)
87
 
+       if (!global_reject && fclose (rejfp) != 0)
88
 
            write_fatal ();
89
 
        if (failed) {
90
 
            somefailed = true;
91
 
            say ("%d out of %d hunk%s %s", failed, hunk, "s" + (hunk == 1),
92
 
                 skip_rest_of_patch ? "ignored" : "FAILED");
93
 
-           if (outname) {
94
 
+           if (!global_reject && outname) {
95
 
                char *rej = rejname;
96
 
                if (!rejname) {
97
 
                    rej = xmalloc (strlen (outname) + 5);
98
 
@@ -445,6 +459,20 @@
99
 
       }
100
 
       set_signals (true);
101
 
     }
102
 
+    if (global_reject)
103
 
+      {
104
 
+       if (fclose (rejfp) != 0)
105
 
+         write_fatal ();
106
 
+       if (somefailed)
107
 
+         {
108
 
+         say (" -- saving rejects to file %s\n", quotearg (global_reject));
109
 
+         /*if (! dry_run)
110
 
+           {*/
111
 
+             move_file (TMPREJNAME, &TMPREJNAME_needs_removal,
112
 
+                        global_reject, 0644, false);
113
 
+           /*}*/
114
 
+         }
115
 
+      }
116
 
     if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0))
117
 
       write_fatal ();
118
 
     cleanup ();
119
 
@@ -523,6 +551,7 @@
120
 
   {"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
121
 
   {"posix", no_argument, NULL, CHAR_MAX + 7},
122
 
   {"quoting-style", required_argument, NULL, CHAR_MAX + 8},
123
 
+  {"global-reject-file", required_argument, NULL, CHAR_MAX + 9},
124
 
   {NULL, no_argument, NULL, 0}
125
 
 };
126
 
 
127
 
@@ -582,6 +611,7 @@
128
 
 "  --dry-run  Do not actually change any files; just print what would happen.",
129
 
 "  --posix  Conform to the POSIX standard.",
130
 
 "  -U  --unified-reject-files  Create unified reject files.",
131
 
+"  --global-reject-file=file  Put all rejects into one file.",
132
 
 "",
133
 
 "  -d DIR  --directory=DIR  Change the working directory to DIR first.",
134
 
 #if HAVE_SETMODE_DOS
135
 
@@ -784,6 +814,9 @@
136
 
                                     (enum quoting_style) i);
137
 
                }
138
 
                break;
139
 
+           case CHAR_MAX + 9:
140
 
+               global_reject = savestr (optarg);
141
 
+               break;
142
 
            default:
143
 
                usage (stderr, 2);
144
 
        }
145
 
@@ -933,6 +966,37 @@
146
 
 }
147
 
 
148
 
 static char *
149
 
+format_timestamp (char timebuf[37], bool which)
150
 
+{
151
 
+  time_t ts = pch_timestamp(which);
152
 
+  if (ts != -1)
153
 
+    {
154
 
+      struct tm *tm = localtime(&ts);
155
 
+      strftime(timebuf, 37, "\t%Y-%m-%d %H:%M:%S.000000000 %z", tm);
156
 
+    }
157
 
+  else
158
 
+    timebuf[0] = 0;
159
 
+  return timebuf;
160
 
+}
161
 
+
162
 
+/* Write a header in a reject file that combines multiple hunks. */
163
 
+static void
164
 
+reject_header (const char *outname)
165
 
+{
166
 
+    char timebuf0[37], timebuf1[37];
167
 
+    if (!global_reject)
168
 
+      return;
169
 
+    if (diff_type == UNI_DIFF)
170
 
+       fprintf(rejfp, "--- %s.orig%s\n+++ %s%s\n",
171
 
+               outname, format_timestamp(timebuf0, reverse),
172
 
+               outname, format_timestamp(timebuf1, !reverse));
173
 
+    else
174
 
+       fprintf(rejfp, "*** %s.orig%s\n--- %s%s\n",
175
 
+               outname, format_timestamp(timebuf0, reverse),
176
 
+               outname, format_timestamp(timebuf1, !reverse));
177
 
+}
178
 
+
179
 
+static char *
180
 
 format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2],
181
 
                  LINENUM first, LINENUM lines)
182
 
 {
183
 
diff -urNad patch~/patch.man patch/patch.man
184
 
--- patch~/patch.man    2006-01-28 19:20:06.726011992 +0100
185
 
+++ patch/patch.man     2006-01-28 19:20:06.839994664 +0100
186
 
@@ -520,6 +520,15 @@
187
 
 \fB\-U\fP  or  \fB\*=unified\-reject\-files\fP
188
 
 Produce unified reject files. The default is to produce context type reject files.
189
 
 .TP
190
 
+.BI \*=global\-reject\-file= rejectfile
191
 
+Put all rejects into
192
 
+.I rejectfile
193
 
+instead of creating separate reject files for all files that have rejects. The
194
 
+.I rejectfile
195
 
+will contain headers that identify which file each reject refers to. Note that
196
 
+the global reject file is created even if \-\-dry\-run is specified (while
197
 
+non-global reject files will only be created without \-\-dry\-run).
198
 
+.TP
199
 
 \fB\-R\fP  or  \fB\*=reverse\fP
200
 
 Assume that this patch was created with the old and new files swapped.
201
 
 (Yes, I'm afraid that does happen occasionally, human nature being what it