1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/***************************************************************************
* Copyright (C) 2008 by Rajko Albrecht [email protected] *
* http://tdesvn.alwins-world.de/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "diff_data.hpp"
#include "svnqt/svnqt_defines.hpp"
#include "svnqt/exception.hpp"
#include <tqfile.h>
#include <svn_version.h>
#include <svn_io.h>
#include <svn_path.h>
namespace svn
{
DiffData::DiffData(const Path&aTmpPath,const Path&_p1,const Revision&_r1,const Path&_p2,const Revision&_r2)
:m_Pool(),m_tmpPath(aTmpPath),
m_outFile(0),m_errFile(0),m_outFileName(0),m_errFileName(0),
m_p1(_p1),m_p2(_p2),m_r1(_r1),m_r2(_r2),
m_working_copy_present(false),m_url_is_present(false)
{
init();
}
void DiffData::init()
{
svn_error_t * error;
#if (SVN_VER_MAJOR >= 1) && (SVN_VER_MINOR >= 4)
error = svn_io_open_unique_file2(&m_outFile, &m_outFileName,
m_tmpPath.path().TOUTF8(),
".tmp",
svn_io_file_del_on_pool_cleanup, m_Pool);
#else
error = svn_io_open_unique_file (&m_outFile, &m_outFileName,
m_tmpPath.path().TOUTF8(),
".tmp",
FALSE, m_Pool);
#endif
if (error!=0) {
clean();
throw ClientException (error);
}
#if (SVN_VER_MAJOR >= 1) && (SVN_VER_MINOR >= 4)
error = svn_io_open_unique_file2(&m_errFile, &m_errFileName,
m_tmpPath.path().TOUTF8(),
".tmp",
svn_io_file_del_on_pool_cleanup, m_Pool);
#else
error = svn_io_open_unique_file (&m_errFile, &m_errFileName,
m_tmpPath.path().TOUTF8(),
".tmp",
FALSE, m_Pool);
#endif
if (error!=0) {
clean();
throw ClientException (error);
}
if (svn_path_is_url(m_p1.cstr())) {
m_url_is_present = true;
} else {
m_working_copy_present = true;
}
if (svn_path_is_url(m_p2.cstr())) {
m_url_is_present = true;
} else {
m_working_copy_present = true;
}
if (m_r1.revision()->kind==svn_opt_revision_unspecified && m_working_copy_present) {
m_r1 = svn_opt_revision_base;
}
if (m_r2.revision()->kind==svn_opt_revision_unspecified) {
m_r2 = m_working_copy_present?svn_opt_revision_working : svn_opt_revision_head;
}
}
DiffData::~DiffData()
{
clean();
}
void DiffData::clean()
{
close();
#if !((SVN_VER_MAJOR >= 1) && (SVN_VER_MINOR >= 4))
if (m_outFileName != 0) {
svn_error_clear (svn_io_remove_file (m_outFileName, m_Pool));
m_outFileName=0;
}
if (m_errFileName != 0) {
svn_error_clear (svn_io_remove_file (m_errFileName, m_Pool));
m_errFileName=0;
}
#endif
}
void DiffData::close()
{
if (m_outFile != 0) {
svn_io_file_close(m_outFile,m_Pool);
m_outFile=0;
}
if (m_errFile != 0) {
svn_io_file_close(m_errFile,m_Pool);
m_errFile=0;
}
}
TQByteArray DiffData::content()
{
if (!m_outFileName) {
return TQByteArray();
}
close();
TQFile fi(m_outFileName);
if (!fi.open(IO_ReadOnly|IO_Raw)) {
throw ClientException(TQString("%1 '%2'").tqarg(fi.errorString()).tqarg(m_outFileName));
}
TQByteArray res = fi.readAll();
fi.close();
return res;
}
}
|