KiCad PCB EDA Suite
Loading...
Searching...
No Matches
local_history.cpp File Reference
#include <local_history.h>
#include <dialogs/dialog_restore_local_history.h>
#include <history_lock.h>
#include <paths.h>
#include <io/kicad/kicad_io_utils.h>
#include <lockfile.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <pgm_base.h>
#include <thread_pool.h>
#include <trace_helpers.h>
#include <wildcards_and_files_ext.h>
#include <confirm.h>
#include <progress_reporter.h>
#include <kiid.h>
#include <kiplatform/io.h>
#include <git2.h>
#include <git2/sys/odb_backend.h>
#include <gestfich.h>
#include <wx/filename.h>
#include <wx/filefn.h>
#include <wx/ffile.h>
#include <wx/dir.h>
#include <wx/datetime.h>
#include <wx/log.h>
#include <wx/msgdlg.h>
#include <wx/utils.h>
#include <vector>
#include <string>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <functional>
#include <chrono>
#include <cstring>

Go to the source code of this file.

Functions

static wxString historyPath (const wxString &aProjectPath)
 
static wxString joinHistoryDestination (const wxString &aHistoryRoot, const wxString &aRelativePath)
 
static bool readFileContent (const wxString &aPath, std::string &aContent)
 
static void removeLegacyWorkingCopies (git_repository *aRepo, const wxString &aHistoryRoot)
 
static bool filesContentEqual (const wxString &aPathA, const wxString &aPathB)
 
static wxString resolveAutosaveDestination (const wxString &aAutosaveRoot, const wxString &aRelativePath, BACKUP_LOCATION aLocation)
 
static wxString sourceForAutosaveFile (const wxString &aAutosavePath, const wxString &aProjectPath, const wxString &aAutosaveRoot, BACKUP_LOCATION aLocation)
 
static bool commitSnapshotForProject (const wxString &aProjectPath, const std::vector< wxString > &aFiles, const wxString &aTitle)
 
static bool localHistoryEnabled ()
 
static bool isProjectDirectory (const wxString &aProjectPath)
 
static bool isRestoreProtectedEntry (const wxString &aName)
 
static std::vector< std::pair< wxString, wxString > > findAutosaveFilePairs (const wxString &aProjectPath)
 
static SNAPSHOT_COMMIT_RESULT commitSnapshotWithLock (git_repository *repo, git_index *index, const wxString &aHistoryPath, const wxString &aProjectPath, const std::vector< wxString > &aFiles, const wxString &aTitle)
 
static bool isKiCadProjectFile (const wxFileName &aFile)
 
static void collectProjectFiles (const wxString &aProjectPath, std::vector< wxString > &aFiles)
 
static bool tagSaveAtHead (git_repository *repo, const wxString &aFileType)
 
static size_t dirSizeRecursive (const wxString &path)
 
static std::vector< wxString > listPackFiles (const wxString &aPackDir)
 
static bool writePack (git_packbuilder *aPb, const wxString &aPackDir, PROGRESS_REPORTER *aReporter, const std::atomic< bool > *aCancel=nullptr)
 
static void pruneLooseObjects (const wxString &aObjectsPath, const wxString &aPackIndex, time_t aWalkStart)
 
static wxString buildPack (git_repository *aRepo, const wxString &aPackDir, PROGRESS_REPORTER *aReporter, const std::atomic< bool > *aCancel)
 
static std::vector< wxString > supersededBy (const std::vector< wxString > &aPriorPacks, const wxString &aNewStem)
 
static bool compactRepository (git_repository *aRepo, PROGRESS_REPORTER *aReporter, std::vector< wxString > *aSupersededPacks)
 
static void removeStaleStageDirs (const wxString &aGitDir)
 
static std::vector< std::string > refTargets (git_repository *aRepo)
 
static size_t looseObjectBytes (const wxString &aObjectsPath)
 

Variables

static const wxString AUTOSAVE_PREFIX = wxS( "_autosave-" )
 
static const size_t UNLIMITED_HISTORY_LOOSE_BYTES = 25 * 1024 * 1024
 
static const time_t UNREACHABLE_LOOSE_EXPIRY_SECONDS = 24 * 60 * 60
 
static const wxString STAGE_DIR_PREFIX = wxS( "kicad-compact-" )
 

Function Documentation

◆ buildPack()

static wxString buildPack ( git_repository * aRepo,
const wxString & aPackDir,
PROGRESS_REPORTER * aReporter,
const std::atomic< bool > * aCancel )
static

Definition at line 1747 of file local_history.cpp.

References writePack().

Referenced by compactRepository(), and LOCAL_HISTORY::scheduleCompaction().

◆ collectProjectFiles()

static void collectProjectFiles ( const wxString & aProjectPath,
std::vector< wxString > & aFiles )
static

◆ commitSnapshotForProject()

static bool commitSnapshotForProject ( const wxString & aProjectPath,
const std::vector< wxString > & aFiles,
const wxString & aTitle )
static

◆ commitSnapshotWithLock()

static SNAPSHOT_COMMIT_RESULT commitSnapshotWithLock ( git_repository * repo,
git_index * index,
const wxString & aHistoryPath,
const wxString & aProjectPath,
const std::vector< wxString > & aFiles,
const wxString & aTitle )
static

◆ compactRepository()

static bool compactRepository ( git_repository * aRepo,
PROGRESS_REPORTER * aReporter,
std::vector< wxString > * aSupersededPacks )
static

◆ dirSizeRecursive()

static size_t dirSizeRecursive ( const wxString & path)
static

◆ filesContentEqual()

static bool filesContentEqual ( const wxString & aPathA,
const wxString & aPathB )
static

Definition at line 193 of file local_history.cpp.

Referenced by LOCAL_HISTORY::FindStaleAutosaveFiles().

◆ findAutosaveFilePairs()

◆ historyPath()

static wxString historyPath ( const wxString & aProjectPath)
static

◆ isKiCadProjectFile()

static bool isKiCadProjectFile ( const wxFileName & aFile)
static

Definition at line 1302 of file local_history.cpp.

References name.

Referenced by collectProjectFiles().

◆ isProjectDirectory()

◆ isRestoreProtectedEntry()

static bool isRestoreProtectedEntry ( const wxString & aName)
static

Definition at line 323 of file local_history.cpp.

References PROJECT_BACKUPS_DIR_SUFFIX.

Referenced by collectProjectFiles().

◆ joinHistoryDestination()

static wxString joinHistoryDestination ( const wxString & aHistoryRoot,
const wxString & aRelativePath )
static

Definition at line 70 of file local_history.cpp.

Referenced by removeLegacyWorkingCopies().

◆ listPackFiles()

static std::vector< wxString > listPackFiles ( const wxString & aPackDir)
static

Definition at line 1617 of file local_history.cpp.

References name.

Referenced by compactRepository(), and LOCAL_HISTORY::scheduleCompaction().

◆ localHistoryEnabled()

◆ looseObjectBytes()

static size_t looseObjectBytes ( const wxString & aObjectsPath)
static

Definition at line 2348 of file local_history.cpp.

References dirSizeRecursive().

Referenced by LOCAL_HISTORY::scheduleCompaction().

◆ pruneLooseObjects()

static void pruneLooseObjects ( const wxString & aObjectsPath,
const wxString & aPackIndex,
time_t aWalkStart )
static

◆ readFileContent()

static bool readFileContent ( const wxString & aPath,
std::string & aContent )
static

Definition at line 100 of file local_history.cpp.

Referenced by LOCAL_HISTORY::commitInBackground().

◆ refTargets()

static std::vector< std::string > refTargets ( git_repository * aRepo)
static

Definition at line 2315 of file local_history.cpp.

Referenced by LOCAL_HISTORY::scheduleCompaction().

◆ removeLegacyWorkingCopies()

static void removeLegacyWorkingCopies ( git_repository * aRepo,
const wxString & aHistoryRoot )
static

◆ removeStaleStageDirs()

static void removeStaleStageDirs ( const wxString & aGitDir)
static

◆ resolveAutosaveDestination()

static wxString resolveAutosaveDestination ( const wxString & aAutosaveRoot,
const wxString & aRelativePath,
BACKUP_LOCATION aLocation )
static

Definition at line 235 of file local_history.cpp.

References AUTOSAVE_PREFIX, and PROJECT_DIR.

Referenced by LOCAL_HISTORY::RunRegisteredSaversAsAutosaveFiles().

◆ sourceForAutosaveFile()

static wxString sourceForAutosaveFile ( const wxString & aAutosavePath,
const wxString & aProjectPath,
const wxString & aAutosaveRoot,
BACKUP_LOCATION aLocation )
static

Definition at line 258 of file local_history.cpp.

References AUTOSAVE_PREFIX, name, and PROJECT_DIR.

Referenced by LOCAL_HISTORY::CollectAutosaveFilePairs().

◆ supersededBy()

static std::vector< wxString > supersededBy ( const std::vector< wxString > & aPriorPacks,
const wxString & aNewStem )
static

Definition at line 1784 of file local_history.cpp.

Referenced by compactRepository(), and LOCAL_HISTORY::scheduleCompaction().

◆ tagSaveAtHead()

static bool tagSaveAtHead ( git_repository * repo,
const wxString & aFileType )
static

Definition at line 1402 of file local_history.cpp.

Referenced by LOCAL_HISTORY::RestoreCommit(), and LOCAL_HISTORY::TagSave().

◆ writePack()

static bool writePack ( git_packbuilder * aPb,
const wxString & aPackDir,
PROGRESS_REPORTER * aReporter,
const std::atomic< bool > * aCancel = nullptr )
static

Definition at line 1641 of file local_history.cpp.

References cancel, and reporter.

Referenced by buildPack(), and LOCAL_HISTORY::enforceSizeLimit().

Variable Documentation

◆ AUTOSAVE_PREFIX

const wxString AUTOSAVE_PREFIX = wxS( "_autosave-" )
static

◆ STAGE_DIR_PREFIX

const wxString STAGE_DIR_PREFIX = wxS( "kicad-compact-" )
static

Definition at line 2288 of file local_history.cpp.

Referenced by removeStaleStageDirs(), and LOCAL_HISTORY::scheduleCompaction().

◆ UNLIMITED_HISTORY_LOOSE_BYTES

const size_t UNLIMITED_HISTORY_LOOSE_BYTES = 25 * 1024 * 1024
static

Definition at line 97 of file local_history.cpp.

◆ UNREACHABLE_LOOSE_EXPIRY_SECONDS

const time_t UNREACHABLE_LOOSE_EXPIRY_SECONDS = 24 * 60 * 60
static

Definition at line 1681 of file local_history.cpp.

Referenced by pruneLooseObjects(), and removeStaleStageDirs().