Chris@109
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@109
|
2
|
Chris@109
|
3 /*
|
Chris@109
|
4 EasyMercurial
|
Chris@109
|
5
|
Chris@109
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@109
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@109
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@109
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@109
|
10
|
Chris@109
|
11 This program is free software; you can redistribute it and/or
|
Chris@109
|
12 modify it under the terms of the GNU General Public License as
|
Chris@109
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@109
|
14 License, or (at your option) any later version. See the file
|
Chris@109
|
15 COPYING included with this distribution for more information.
|
Chris@109
|
16 */
|
Chris@109
|
17
|
Chris@92
|
18 #include "filestates.h"
|
Chris@74
|
19
|
Chris@86
|
20 #include "debug.h"
|
Chris@86
|
21
|
Chris@74
|
22 #include <QMap>
|
Chris@74
|
23
|
Chris@94
|
24 FileStates::FileStates()
|
Chris@94
|
25 {
|
Chris@94
|
26 }
|
Chris@94
|
27
|
Chris@94
|
28 void FileStates::clearBuckets()
|
Chris@94
|
29 {
|
Chris@94
|
30 m_modified.clear();
|
Chris@94
|
31 m_added.clear();
|
Chris@94
|
32 m_removed.clear();
|
Chris@94
|
33 m_missing.clear();
|
Chris@94
|
34 m_unknown.clear();
|
Chris@94
|
35 }
|
Chris@94
|
36
|
Chris@94
|
37 FileStates::State FileStates::charToState(QChar c, bool *ok)
|
Chris@94
|
38 {
|
Chris@94
|
39 if (ok) *ok = true;
|
Chris@94
|
40 if (c == 'M') return Modified;
|
Chris@94
|
41 if (c == 'A') return Added;
|
Chris@94
|
42 if (c == 'R') return Removed;
|
Chris@94
|
43 if (c == '!') return Missing;
|
Chris@94
|
44 if (c == '?') return Unknown;
|
Chris@94
|
45 if (c == 'C') return Clean;
|
Chris@94
|
46 if (ok) *ok = false;
|
Chris@94
|
47 return Unknown;
|
Chris@94
|
48 }
|
Chris@94
|
49
|
Chris@94
|
50 QStringList *FileStates::stateToBucket(State s)
|
Chris@94
|
51 {
|
Chris@94
|
52 switch (s) {
|
Chris@94
|
53 case Clean: default: return 0; // not implemented yet
|
Chris@94
|
54 case Modified: return &m_modified;
|
Chris@94
|
55 case Added: return &m_added;
|
Chris@94
|
56 case Unknown: return &m_unknown;
|
Chris@94
|
57 case Removed: return &m_removed;
|
Chris@94
|
58 case Missing: return &m_missing;
|
Chris@94
|
59 }
|
Chris@94
|
60 }
|
Chris@94
|
61
|
Chris@94
|
62 void FileStates::parseStates(QString text)
|
Chris@74
|
63 {
|
Chris@74
|
64 text.replace("\r\n", "\n");
|
Chris@74
|
65
|
Chris@94
|
66 clearBuckets();
|
Chris@74
|
67
|
Chris@74
|
68 QStringList lines = text.split("\n", QString::SkipEmptyParts);
|
Chris@94
|
69
|
Chris@74
|
70 foreach (QString line, lines) {
|
Chris@94
|
71
|
Chris@86
|
72 if (line.length() < 3 || line[1] != ' ') {
|
Chris@86
|
73 continue;
|
Chris@86
|
74 }
|
Chris@94
|
75
|
Chris@94
|
76 QChar c = line[0];
|
Chris@94
|
77 bool ok = false;
|
Chris@94
|
78 State s = charToState(c, &ok);
|
Chris@94
|
79 if (!ok) continue;
|
Chris@94
|
80
|
Chris@74
|
81 QString file = line.right(line.length() - 2);
|
Chris@94
|
82 QStringList *bucket = stateToBucket(s);
|
Chris@94
|
83 bucket->push_back(file);
|
Chris@94
|
84 m_stateMap[file] = s;
|
Chris@74
|
85 }
|
Chris@86
|
86
|
Chris@94
|
87 DEBUG << "FileStates: " << m_modified.size() << " modified, " << m_added.size()
|
Chris@94
|
88 << " added, " << m_removed.size() << " removed, " << m_missing.size()
|
Chris@94
|
89 << " missing, " << m_unknown.size() << " unknown" << endl;
|
Chris@74
|
90 }
|
Chris@92
|
91
|
Chris@94
|
92 QStringList FileStates::getFilesInState(State s) const
|
Chris@92
|
93 {
|
Chris@94
|
94 QStringList *sl = const_cast<FileStates *>(this)->stateToBucket(s);
|
Chris@94
|
95 if (sl) return *sl;
|
Chris@94
|
96 else return QStringList();
|
Chris@92
|
97 }
|
Chris@92
|
98
|
Chris@94
|
99 FileStates::State FileStates::getStateOfFile(QString file) const
|
Chris@92
|
100 {
|
Chris@94
|
101 if (m_stateMap.contains(file)) {
|
Chris@94
|
102 return m_stateMap[file];
|
Chris@92
|
103 }
|
Chris@92
|
104 DEBUG << "FileStates: WARNING: getStateOfFile: file "
|
Chris@92
|
105 << file << " is unknown to us: returning Unknown state, "
|
Chris@92
|
106 << "but unknown to us is not supposed to be the same "
|
Chris@92
|
107 << "thing as unknown state..."
|
Chris@92
|
108 << endl;
|
Chris@92
|
109 return Unknown;
|
Chris@92
|
110 }
|