Changeset 0682d7ac9234…
Parent 6c05aa69d95b…
by
Changes to 4 files · Browse files at 0682d7ac9234 Showing diff from parent 6c05aa69d95b Diff from another changeset...
|
@@ -0,0 +1,98 @@ +
+// Copyright (C) 2009 Benjamin Pollack
+// Copyright (C) 2009 Adrian Buehlmann
+//
+// 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.
+//
+// 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, see <http://www.gnu.org/licenses/>.
+
+#include "stdafx.h"
+
+#include "Dirstatecache.h"
+#include "dirstate.h"
+#include "Winstat.h"
+
+#include <list>
+
+
+Dirstate* Dirstatecache::get(const std::string& hgroot)
+{
+ typedef std::list<E>::iterator Iter;
+
+ static std::list<Dirstatecache::E> _cache;
+
+ Iter iter = _cache.begin();
+
+ for (;iter != _cache.end(); ++iter)
+ {
+ if (hgroot == iter->hgroot)
+ break;
+ }
+
+ bool isnew = false;
+
+ if (iter == _cache.end())
+ {
+ if (_cache.size() >= 10)
+ {
+ TDEBUG_TRACE("Dirstatecache::get: dropping " << _cache.back().hgroot);
+ delete _cache.back().dstate;
+ _cache.back().dstate = 0;
+ _cache.pop_back();
+ }
+ E e;
+ e.hgroot = hgroot;
+ _cache.push_front(e);
+ iter = _cache.begin();
+ isnew = true;
+ }
+
+ unsigned tc = GetTickCount();
+
+ std::string path = hgroot + "\\.hg\\dirstate";
+
+ Winstat stat;
+
+ bool stat_done = false;
+
+ if (isnew || (tc - iter->tickcount) > 500)
+ {
+ if (0 != stat.lstat(path.c_str()))
+ {
+ TDEBUG_TRACE("Dirstatecache::get: lstat(" << path <<") failed");
+ return 0;
+ }
+ iter->tickcount = tc;
+ stat_done = true;
+ TDEBUG_TRACE("Dirstatecache::get: lstat(" << path <<") ok ");
+ }
+
+ if (stat_done && iter->dstate_mtime < stat.mtime)
+ {
+ iter->dstate_mtime = stat.mtime;
+ if (iter->dstate) {
+ delete iter->dstate;
+ iter->dstate = 0;
+ TDEBUG_TRACE("Dirstatecache::get: refreshing " << hgroot);
+ } else {
+ TDEBUG_TRACE("Dirstatecache::get: reading " << hgroot);
+ }
+ unsigned tc0 = GetTickCount();
+ iter->dstate = Dirstate::read(path).release();
+ unsigned tc1 = GetTickCount();
+ unsigned delta = tc1 - tc0;
+ TDEBUG_TRACE("Dirstatecache::get: read done in " << delta << " ticks, "
+ << _cache.size() << " repos in cache");
+ }
+
+ return iter->dstate;
+}
|
|
@@ -0,0 +1,42 @@ +
+// Copyright (C) 2009 Benjamin Pollack
+// Copyright (C) 2009 Adrian Buehlmann
+//
+// 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.
+//
+// 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, see <http://www.gnu.org/licenses/>.
+
+#ifndef _DIRSTATECACHE_H
+#define _DIRSTATECACHE_H
+
+#include <string>
+
+class Dirstate;
+
+class Dirstatecache
+{
+ struct E
+ {
+ Dirstate* dstate;
+ __time64_t dstate_mtime;
+
+ std::string hgroot;
+ unsigned tickcount;
+
+ E(): dstate(0), dstate_mtime(0), tickcount(0) {}
+ };
+
+public:
+ static Dirstate* get(const std::string& hgroot);
+};
+
+#endif
|
@@ -14,6 +14,7 @@ ShellUtils2.o \
StringUtils.o \
dirstate.o \
+ Dirstatecache.o \
QueryDirstate.o
BASE_LDFLAGS=-lole32 -lkernel32 -luser32 -lgdi32 -lshlwapi -lwininet \
|
|
@@ -20,109 +20,12 @@ #include "QueryDirstate.h"
#include "dirstate.h"
#include "DirectoryStatus.h"
+#include "Dirstatecache.h"
#include "TortoiseUtils.h"
#include "Winstat.h"
#include <shlwapi.h>
-#include <vector>
-#include <list>
-
-
-#define HASH_LENGTH 20
-
-
-class Dirstatecache
-{
- struct E
- {
- Dirstate* dstate;
- __time64_t dstate_mtime;
-
- std::string hgroot;
- unsigned tickcount;
-
- E(): dstate(0), dstate_mtime(0), tickcount(0) {}
- };
-
-public:
- static Dirstate* get(const std::string& hgroot);
-};
-
-
-Dirstate* Dirstatecache::get(const std::string& hgroot)
-{
- typedef std::list<E>::iterator Iter;
-
- static std::list<Dirstatecache::E> _cache;
-
- Iter iter = _cache.begin();
-
- for (;iter != _cache.end(); ++iter)
- {
- if (hgroot == iter->hgroot)
- break;
- }
-
- bool isnew = false;
-
- if (iter == _cache.end())
- {
- if (_cache.size() >= 10)
- {
- TDEBUG_TRACE("Dirstatecache::get: dropping " << _cache.back().hgroot);
- delete _cache.back().dstate;
- _cache.back().dstate = 0;
- _cache.pop_back();
- }
- E e;
- e.hgroot = hgroot;
- _cache.push_front(e);
- iter = _cache.begin();
- isnew = true;
- }
-
- unsigned tc = GetTickCount();
-
- std::string path = hgroot + "\\.hg\\dirstate";
-
- Winstat stat;
-
- bool stat_done = false;
-
- if (isnew || (tc - iter->tickcount) > 500)
- {
- if (0 != stat.lstat(path.c_str()))
- {
- TDEBUG_TRACE("Dirstatecache::get: lstat(" << path <<") failed");
- return 0;
- }
- iter->tickcount = tc;
- stat_done = true;
- TDEBUG_TRACE("Dirstatecache::get: lstat(" << path <<") ok ");
- }
-
- if (stat_done && iter->dstate_mtime < stat.mtime)
- {
- iter->dstate_mtime = stat.mtime;
- if (iter->dstate) {
- delete iter->dstate;
- iter->dstate = 0;
- TDEBUG_TRACE("Dirstatecache::get: refreshing " << hgroot);
- } else {
- TDEBUG_TRACE("Dirstatecache::get: reading " << hgroot);
- }
- unsigned tc0 = GetTickCount();
- iter->dstate = Dirstate::read(path).release();
- unsigned tc1 = GetTickCount();
- unsigned delta = tc1 - tc0;
- TDEBUG_TRACE("Dirstatecache::get: read done in " << delta << " ticks, "
- << _cache.size() << " repos in cache");
- }
-
- return iter->dstate;
-}
-
int HgQueryDirstate(
const std::string& path, const char& filterStatus, char& outStatus)
|
Loading...