private void Warnings_SelectionChanged(object sender, EventArgs e) { if (CurrentItem is null || _previewedItem == CurrentItem) { return; } _previewedItem = CurrentItem; var content = Module.ShowObject(_previewedItem.ObjectId); if (_previewedItem.ObjectType == LostObjectType.Commit) { ThreadHelper.JoinableTaskFactory.RunAsync(() => fileViewer.ViewFixedPatchAsync("commit.patch", content, null)) .FileAndForget(); } else { ThreadHelper.JoinableTaskFactory.RunAsync(async() => { var filename = GuessFileTypeWithContent(content); await fileViewer.ViewTextAsync(filename, content ?? string.Empty, null); }).FileAndForget(); } }
// TODO: add textbox for simple fulltext search/filtering (useful for large repos) private bool IsMatchToFilter(LostObject lostObject) { if (ShowOnlyCommits.Checked) { return(lostObject.ObjectType == LostObjectType.Commit); } return(true); }
private void ShuffleLostObjects(List <LostObject> _objList) { for (int i = 0; i < _objList.Count; i++) { LostObject temp = _objList[i]; int randomIndex = Random.Range(i, _objList.Count); _objList[i] = _objList[randomIndex]; _objList[randomIndex] = temp; } }
public static LostObject TryParse(GitModule module, string raw) { if (string.IsNullOrEmpty(raw)) { throw new ArgumentException("Raw source must be non-empty string", raw); } var patternMatch = RawDataRegex.Match(raw); // show failed assertion for unsupported cases (for developers) // if you get this message, // you can implement this format parsing // or post an issue to https://github.com/gitextensions/gitextensions/issues Debug.Assert(patternMatch.Success, "Lost object's extracted diagnostics format not implemented", raw); // skip unsupported raw data format (for end users) if (!patternMatch.Success) { return(null); } var matchedGroups = patternMatch.Groups; Debug.Assert(matchedGroups[4].Success, "matchedGroups[4].Success"); var hash = matchedGroups[4].Value; var result = new LostObject(GetObjectType(matchedGroups), matchedGroups[1].Value, hash); if (result.ObjectType == LostObjectType.Commit) { var commitLog = GetLostCommitLog(module, hash); var logPatternMatch = LogRegex.Match(commitLog); if (logPatternMatch.Success) { result.Author = module.ReEncodeStringFromLossless(logPatternMatch.Groups[1].Value); string encodingName = logPatternMatch.Groups[2].Value; result.Subject = module.ReEncodeCommitMessage(logPatternMatch.Groups[3].Value, encodingName); result.Date = DateTimeUtils.ParseUnixTime(logPatternMatch.Groups[4].Value); } } if (result.ObjectType == LostObjectType.Blob) { var blobPath = Path.Combine(module.WorkingDirGitDir, "objects", hash.Substring(0, 2), hash.Substring(2, hash.Length - 2)); result.Date = new FileInfo(blobPath).CreationTime; } return(result); }
public static LostObject TryParse(string raw) { if (string.IsNullOrEmpty(raw)) { throw new ArgumentException("Raw source must be non-empty string", raw); } var patternMatch = RawDataRegex.Match(raw); // show failed assertion for unsupported cases (for developers) // if you get this message, // you can implement this format parsing // or post an issue to https://github.com/spdr870/gitextensions/issues Debug.Assert(patternMatch.Success, "Lost object's extracted diagnostics format not implemented", raw); // skip unsupported raw data format (for end users) if (!patternMatch.Success) { return(null); } var matchedGroups = patternMatch.Groups; Debug.Assert(matchedGroups[4].Success); var hash = matchedGroups[4].Value; var result = new LostObject(GetObjectType(matchedGroups), matchedGroups[1].Value, hash); if (result.ObjectType == LostObjectType.Commit) { var commitLog = GetLostCommitLog(hash); var logPatternMatch = LogRegex.Match(commitLog); if (logPatternMatch.Success) { result.Author = GitCommandHelpers.ReEncodeStringFromLossless(logPatternMatch.Groups[1].Value); string encodingName = logPatternMatch.Groups[2].Value; result.Subject = GitCommandHelpers.ReEncodeCommitMessage(logPatternMatch.Groups[3].Value, encodingName); result.Date = UnixEpoch.AddSeconds(long.Parse(logPatternMatch.Groups[4].Value)); } } return(result); }
private void UpdateLostObjects() { Cursor.Current = Cursors.WaitCursor; var dialogResult = FormProcess.ReadDialog(this, "fsck-objects" + GetOptions()); if (FormProcess.IsOperationAborted(dialogResult)) { DialogResult = DialogResult.Abort; return; } lostObjects.Clear(); lostObjects.AddRange(dialogResult .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select <string, LostObject>((s) => LostObject.TryParse(Module, s)) .Where(parsedLostObject => parsedLostObject != null)); UpdateFilteredLostObjects(); Cursor.Current = Cursors.Default; }
public static LostObject TryParse(GitModule aModule, string raw) { if (string.IsNullOrEmpty(raw)) throw new ArgumentException("Raw source must be non-empty string", raw); var patternMatch = RawDataRegex.Match(raw); // show failed assertion for unsupported cases (for developers) // if you get this message, // you can implement this format parsing // or post an issue to https://github.com/gitextensions/gitextensions/issues Debug.Assert(patternMatch.Success, "Lost object's extracted diagnostics format not implemented", raw); // skip unsupported raw data format (for end users) if (!patternMatch.Success) return null; var matchedGroups = patternMatch.Groups; Debug.Assert(matchedGroups[4].Success); var hash = matchedGroups[4].Value; var result = new LostObject(GetObjectType(matchedGroups), matchedGroups[1].Value, hash); if (result.ObjectType == LostObjectType.Commit) { var commitLog = GetLostCommitLog(aModule, hash); var logPatternMatch = LogRegex.Match(commitLog); if (logPatternMatch.Success) { result.Author = aModule.ReEncodeStringFromLossless(logPatternMatch.Groups[1].Value); string encodingName = logPatternMatch.Groups[2].Value; result.Subject = aModule.ReEncodeCommitMessage(logPatternMatch.Groups[3].Value, encodingName); result.Date = DateTimeUtils.ParseUnixTime(logPatternMatch.Groups[4].Value); } } return result; }
private void UpdateLostObjects() { using (WaitCursorScope.Enter()) { string cmdOutput = FormProcess.ReadDialog(this, process: null, arguments: $"fsck-objects{GetOptions()}", Module.WorkingDir, input: null, useDialogSettings: true); if (FormProcess.IsOperationAborted(cmdOutput)) { DialogResult = DialogResult.Abort; return; } _lostObjects.Clear(); _lostObjects.AddRange( cmdOutput .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select((s) => LostObject.TryParse(Module, s)) .Where(parsedLostObject => parsedLostObject is not null) .OrderByDescending(l => l.Date)); UpdateFilteredLostObjects(); } }
private void UpdateLostObjects() { using (WaitCursorScope.Enter()) { var dialogResult = FormProcess.ReadDialog(this, "fsck-objects" + GetOptions()); if (FormProcess.IsOperationAborted(dialogResult)) { DialogResult = DialogResult.Abort; return; } _lostObjects.Clear(); _lostObjects.AddRange( dialogResult .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select((s) => LostObject.TryParse(Module, s)) .Where(parsedLostObject => parsedLostObject != null)); UpdateFilteredLostObjects(); } }
public static LostObject TryParse(GitModule module, string raw) { if (string.IsNullOrEmpty(raw)) { throw new ArgumentException("Raw source must be non-empty string", raw); } var patternMatch = RawDataRegex.Match(raw); // show failed assertion for unsupported cases (for developers) // if you get this message, // you can implement this format parsing // or post an issue to https://github.com/gitextensions/gitextensions/issues Debug.Assert(patternMatch.Success, "Lost object's extracted diagnostics format not implemented", raw); // skip unsupported raw data format (for end users) if (!patternMatch.Success) { return(null); } var matchedGroups = patternMatch.Groups; var rawType = matchedGroups[1].Value; var objectType = GetObjectType(matchedGroups[3]); var objectId = ObjectId.Parse(raw, matchedGroups[4]); var result = new LostObject(objectType, rawType, objectId); if (objectType == LostObjectType.Commit) { var commitLog = GetLostCommitLog(); var logPatternMatch = LogRegex.Match(commitLog); if (logPatternMatch.Success) { result.Author = module.ReEncodeStringFromLossless(logPatternMatch.Groups[1].Value); string encodingName = logPatternMatch.Groups[2].Value; result.Subject = module.ReEncodeCommitMessage(logPatternMatch.Groups[3].Value, encodingName); result.Date = DateTimeUtils.ParseUnixTime(logPatternMatch.Groups[4].Value); if (logPatternMatch.Groups.Count >= 5) { var parentId = logPatternMatch.Groups[5].Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); if (parentId != null) { result.Parent = ObjectId.Parse(parentId); } } } } else if (objectType == LostObjectType.Tag) { var tagData = GetLostTagData(); var tagPatternMatch = TagRegex.Match(tagData); if (tagPatternMatch.Success) { result.Parent = ObjectId.Parse(tagData, tagPatternMatch.Groups[1]); result.Author = module.ReEncodeStringFromLossless(tagPatternMatch.Groups[3].Value); result.TagName = tagPatternMatch.Groups[2].Value; result.Subject = result.TagName + ":" + tagPatternMatch.Groups[5].Value; result.Date = DateTimeUtils.ParseUnixTime(tagPatternMatch.Groups[4].Value); } } else if (objectType == LostObjectType.Blob) { var hash = objectId.ToString(); var blobPath = Path.Combine(module.WorkingDirGitDir, "objects", hash.Substring(0, 2), hash.Substring(2, ObjectId.Sha1CharCount - 2)); result.Date = new FileInfo(blobPath).CreationTime; } return(result); string GetLostCommitLog() => VerifyHashAndRunCommand(LogCommandArgumentsFormat); string GetLostTagData() => VerifyHashAndRunCommand(TagCommandArgumentsFormat); string VerifyHashAndRunCommand(ArgumentString commandFormat) { return(module.GitExecutable.GetOutput(string.Format(commandFormat, objectId), outputEncoding: GitModule.LosslessEncoding)); } LostObjectType GetObjectType(Group matchedGroup) { if (!matchedGroup.Success) { return(LostObjectType.Other); } switch (matchedGroup.Value) { case "commit": return(LostObjectType.Commit); case "blob": return(LostObjectType.Blob); case "tree": return(LostObjectType.Tree); case "tag": return(LostObjectType.Tag); default: return(LostObjectType.Other); } } }
// TODO: add textbox for simple fulltext search/filtering (useful for large repos) private bool IsMatchToFilter(LostObject lostObject) { if (ShowOnlyCommits.Checked) return lostObject.ObjectType == LostObjectType.Commit; return true; }
// TODO: add textbox for simple fulltext search/filtering (useful for large repos) private bool IsMatchToFilter(LostObject lostObject) { return((ShowCommitsAndTags.Checked && (lostObject.ObjectType == LostObjectType.Commit || lostObject.ObjectType == LostObjectType.Tag)) || (ShowOtherObjects.Checked && (lostObject.ObjectType != LostObjectType.Commit && lostObject.ObjectType != LostObjectType.Tag))); }
public static LostObject TryParse(string raw) { if (string.IsNullOrEmpty(raw)) throw new ArgumentException("Raw source must be non-empty string", raw); var patterMatch = RawDataRegex.Match(raw); // show failed assertion for unsupported cases (for developers) // if you get this message, // you can implement this format parsing // or post an issue to https://github.com/spdr870/gitextensions/issues Debug.Assert(patterMatch.Success, "Lost object's extracted diagnostics format not implemented", raw); // skip unsupported raw data format (for end users) if (!patterMatch.Success) return null; Debug.Assert(patterMatch.Groups[4].Success); var hash = patterMatch.Groups[4].Value; var result = new LostObject(hash, raw); var objectInfo = GetLostObjectLog(hash); var logPatternMatch = LogRegex.Match(objectInfo); if (logPatternMatch.Success) { result.Author = logPatternMatch.Groups[1].Value; result.Subject = logPatternMatch.Groups[2].Value; result.Date = UnixEpoch.AddSeconds(long.Parse(logPatternMatch.Groups[3].Value)); } return result; }