summaryrefslogtreecommitdiffstats
path: root/src/svnqt/status.cpp
blob: 54170b8fd2b9e89cde8ef4383ce7899805b6943f (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 * Port for usage with tqt-framework and development for tdesvn
 * (C) 2005-2007 by Rajko Albrecht
 * http://tdesvn.alwins-world.de
 */
/*
 * ====================================================================
 * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library (in the file LGPL.txt); if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA  02110-1301  USA
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://rapidsvn.tigris.org/.
 * ====================================================================
 */

// svncpp
#include "status.h"
#include "svnqt/svnqt_defines.h"
#include "svnqt/path.h"
#include "svnqt/url.h"

#include "svn_path.h"

namespace svn
{
  class SVNTQT_NOEXPORT Status_private
  {
  public:
    Status_private();
    virtual ~Status_private();
    /**
     * Initialize structures
     *
     * @param path
     * @param status if NULL isVersioned will be false
     */
    void
    init (const TQString&path, const svn_wc_status2_t * status);
    void
    init (const TQString&path,const Status_private&src);
    void
    init(const TQString&url,const DirEntryPtr&src);
    void
    init(const TQString&url,const InfoEntry&src);

    void setPath(const TQString&);

    TQString m_Path;
    bool m_isVersioned;
    bool m_hasReal;
    LockEntry m_Lock;
    Entry m_entry;

    svn_wc_status_kind _text_status,_prop_status,_repos_text_status,_repos_prop_status;
    bool _copied,_switched;
  };

  Status_private::Status_private()
    :m_Path(),m_isVersioned(false),m_hasReal(false)
  {
  }

  Status_private::~ Status_private()
  {
  }

  void Status_private::setPath(const TQString&aPath)
  {
    Pool pool;
    if (!Url::isValid(aPath)) {
        m_Path = aPath;
    } else {
        const char * int_path = svn_path_uri_decode(aPath.TOUTF8(), pool.pool () );
        m_Path = TQString::FROMUTF8(int_path);
    }
  }

  void Status_private::init (const TQString&path, const svn_wc_status2_t * status)
  {
    setPath(path);
    if (!status)
    {
      m_isVersioned = false;
      m_hasReal = false;
      m_entry=Entry();
      m_Lock = LockEntry();
    }
    else
    {
      m_isVersioned = status->text_status > svn_wc_status_unversioned||status->repos_text_status>svn_wc_status_unversioned;
      m_hasReal = m_isVersioned &&
                          status->text_status!=svn_wc_status_ignored;
      // now duplicate the contents
      if (status->entry)
      {
        m_entry = Entry(status->entry);
      } else {
        m_entry=Entry();
      }
      _text_status = status->text_status;
      _prop_status = status->prop_status;
      _copied = status->copied!=0;
      _switched = status->switched!=0;
      _repos_text_status = status->repos_text_status;
      _repos_prop_status = status->repos_prop_status;
      if (status->repos_lock) {
        m_Lock.init(status->repos_lock->creation_date,
                    status->repos_lock->expiration_date,
                    status->repos_lock->owner,
                    status->repos_lock->comment,
                    status->repos_lock->token);
      } else {
        m_Lock=LockEntry();
      }
    }
  }

  void
  Status_private::init (const TQString&path,const Status_private&src)
  {
    setPath(path);
    m_Lock=src.m_Lock;
    m_entry=src.m_entry;
    m_isVersioned=src.m_isVersioned;
    m_hasReal=src.m_hasReal;
    _text_status=src._text_status;
    _prop_status=src._prop_status;
    _repos_text_status=src._repos_text_status;
    _repos_prop_status=src._repos_prop_status;
    _copied=src._copied;
    _switched=src._switched;
  }

  void Status_private::init(const TQString&url,const DirEntryPtr&src)
  {
    m_entry=Entry(url,src);
    setPath(url);
    _text_status = svn_wc_status_normal;
    _prop_status = svn_wc_status_normal;
    if (src) {
        m_Lock=src->lockEntry();
        m_isVersioned=true;
        m_hasReal=true;
    }
    _switched = false;
    _repos_text_status = svn_wc_status_normal;
    _repos_prop_status = svn_wc_status_normal;
  }

  void Status_private::init(const TQString&url,const InfoEntry&src)
  {
    m_entry=Entry(url,src);
    setPath(url);
    m_Lock=src.lockEntry();
    _text_status = svn_wc_status_normal;
    _prop_status = svn_wc_status_normal;
    _repos_text_status = svn_wc_status_normal;
    _repos_prop_status = svn_wc_status_normal;
    m_isVersioned=true;
    m_hasReal=true;
  }

  Status::Status (const Status & src)
    : m_Data(new Status_private())
  {
    if( &src != this )
    {
        if (src.m_Data) {
             m_Data->init (src.m_Data->m_Path, *(src.m_Data));
        } else {
            m_Data->init(src.m_Data->m_Path,0);
        }
    }
  }

  Status::Status (const TQString&path, svn_wc_status2_t * status)
    : m_Data(new Status_private())
  {
    m_Data->init(path, status);
  }

  Status::Status (const char*path, svn_wc_status2_t * status)
    : m_Data(new Status_private())
  {
    m_Data->init(TQString::FROMUTF8(path),status);
  }

  Status::Status(const TQString&url,const DirEntryPtr&src)
    : m_Data(new Status_private())
  {
    m_Data->init(url,src);
  }

  Status::Status(const TQString&url,const InfoEntry&src)
    : m_Data(new Status_private())
  {
    m_Data->init(url,src);
  }

  Status::~Status ()
  {
    delete m_Data;
  }

  Status &
  Status::operator=(const Status & status)
  {
    if (this == &status)
      return *this;
    if (status.m_Data) {
        m_Data->init (status.m_Data->m_Path, *(status.m_Data));
    } else {
        m_Data->init(status.m_Data->m_Path,0);
    }
    return *this;
  }

  const LockEntry&
  Status::lockEntry () const
  {
      return m_Data->m_Lock;
  }
    svn_wc_status_kind
    Status::reposPropStatus () const
    {
      return m_Data->_repos_prop_status;
    }
    svn_wc_status_kind
    Status::reposTextStatus () const
    {
      return m_Data->_repos_text_status;
    }
    bool
    Status::isSwitched () const
    {
      return m_Data->_switched != 0;
    }
    bool
    Status::isCopied () const
    {
      return m_Data->_copied;
    }

    bool
    Status::isLocked () const
    {
      return m_Data->m_Lock.Locked();
    }

    bool
    Status::isModified()const
    {
        return textStatus()==svn_wc_status_modified||propStatus()==svn_wc_status_modified
                ||textStatus ()==svn_wc_status_replaced;
    }

    bool
    Status::isRealVersioned()const
    {
      return m_Data->m_hasReal;
    }

    bool
    Status::isVersioned () const
    {
      return m_Data->m_isVersioned;
    }

    svn_wc_status_kind
    Status::propStatus () const
    {
      return m_Data->_prop_status;
    }

    svn_wc_status_kind
    Status::textStatus () const
    {
      return m_Data->_text_status;
    }

    const Entry&
    Status::entry () const
    {
      return m_Data->m_entry;
    }

    const TQString&
    Status::path () const
    {
      return m_Data->m_Path;
    }

    bool
    Status::validReposStatus()const
    {
        return reposTextStatus()!=svn_wc_status_none||reposPropStatus()!=svn_wc_status_none;
    }

    bool
    Status::validLocalStatus()const
    {
        return textStatus()!=svn_wc_status_none||propStatus()!=svn_wc_status_none;
    }
}