public IList<PatchFile> GetRebasePatchFiles() { var patchFiles = new List<PatchFile>(); var nextFile = GetNextRebasePatch(); int next; int.TryParse(nextFile, out next); var files = new string[0]; if (Directory.Exists(GetRebaseDir())) files = Directory.GetFiles(GetRebaseDir()); foreach (var fullFileName in files) { int n; var file = fullFileName.Substring(fullFileName.LastIndexOf(AppSettings.PathSeparator.ToString()) + 1); if (!int.TryParse(file, out n)) continue; var patchFile = new PatchFile { Name = file, FullName = fullFileName, IsNext = n == next, IsSkipped = n < next }; if (File.Exists(GetRebaseDir() + file)) { string key = null; string value = null; foreach (var line in File.ReadLines(GetRebaseDir() + file)) { var m = HeadersMatch.Match(line); if (key == null) { if (!String.IsNullOrWhiteSpace(line) && !m.Success) continue; } else if (String.IsNullOrWhiteSpace(line) || m.Success) { value = DecodeString(value); switch (key) { case "From": if (value.IndexOf('<') > 0 && value.IndexOf('<') < value.Length) patchFile.Author = value.Substring(0, value.IndexOf('<')).Trim(); else patchFile.Author = value; break; case "Date": if (value.IndexOf('+') > 0 && value.IndexOf('<') < value.Length) patchFile.Date = value.Substring(0, value.IndexOf('+')).Trim(); else patchFile.Date = value; break; case "Subject": patchFile.Subject = value; break; } } if (m.Success) { key = m.Groups[1].Value; value = m.Groups[2].Value; } else value = AppendQuotedString(value, line.Trim()); if (string.IsNullOrEmpty(line) || !string.IsNullOrEmpty(patchFile.Author) && !string.IsNullOrEmpty(patchFile.Date) && !string.IsNullOrEmpty(patchFile.Subject)) break; } } patchFiles.Add(patchFile); } return patchFiles; }
public static List<PatchFile> GetRebasePatchFiles() { var patchFiles = new List<PatchFile>(); var nextFile = GetNextRebasePatch(); int next; int.TryParse(nextFile, out next); var files = new string[0]; if (Directory.Exists(GetRebaseDir())) files = Directory.GetFiles(GetRebaseDir()); foreach (var fullFileName in files) { int n; var file = fullFileName.Substring(fullFileName.LastIndexOf(Settings.PathSeparator) + 1); if (!int.TryParse(file, out n)) continue; var patchFile = new PatchFile { Name = file, FullName = fullFileName, IsNext = n == next, IsSkipped = n < next }; if (File.Exists(GetRebaseDir() + file)) { foreach (var line in File.ReadAllLines(GetRebaseDir() + file)) { if (line.StartsWith("From: ")) if (line.IndexOf('<') > 0 && line.IndexOf('<') < line.Length) patchFile.Author = line.Substring(6, line.IndexOf('<') - 6).Trim(); else patchFile.Author = line.Substring(6).Trim(); if (line.StartsWith("Date: ")) if (line.IndexOf('+') > 0 && line.IndexOf('<') < line.Length) patchFile.Date = line.Substring(6, line.IndexOf('+') - 6).Trim(); else patchFile.Date = line.Substring(6).Trim(); if (line.StartsWith("Subject: ")) patchFile.Subject = line.Substring(9).Trim(); if (!string.IsNullOrEmpty(patchFile.Author) && !string.IsNullOrEmpty(patchFile.Date) && !string.IsNullOrEmpty(patchFile.Subject)) break; } } patchFiles.Add(patchFile); } return patchFiles; }
public IList<PatchFile> GetInteractiveRebasePatchFiles() { string todoFile = GetRebaseDir() + "git-rebase-todo"; string[] todoCommits = File.Exists(todoFile) ? File.ReadAllText(todoFile).Trim().Split(new char[]{'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries) : null; IList<PatchFile> patchFiles = new List<PatchFile>(); if (todoCommits != null) { foreach (string todoCommit in todoCommits) { if (todoCommit.StartsWith("#")) continue; string[] parts = todoCommit.Split(' '); if (parts.Length >= 3) { string error = string.Empty; CommitData data = CommitData.GetCommitData(this, parts[1], ref error); PatchFile nextCommitPatch = new PatchFile(); nextCommitPatch.Author = string.IsNullOrEmpty(error) ? data.Author : error; nextCommitPatch.Subject = string.IsNullOrEmpty(error) ? data.Body : error; nextCommitPatch.Name = parts[0]; nextCommitPatch.Date = string.IsNullOrEmpty(error) ? data.CommitDate.LocalDateTime.ToString() : error; nextCommitPatch.IsNext = patchFiles.Count == 0; patchFiles.Add(nextCommitPatch); } } } return patchFiles; }
public static List<PatchFile> GetRebasePatchFiles() { List<PatchFile> patchFiles = new List<PatchFile>(); string nextFile = GetNextRebasePatch(); int next = 0; int.TryParse(nextFile, out next); string[] files = new string[0]; if (Directory.Exists(GetRebaseDir())) files = Directory.GetFiles(GetRebaseDir()); foreach (string fullFileName in files) { int n = 0; string file = fullFileName.Substring(fullFileName.LastIndexOf('\\') + 1); if (int.TryParse(file, out n)) { PatchFile patchFile = new PatchFile(); patchFile.Name = file; patchFile.FullName = fullFileName; patchFile.IsNext = n == next; patchFile.IsSkipped = n < next; if (File.Exists(GetRebaseDir() + file)) { foreach (string line in File.ReadAllLines(GetRebaseDir() + file)) { if (line.StartsWith("From: ")) if (line.IndexOf('<') > 0 && line.IndexOf('<') < line.Length) patchFile.Author = line.Substring(6, line.IndexOf('<') - 6).Trim(); else patchFile.Author = line.Substring(6).Trim(); if (line.StartsWith("Date: ")) if (line.IndexOf('+') > 0 && line.IndexOf('<') < line.Length) patchFile.Date = line.Substring(6, line.IndexOf('+') - 6).Trim(); else patchFile.Date = line.Substring(6).Trim(); if (line.StartsWith("Subject: ")) patchFile.Subject = line.Substring(9).Trim(); if (!string.IsNullOrEmpty(patchFile.Author) && !string.IsNullOrEmpty(patchFile.Date) && !string.IsNullOrEmpty(patchFile.Subject)) break; } } patchFiles.Add(patchFile); } } return patchFiles; }