Skip to content

Commit b747e56

Browse files
committed
test-svn-fe: split off "test-svn-fe -d" into a separate function
The helper for testing the svndiff library is getting dangerously close to the right margin. Split it off into a separate function so it is easier to contemplate on its own. In the process, make the test_svnfe_usage[] string static so it can be shared by the two functions (and other future functions in this test program) without fuss. In other words, this just unindents the code a little. No functional change intended. Signed-off-by: Jonathan Nieder <[email protected]>
1 parent c846e41 commit b747e56

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

test-svn-fe.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,37 @@
88
#include "vcs-svn/sliding_window.h"
99
#include "vcs-svn/line_buffer.h"
1010

11+
static const char test_svnfe_usage[] =
12+
"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
13+
14+
static int apply_delta(int argc, char *argv[])
15+
{
16+
struct line_buffer preimage = LINE_BUFFER_INIT;
17+
struct line_buffer delta = LINE_BUFFER_INIT;
18+
struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage);
19+
20+
if (argc != 5)
21+
usage(test_svnfe_usage);
22+
23+
if (buffer_init(&preimage, argv[2]))
24+
die_errno("cannot open preimage");
25+
if (buffer_init(&delta, argv[3]))
26+
die_errno("cannot open delta");
27+
if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
28+
&preimage_view, stdout))
29+
return 1;
30+
if (buffer_deinit(&preimage))
31+
die_errno("cannot close preimage");
32+
if (buffer_deinit(&delta))
33+
die_errno("cannot close delta");
34+
buffer_reset(&preimage);
35+
strbuf_release(&preimage_view.buf);
36+
buffer_reset(&delta);
37+
return 0;
38+
}
39+
1140
int main(int argc, char *argv[])
1241
{
13-
static const char test_svnfe_usage[] =
14-
"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
1542
if (argc == 2) {
1643
if (svndump_init(argv[1]))
1744
return 1;
@@ -20,25 +47,8 @@ int main(int argc, char *argv[])
2047
svndump_reset();
2148
return 0;
2249
}
23-
if (argc == 5 && !strcmp(argv[1], "-d")) {
24-
struct line_buffer preimage = LINE_BUFFER_INIT;
25-
struct line_buffer delta = LINE_BUFFER_INIT;
26-
struct sliding_view preimage_view = SLIDING_VIEW_INIT(&preimage);
27-
if (buffer_init(&preimage, argv[2]))
28-
die_errno("cannot open preimage");
29-
if (buffer_init(&delta, argv[3]))
30-
die_errno("cannot open delta");
31-
if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
32-
&preimage_view, stdout))
33-
return 1;
34-
if (buffer_deinit(&preimage))
35-
die_errno("cannot close preimage");
36-
if (buffer_deinit(&delta))
37-
die_errno("cannot close delta");
38-
buffer_reset(&preimage);
39-
strbuf_release(&preimage_view.buf);
40-
buffer_reset(&delta);
41-
return 0;
42-
}
50+
51+
if (argc >= 2 && !strcmp(argv[1], "-d"))
52+
return apply_delta(argc, argv);
4353
usage(test_svnfe_usage);
4454
}

0 commit comments

Comments
 (0)