summaryrefslogtreecommitdiffstats
path: root/vcs/cvsservice/cvsentry.cpp
blob: bf478f7c398f5984498b14e4c1e95200b27511a6 (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
/***************************************************************************
 *   Copyright (C) 2003 by Mario Scalas                                    *
 *   mario.scalas@libero.it                                                *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqfile.h>
#include <tqtextstream.h>

#include "cvsentry.h"
#include "cvsdir.h"

///////////////////////////////////////////////////////////////////////////////
// Static
///////////////////////////////////////////////////////////////////////////////

const TQString CVSEntry::invalidMarker = "<Invalid entry>";
const TQString CVSEntry::directoryMarker = "D";
const TQString CVSEntry::fileMarker = "";
const TQString CVSEntry::entrySeparator = "/";

///////////////////////////////////////////////////////////////////////////////
// class CVSEntry
///////////////////////////////////////////////////////////////////////////////

CVSEntry::CVSEntry()
{
    clean();
}

///////////////////////////////////////////////////////////////////////////////

CVSEntry::CVSEntry( const TQString &aLine, const CVSDir& dir )
{
    parse( aLine, dir );
}

///////////////////////////////////////////////////////////////////////////////

void CVSEntry::clean()
{
    m_type = invalidEntry;
    m_state = Unknown;
}

///////////////////////////////////////////////////////////////////////////////

CVSEntry::EntryType CVSEntry::type() const
{
    return m_type;
}

///////////////////////////////////////////////////////////////////////////////

void CVSEntry::parse( const TQString &aLine, const CVSDir& dir )
{
    clean();

    m_fields = TQStringList::split( "/", aLine );

    if (aLine.startsWith( entrySeparator )) // Is a file?
    {
        m_type = fileEntry; // Is a file
    }
    else if (aLine.startsWith( directoryMarker )) // Must be a directory then
    {
        m_type = directoryEntry; // Is a directory
        m_fields.pop_front(); // TQStringList::split() fills and empty item in head
	return;
    }
    else // What the hell is this? >:-)
    {
        m_type = invalidEntry;
	return;
    }

    //if we're a file, keep going
    TQDateTime entryFileDate(TQDateTime::fromString(timeStamp()));
    TQDateTime realFileDate;
    TQFileInfo info(dir, m_fields[0]);
    realFileDate = info.lastModified();

    m_state = UpToDate;

    if ( revision() == "0" )
        m_state = Added;
    else if ( revision().length() > 3 && revision()[0] == '-' )
        m_state = Removed;
    else if ( timeStamp().find('+') >= 0 )
        m_state = Conflict;
    else
    {
        TQDateTime date( TQDateTime::fromString( timeStamp() ) );
        TQDateTime fileDateUTC;
        fileDateUTC.setTime_t( TQFileInfo(dir, fileName()).lastModified().toTime_t(), Qt::UTC );
        if ( date != fileDateUTC )
            m_state = Modified;
    }
}

///////////////////////////////////////////////////////////////////////////////

TQString CVSEntry::fileName() const
{
    if (type() != invalidEntry && m_fields.count() >= 1)
        return m_fields[0];
    else
        return TQString();
}

///////////////////////////////////////////////////////////////////////////////

TQString CVSEntry::revision() const
{
    if (type() != invalidEntry && m_fields.count() >= 2)
        return m_fields[1];
    else
        return TQString();
}

///////////////////////////////////////////////////////////////////////////////

TQString CVSEntry::timeStamp() const
{
    if (type() != invalidEntry && m_fields.count() >= 3)
        return m_fields[2];
    else
        return TQString();
}

///////////////////////////////////////////////////////////////////////////////

TQString CVSEntry::options() const
{
    if (type() != invalidEntry && m_fields.count() >= 4)
        return m_fields[3];
    else
        return TQString();
}

///////////////////////////////////////////////////////////////////////////////

TQString CVSEntry::tag() const
{
    if (type() != invalidEntry && m_fields.count() >= 5)
        return m_fields[4];
    else
        return TQString();
}

///////////////////////////////////////////////////////////////////////////////

VCSFileInfo CVSEntry::toVCSFileInfo() const
{
    VCSFileInfo::FileState fileState = VCSFileInfo::Unknown;
    if (isDirectory())
        fileState = VCSFileInfo::Directory;

    switch (m_state)
    {
        case Added:
            fileState = VCSFileInfo::Added;
            break;
        case Conflict:
            fileState = VCSFileInfo::Conflict;
            break;
        case Modified:
        case Removed:
            fileState = VCSFileInfo::Modified;
            break;
        case UpToDate:
            fileState = VCSFileInfo::Uptodate;
            break;
        default:
            fileState = VCSFileInfo::Unknown;
            break;
    }

    return VCSFileInfo( fileName(), revision(), revision(), fileState );
}

//kate: space-indent on; indent-width 4; replace-tabs on;