annotate filestates.cpp @ 201:0844b4d8d911

* Ensure explorer.exe invocation gets backslashes as directory separators, not forward slashes
author Chris Cannam
date Tue, 04 Jan 2011 14:05:17 +0000
parents f16fe0db11f3
children 3cc6455e58c2
rev   line source
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@199 30 m_clean.clear();
Chris@94 31 m_modified.clear();
Chris@94 32 m_added.clear();
Chris@94 33 m_removed.clear();
Chris@94 34 m_missing.clear();
Chris@159 35 m_inConflict.clear();
Chris@94 36 m_unknown.clear();
Chris@199 37 m_ignored.clear();
Chris@94 38 }
Chris@94 39
Chris@94 40 FileStates::State FileStates::charToState(QChar c, bool *ok)
Chris@94 41 {
Chris@159 42 // Note that InConflict does not correspond to a stat char -- it's
Chris@163 43 // reported separately, by resolve --list, which shows U for
Chris@163 44 // Unresolved -- stat reports files in conflict as M, which means
Chris@163 45 // they will appear in more than one bin if we handle them
Chris@163 46 // naively. 'u' is also used by stat as the command option for
Chris@163 47 // Unknown, but the stat output uses ? for these so there's no
Chris@163 48 // ambiguity in parsing.
Chris@159 49
Chris@94 50 if (ok) *ok = true;
Chris@94 51 if (c == 'M') return Modified;
Chris@94 52 if (c == 'A') return Added;
Chris@94 53 if (c == 'R') return Removed;
Chris@94 54 if (c == '!') return Missing;
Chris@163 55 if (c == 'U') return InConflict;
Chris@94 56 if (c == '?') return Unknown;
Chris@94 57 if (c == 'C') return Clean;
Chris@199 58 if (c == 'I') return Ignored;
Chris@94 59 if (ok) *ok = false;
Chris@94 60 return Unknown;
Chris@94 61 }
Chris@94 62
Chris@94 63 QStringList *FileStates::stateToBucket(State s)
Chris@94 64 {
Chris@94 65 switch (s) {
Chris@199 66 case Clean: return &m_clean; // not implemented yet
Chris@94 67 case Modified: return &m_modified;
Chris@94 68 case Added: return &m_added;
Chris@94 69 case Unknown: return &m_unknown;
Chris@94 70 case Removed: return &m_removed;
Chris@94 71 case Missing: return &m_missing;
Chris@159 72 case InConflict: return &m_inConflict;
Chris@199 73 case Ignored: return &m_ignored;
Chris@94 74 }
Chris@94 75 }
Chris@94 76
Chris@94 77 void FileStates::parseStates(QString text)
Chris@74 78 {
Chris@74 79 text.replace("\r\n", "\n");
Chris@74 80
Chris@94 81 clearBuckets();
Chris@163 82 m_stateMap.clear();
Chris@74 83
Chris@74 84 QStringList lines = text.split("\n", QString::SkipEmptyParts);
Chris@94 85
Chris@74 86 foreach (QString line, lines) {
Chris@94 87
Chris@86 88 if (line.length() < 3 || line[1] != ' ') {
Chris@86 89 continue;
Chris@86 90 }
Chris@94 91
Chris@94 92 QChar c = line[0];
Chris@94 93 bool ok = false;
Chris@94 94 State s = charToState(c, &ok);
Chris@94 95 if (!ok) continue;
Chris@94 96
Chris@74 97 QString file = line.right(line.length() - 2);
Chris@163 98 m_stateMap[file] = s;
Chris@163 99 }
Chris@163 100
Chris@163 101 foreach (QString file, m_stateMap.keys()) {
Chris@163 102 QStringList *bucket = stateToBucket(m_stateMap[file]);
Chris@199 103 if (bucket) bucket->push_back(file);
Chris@74 104 }
Chris@86 105
Chris@199 106 DEBUG << "FileStates: "
Chris@199 107 << m_modified.size() << " modified, " << m_added.size()
Chris@159 108 << " added, " << m_removed.size() << " removed, " << m_missing.size()
Chris@159 109 << " missing, " << m_inConflict.size() << " in conflict, "
Chris@159 110 << m_unknown.size() << " unknown" << endl;
Chris@74 111 }
Chris@92 112
Chris@94 113 QStringList FileStates::getFilesInState(State s) const
Chris@92 114 {
Chris@94 115 QStringList *sl = const_cast<FileStates *>(this)->stateToBucket(s);
Chris@94 116 if (sl) return *sl;
Chris@94 117 else return QStringList();
Chris@92 118 }
Chris@92 119
Chris@94 120 FileStates::State FileStates::getStateOfFile(QString file) const
Chris@92 121 {
Chris@94 122 if (m_stateMap.contains(file)) {
Chris@94 123 return m_stateMap[file];
Chris@92 124 }
Chris@92 125 DEBUG << "FileStates: WARNING: getStateOfFile: file "
Chris@92 126 << file << " is unknown to us: returning Unknown state, "
Chris@92 127 << "but unknown to us is not supposed to be the same "
Chris@92 128 << "thing as unknown state..."
Chris@92 129 << endl;
Chris@92 130 return Unknown;
Chris@92 131 }