diff --git a/uppsrc/TextDiffCtrl/PatchDiff.cpp b/uppsrc/TextDiffCtrl/PatchDiff.cpp index fb8fb95e2..70a22b9ab 100644 --- a/uppsrc/TextDiffCtrl/PatchDiff.cpp +++ b/uppsrc/TextDiffCtrl/PatchDiff.cpp @@ -90,6 +90,8 @@ bool PatchDiff::Open(const char *patch_path, const Vector& target_dirs) return false; } + patch_file <<= patch_path; + if(!patch.MatchFiles(target_dirs, pi)) { Exclamation("Unable to match the directory structure!"); return true; @@ -97,7 +99,6 @@ bool PatchDiff::Open(const char *patch_path, const Vector& target_dirs) String target_dir = patch.GetTargetDir(); - patch_file <<= patch_path; this->target_dir <<= target_dir; list.Clear(); diff --git a/uppsrc/TextDiffCtrl/TextDiffCtrl.h b/uppsrc/TextDiffCtrl/TextDiffCtrl.h index 578ddb172..34e8b911a 100644 --- a/uppsrc/TextDiffCtrl/TextDiffCtrl.h +++ b/uppsrc/TextDiffCtrl/TextDiffCtrl.h @@ -283,6 +283,7 @@ struct Patch { static int MatchLen(const String& a, const String& b); int MatchCount(const char *dir); + bool Load0(Stream& in, Progress& pi); public: bool Load(Stream& in, Progress& pi); diff --git a/uppsrc/TextDiffCtrl/patch.cpp b/uppsrc/TextDiffCtrl/patch.cpp index 7ca78fc8d..d3f41d41a 100644 --- a/uppsrc/TextDiffCtrl/patch.cpp +++ b/uppsrc/TextDiffCtrl/patch.cpp @@ -2,25 +2,7 @@ namespace Upp { -int Patch::MatchLen(const String& a, const String& b) -{ - int n = min(a.GetLength(), b.GetLength()); - for(int i = 0; i < n; i++) - if(a[i] != b[i]) - return i; - return n; -} - -int Patch::MatchCount(const char *dir) -{ - int count = 0; - for(const String& p : file.GetKeys()) - if(FileExists(AppendFileName(dir, p))) - count++; - return count; -} - -bool Patch::Load(Stream& in, Progress& pi) +bool Patch::Load0(Stream& in, Progress& pi) { pi.SetText("Loading patch file"); target_dir.Clear(); @@ -40,7 +22,7 @@ bool Patch::Load(Stream& in, Progress& pi) int q = ln.Find('\t'); if(q >= 0) ln.Trim(q); - String fn = UnixPath(ln); + String fn = UnixPath(TrimLeft("\"", TrimRight("\"", ln))); Array& fp = file.GetAdd(fn); while(!ln.StartsWith("@@")) { if(pi.StepCanceled()) @@ -81,11 +63,15 @@ bool Patch::Load(Stream& in, Progress& pi) } } } + return ok; } -bool Patch::MatchFiles(const Vector& dir, Progress& pi) +bool Patch::Load(Stream& in, Progress& pi) { + common_path.Clear(); + if(!Load0(in, pi)) + return false; const Vector& h = file.GetKeys(); if(h.GetCount() == 0) return false; @@ -96,7 +82,34 @@ bool Patch::MatchFiles(const Vector& dir, Progress& pi) common_path.TrimStart("/"); for(int i = 0; i < h.GetCount(); i++) file.SetKey(i, h[i].Mid(common_path.GetCount() + 1)); + return true; +} +int Patch::MatchLen(const String& a, const String& b) +{ + int n = min(a.GetLength(), b.GetLength()); + int q = 0; + for(int i = 0; i < n; i++) { + if(a[i] != b[i]) + return q; + if(a[i] == '/') + q = i; + } + return a[n] || b[n] ? b[n] == '/' || a[n] == '/' ? n : q : n; +} + +int Patch::MatchCount(const char *dir) +{ + int count = 0; + for(const String& p : file.GetKeys()) { + if(FileExists(AppendFileName(dir, p))) + count++; + } + return count; +} + +bool Patch::MatchFiles(const Vector& dir, Progress& pi) +{ pi.SetText("Matching directories"); int best = 0; String com_path = common_path;