2 * wiggle - apply rejected patches
4 * Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
31 * split patch or merge files.
39 void skip_eol(char **cp
, char *end
)
42 while (c
< end
&& *c
!= '\n')
48 void copyline(struct stream
*s
, char **cp
, char *end
)
51 char *to
= s
->body
+s
->len
;
53 while (from
< end
&& *from
!= '\n')
61 int split_patch(struct stream f
, struct stream
*f1
, struct stream
*f2
)
71 f1
->body
= f2
->body
= NULL
;
73 r1
.body
= malloc(f
.len
);
74 r2
.body
= malloc(f
.len
);
75 if (!r1
.body
|| !r2
.body
)
85 * 1 first half of context
86 * 2 second half of context
92 if (sscanf(cp
, "@@ -%d,%d +%d,%d @@", &a
, &b
, &c
, &d
)==4) {
96 } else if (sscanf(cp
, "*** %d,%d ****", &a
, &b
)==2) {
99 } else if (sscanf(cp
, "--- %d,%d ----", &c
, &d
)==2) {
104 if (state
==1 || state
== 3) {
108 sprintf(buf
+1, "%5d %5d %5d\n", chunks
, a
, acnt
);
109 memcpy(r1
.body
+r1
.len
, buf
, 19);
112 if (state
==2 || state
== 3) {
115 sprintf(buf
+1, "%5d %5d %5d\n", chunks
, c
, bcnt
);
116 memcpy(r2
.body
+r2
.len
, buf
, 19);
121 if ((*cp
== ' ' || *cp
=='!' || *cp
== '-' || *cp
== '+')
124 copyline(&r1
, &cp
, end
);
129 fprintf(stderr
, "wiggle: bad context patch at line %d\n", lineno
);
134 if ((*cp
== ' ' || *cp
=='!' || *cp
== '-' || *cp
== '+')
137 copyline(&r2
, &cp
, end
);
142 fprintf(stderr
, "wiggle: bad context patch/2 at line %d\n", lineno
);
151 copyline(&r1
, &cp
, end
);
152 copyline(&r2
, &cp2
, end
);
154 } else if (*cp
== '-') {
156 copyline(&r1
, &cp
, end
);
158 } else if (*cp
== '+') {
160 copyline(&r2
, &cp
, end
);
163 fprintf(stderr
, "wiggle: bad unified patch at line %d\n", lineno
);
166 if (acnt
<= 0 && bcnt
<= 0)
171 if (r1
.len
> f
.len
|| r2
.len
> f
.len
)
179 * extract parts of a "diff3 -m" or "wiggle -m" output
181 int split_merge(struct stream f
, struct stream
*f1
, struct stream
*f2
, struct stream
*f3
)
186 struct stream r1
,r2
,r3
;
187 f1
->body
= f2
->body
= f2
->body
= NULL
;
189 r1
.body
= malloc(f
.len
);
190 r2
.body
= malloc(f
.len
);
191 r3
.body
= malloc(f
.len
);
192 if (!r1
.body
|| !r2
.body
|| !r3
.body
)
195 r1
.len
= r2
.len
= r3
.len
= 0;
202 * 1 in file 1 of conflict
203 * 2 in file 2 of conflict
204 * 3 in file 3 of conflict
211 strncmp(cp
, "<<<<<<<", 7)==0 &&
212 (cp
[7] == ' ' || cp
[7] == '\n')
218 copyline(&r1
, &cp2
, end
);
220 copyline(&r2
, &cp2
, end
);
221 copyline(&r3
, &cp
, end
);
226 strncmp(cp
, "|||||||", 7)==0 &&
227 (cp
[7] == ' ' || cp
[7] == '\n')
232 copyline(&r1
, &cp
, end
);
236 strncmp(cp
, "=======", 7)==0 &&
237 (cp
[7] == ' ' || cp
[7] == '\n')
242 copyline(&r2
, &cp
, end
);
246 strncmp(cp
, ">>>>>>>", 7)==0 &&
247 (cp
[7] == ' ' || cp
[7] == '\n')
252 copyline(&r3
, &cp
, end
);