1#!/usr/bin/perl
2#
3#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements.  See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership.  The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License.  You may obtain a copy of the License at
11#
12#   http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied.  See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21#
22
23use strict;
24use warnings;
25
26use Test::More tests => 8;
27use File::Temp qw(tempdir);
28use File::Path qw(rmtree);
29use File::Spec;
30use POSIX qw(locale_h);
31
32use SVN::Core;
33use SVN::Repos;
34use SVN::Fs;
35use SVN::Delta;
36
37setlocale(LC_ALL, "C");
38
39my $repospath = tempdir('svn-perl-test-XXXXXX', TMPDIR => 1, CLEANUP => 1);
40
41my $repos;
42
43# TEST
44ok($repos = SVN::Repos::create("$repospath", undef, undef, undef, undef),
45   "create repository at $repospath");
46
47my $fs = $repos->fs;
48
49sub committed {
50    diag "committed ".join(',',@_);
51}
52
53my $editor = SVN::Delta::Editor->
54    new(SVN::Repos::get_commit_editor($repos, "file://$repospath",
55                                      '/', 'root', 'FOO', \&committed));
56
57my $rootbaton = $editor->open_root(0);
58
59my $dirbaton = $editor->add_directory('trunk', $rootbaton, undef, 0);
60
61my $fbaton = $editor->add_file('trunk/filea', $dirbaton, undef, -1);
62
63my $ret = $editor->apply_textdelta($fbaton, undef);
64
65SVN::TxDelta::send_string("FILEA CONTENT", @$ret);
66
67$editor->close_edit();
68
69# TEST
70cmp_ok($fs->youngest_rev, '==', 1);
71{
72$editor = SVN::Delta::Editor->
73    new(SVN::Repos::get_commit_editor($repos, "file://$repospath",
74                                      '/', 'root', 'FOO', \&committed));
75my $rootbaton = $editor->open_root(1);
76
77my $dirbaton = $editor->add_directory('tags', $rootbaton, undef, 1);
78my $subdirbaton = $editor->add_directory('tags/foo', $dirbaton,
79                                         "file://$repospath/trunk", 1);
80
81$editor->close_edit();
82}
83# TEST
84cmp_ok($fs->youngest_rev, '==', 2);
85
86my @history;
87
88SVN::Repos::history($fs, 'tags/foo/filea',
89                    sub {push @history, [@_[0,1]]}, 0, 2, 1);
90
91# TEST
92is_deeply(\@history, [['/tags/foo/filea',2],['/trunk/filea',1]],
93          'repos_history');
94
95{
96my $pool = SVN::Pool->new_default;
97my $something = bless {}, 'something';
98$editor = SVN::Delta::Editor->
99    new(SVN::Repos::get_commit_editor($repos, "file://$repospath",
100                                      '/', 'root', 'FOO', sub {committed(@_);
101                                                               $something;
102                                                          }));
103
104my $rootbaton = $editor->open_root(2);
105$editor->delete_entry('tags', 2, $rootbaton);
106
107$editor->close_edit();
108}
109# TEST
110ok($main::something_destroyed, 'callback properly destroyed');
111
112# TEST
113cmp_ok($fs->youngest_rev, '==', 3);
114
115open my $dump_fh, ">", File::Spec->devnull or die "open file sink: $!";
116
117my $feedback;
118open my $feedback_fh, ">", \$feedback or die "open string: $!";
119
120my $cancel_cb_called = 0;
121$repos->dump_fs2($dump_fh, $feedback_fh,
122                 0, $SVN::Core::INVALID_REVNUM,     # start_rev, end_rev
123                 0, 0,                              # incremental, deltify
124                 sub { $cancel_cb_called++; 0 });
125# TEST
126ok($cancel_cb_called, 'cancel callback was called');
127# TEST
128is($feedback, <<'...', 'dump feedback');
129* Dumped revision 0.
130* Dumped revision 1.
131* Dumped revision 2.
132* Dumped revision 3.
133...
134
135END {
136diag "cleanup";
137rmtree($repospath);
138}
139
140package something;
141
142sub DESTROY {
143    $main::something_destroyed++;
144}
145
1461;
147