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 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
/*
** 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Author : Alexandre Parenteau <aubonbeurre@hotmail.com> --- April 1998
* Modified: Jerzy Kaczorowski <kaczoroj@hotmail.com> - 27 Jan 2001 - fix warning C4800 (Add "0 != " for all the int variables forced to bool value)
*/
/*
* CvsEntries.h --- adaptation from cvs/src/entries.c
*/
#ifndef CVSENTRIES_H
#define CVSENTRIES_H
#include "SortList.h"
#include "CvsIgnore.h"
#include "TextBinary.h"
typedef enum
{
ENT_FILE,
ENT_SUBDIR
} ent_type;
// ref counted full path description, see below
class EntnodePath
{
protected:
// reference counted, we don't use delete on it.
~EntnodePath();
public:
EntnodePath(const char* path);
// ref counting
inline EntnodePath *Ref(void) {++ref; return this;}
inline EntnodePath *UnRef(void)
{
if(--ref == 0)
{
delete this;
return 0L;
}
return this;
}
const char* GetFullPathName(UStr & resPath, const char* name) const;
inline const char* GetFolderPath(void) const { return fullpathname; }
protected:
const char* fullpathname; // fully qualified pathname of the folder containing the item
int ref;
};
class EntnodeData
{
// Construction
protected:
// used by derived classes only
EntnodeData(const char* name, EntnodePath *path);
// cannot use 'delete', use UnRef() instead.
virtual ~EntnodeData();
public:
enum
{
kName = 0,
kStatus = 3,
kPath = 7
};
virtual ent_type GetType(void) const = 0;
inline static int Compare(const EntnodeData & node1, const EntnodeData & node2)
{
#ifdef WIN32
return stricmp(node1.user, node2.user);
#else /* !WIN32 */
return strcmp(node1.user, node2.user);
#endif /* !WIN32 */
}
inline EntnodeData *Ref(void) {++ref; return this;}
inline EntnodeData *UnRef(void)
{
if(--ref == 0)
{
delete this;
return 0L;
}
return this;
}
virtual const char *operator[](int index) const
{
if(index == kName)
return user;
else if(index == kStatus)
return desc;
else if(index == kPath)
return GetFullPathName(sbuffer);
return 0L;
}
inline void SetMissing(bool state) {missing = state;}
inline bool IsMissing(void) const {return 0 != missing;}
inline void SetVisited(bool state) {visited = state;}
inline bool IsVisited(void) const {return 0 != visited;}
inline void SetUnknown(bool state) {unknown = state;}
inline bool IsUnknown(void) const {return 0 != unknown;}
inline void SetIgnored(bool state) {ignored = state;}
inline bool IsIgnored(void) const {return 0 != ignored;}
inline void SetLocked(bool state) {locked = state;}
inline bool IsLocked(void) const {return 0 != locked;}
inline void SetRemoved(bool state) {removed = state;}
inline bool IsRemoved(void) const {return 0 != removed;}
void SetDesc(const char *newdesc);
inline const char *GetDesc(void) const {return desc;}
// accessor for item name
const char* GetName(void) const
{
return user;
}
// accessor for fully qualified item name
const char* GetFullPathName(UStr & resPath) const
{
return fullpathname->GetFullPathName(resPath, user);
}
// accessor for fully qualified folder name of the item
inline const char* GetFolderPath(void) const
{
return fullpathname->GetFolderPath();
}
// returns non-null if this is a files that is marked as having merge conflict
virtual const char* GetConflict() const
{
return 0L;
}
inline void SetUnmodified(bool state) {unmodified = state;}
inline bool IsUnmodified(void) const {return 0 != unmodified;}
#ifdef macintosh
UFSSpec & MacSpec(void) {return macspec;}
const UFSSpec & GetMacSpec(void) const {return macspec;}
#endif /* macintosh */
protected:
int ref;
int missing : 1;
int visited : 1;
int unknown : 1;
int unmodified : 1;
int ignored : 1;
int locked : 1;
int removed : 1;
#ifdef macintosh
UFSSpec macspec;
#endif /* macintosh */
private:
const char* user; // name of this item
const char* desc; // its description
EntnodePath *fullpathname; // fully qualified pathname of the folder containing the item
static UStr sbuffer;
};
class EntnodeFile : public EntnodeData
{
public:
EntnodeFile(const char* name, EntnodePath *path, const char *newvn = 0L,
const char *newts = 0L, const char *newoptions = 0L,
const char *newtag = 0L, const char *newdate = 0L,
const char *newts_conflict = 0L);
protected:
// cannot use 'delete', use UnRef() instead.
virtual ~EntnodeFile();
// Attribute access
public:
enum
{
kVN = 1,
kTS = 5,
kOption = 2,
kTag = 4,
kConflict = 6
};
// access fields
virtual const char *operator[](int index) const
{
if(index == kVN)
return vn;
else if(index == kTS)
return ts;
else if(index == kOption)
return option;
else if(index == kTag)
return tag != 0L ? tag : date;
else if(index == kConflict)
return ts_conflict;
return EntnodeData::operator[](index);
}
virtual ent_type GetType(void) const
{
return ENT_FILE;
}
// returns non-null if this is a files that is marked as having merge conflict
virtual const char* GetConflict() const
{
return ts_conflict;
}
protected:
const char *vn;
const char *ts;
const char *option;
const char *tag; // can be nil
const char *date; // can be nil
const char *ts_conflict; // can be nil
};
class EntnodeFolder : public EntnodeData
{
// Construction
public:
EntnodeFolder(const char* name, EntnodePath * path, const char *newvn = 0L,
const char *newts = 0L, const char *newoptions = 0L, const char *newtag = 0L,
const char *newdate = 0L, const char *newts_conflict = 0L);
protected:
// cannot use 'delete', use UnRef() instead.
virtual ~EntnodeFolder();
// Attribute access
public:
// access fields
virtual const char *operator[](int index) const
{
return EntnodeData::operator[](index);
}
virtual ent_type GetType(void) const
{
return ENT_SUBDIR;
}
protected:
};
// ENTNODE gets a node file or a node folder
// and reference it.
class ENTNODE
{
public:
ENTNODE() : shareData(0L) {}
ENTNODE(EntnodeData *data) : shareData(data->Ref()) {}
ENTNODE(EntnodeData & data) : shareData(data.Ref()) {}
ENTNODE(const ENTNODE & anode) : shareData(0L)
{
*this = anode;
}
~ENTNODE()
{
if(shareData != 0L)
shareData->UnRef();
}
inline static int Compare(const ENTNODE & node1, const ENTNODE & node2)
{
return EntnodeData::Compare(*node1.shareData, *node2.shareData);
}
inline ENTNODE & operator=(const ENTNODE & anode)
{
EntnodeData* oldData = shareData;
shareData = anode.shareData;
if(shareData != 0L)
{
shareData->Ref();
}
if(oldData != 0L)
{
oldData->UnRef();
}
return *this;
}
inline EntnodeData* Data() const { return shareData; }
inline operator EntnodeData *() const { return shareData; }
protected:
EntnodeData *shareData;
};
bool Entries_Open (CSortList<ENTNODE> & entries, const char *fullpath);
// return false if no CVS/Entries
EntnodeData *Entries_SetVisited(const char *path, CSortList<ENTNODE> & entries, const char *name,
const struct stat & finfo, bool isFolder, const std::vector<CStr> * ignlist = 0L);
// fill an ENTNODE when the file appears on the disk : it set
// some flags like "visited", "unknown", "ignored"... and return
// a reference to the node.
void Entries_SetMissing(CSortList<ENTNODE> & entries);
// After the traversal and for the entries which didn't have a
// "Entries_SetVisited" call associated with, mark them to be "missing".
bool Tag_Open(CStr & tag, const char *fullpath);
// return false if no CVS/Tag
#endif /* CVSENTRIES_H */
|