1 /******************************************************************************
3 * Copyright (C) 2005 Stefan Hegny, hydrografix Consulting GmbH,
4 * Frankfurt/Main, Germany
5 * and others, see http://svn2cc.sarovar.org
7 * Copyright (C) 2010 David Barr <david.barr@cordelta.com>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice(s), this list of conditions and the following disclaimer
15 * unmodified other than the allowable addition of one or more
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice(s), this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
23 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 ******************************************************************************/
37 * Parse and rearrange a svnadmin dump.
38 * Create the dump with:
39 * svnadmin dump --incremental -r<startrev>:<endrev> <repository> >outfile
49 * "yyyy-MM-dd'T'HH:mm:ss"
53 * create dump representation by importing dump file
55 void svndump_read(void)
57 char *t
= svndump_read_line();
58 while (t
&& strncmp(t
, "Revision-number:", 16))
59 t
= svndump_read_line();
62 svnrev_read(atoi(&t
[17]));
63 t
= svndump_read_line();
64 } while (strlen(t
) && !feof(stdin
));
68 * read string up to newline from input stream
69 * return all characters except the newline
71 static char line_buffer
[10000];
73 char *svndump_read_line(void)
76 char *res
= fgets(line_buffer
, 10000, stdin
);
81 if (res
[len
- 1] == '\n')
88 * so a line can be pushed-back after read
90 static char *lastLine
= NULL
;
92 void svndump_pushBackInputLine(char *input
)
98 * read a modified file (node) within a revision
100 void svnnode_read(char *fname
)
102 int type
= NODEKIND_UNKNOWN
;
107 char *fullSrcPath
= NULL
;
110 t
= svndump_read_line();
113 if (!strncmp(t
, "Node-kind:", 10)) {
115 if (!strncasecmp(val
, "dir", 3))
118 else if (!strncasecmp(val
, "file", 4))
119 type
= NODEKIND_FILE
;
122 type
= NODEKIND_UNKNOWN
;
123 } else if (!strncmp(t
, "Node-action", 11)) {
125 if (!strncasecmp(val
, "delete", 6))
126 action
= NODEACT_DELETE
;
128 else if (!strncasecmp(val
, "add", 3))
129 action
= NODEACT_ADD
;
131 else if (!strncasecmp(val
, "change", 6))
132 action
= NODEACT_CHANGE
;
135 action
= NODEACT_UNKNOWN
;
136 } else if (!strncmp(t
, "Node-copyfrom-path", 18)) {
138 } else if (!strncmp(t
, "Text-content-length:", 20)) {
140 textLength
= atoi(val
);
141 } else if (!strncmp(t
, "Prop-content-length:", 20)) {
143 propLength
= atoi(val
);
145 t
= svndump_read_line();
146 } while (strlen(t
) && !feof(stdin
));
148 /* check if it's real add or possibly copy_or_move */
149 if ((NULL
!= src
) && (action
== NODEACT_ADD
)) {
151 /* we don't really know at the moment */
152 action
= NODEACT_COPY_OR_MOVE
;
158 copy_bytes(textLength
);
160 t
= svndump_read_line();
162 svndump_pushBackInputLine(t
);
166 * Note: creating the revision will import it from
170 int strendswith(char *s
, char *end
);
173 * create revision reading from stdin
174 * param number revision number
176 void svnrev_read(uint32_t number
)
186 /* skip rest of revision definition */
187 while (strlen(svndump_read_line()));
189 /* key-value pairs containing log, date etc. */
190 t
= svndump_read_line();
193 if (!strncmp(t
, "K ", 2)) {
195 key
= svndump_read_string(len
);
197 t
= svndump_read_line();
198 } else if (!strncmp(t
, "V ", 2)) {
200 val
= svndump_read_string(len
);
201 if (strendswith(key
, ":log"))
204 } else if (strendswith(key
, ":author")) {
206 } else if (strendswith(key
, ":date")) {
211 t
= svndump_read_line();
213 } while (strlen(t
) && strncasecmp(t
, "PROPS-END", 9));
216 t
= svndump_read_line();
217 } while ((!feof(stdin
)) && (!strlen(t
)));
218 while (strncmp(t
, "Revision-number:", 16) && !feof(stdin
)) {
219 if (!strncmp(t
, "Node-path:", 10)) {
220 svnnode_read(&t
[11]);
224 t
= svndump_read_line();
225 } while ((!feof(stdin
)) && (!strlen(t
)));
228 svndump_pushBackInputLine(t
);