/// <summary> /// Throws ArgumentException, ContextMakingException. /// </summary> public DiffContext GetContext(DiffPosition position, ContextDepth depth) { if (!Context.Helpers.IsValidPosition(position)) { throw new ArgumentException( String.Format("Bad \"position\": {0}", position.ToString())); } if (!Context.Helpers.IsValidContextDepth(depth)) { throw new ArgumentException( String.Format("Bad \"depth\": {0}", depth.ToString())); } GitDiffAnalyzer analyzer = new GitDiffAnalyzer(_git, position.Refs.LeftSHA, position.Refs.RightSHA, position.LeftPath, position.RightPath); // If RightLine is valid, then it points to either added/modified or unchanged line, handle them the same way bool isRightSideContext = position.RightLine != null; int linenumber = isRightSideContext ? int.Parse(position.RightLine) : int.Parse(position.LeftLine); string filename = isRightSideContext ? position.RightPath : position.LeftPath; string sha = isRightSideContext ? position.Refs.RightSHA : position.Refs.LeftSHA; GitShowRevisionArguments arguments = new GitShowRevisionArguments(filename, sha); IEnumerable <string> contents; try { contents = _git?.ShowRevision(arguments); } catch (GitNotAvailableDataException ex) { throw new ContextMakingException("Cannot obtain git revision", ex); } if (contents == null) { throw new ContextMakingException("Cannot obtain git revision", null); } if (linenumber > contents.Count()) { throw new ArgumentException( String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}", linenumber.ToString(), position.ToString())); } return(createDiffContext(linenumber, isRightSideContext, contents, analyzer, depth)); }
/// <summary> /// Throws ArgumentException, ContextMakingException. /// </summary> public DiffContext GetContext(DiffPosition position, ContextDepth depth, UnchangedLinePolicy unchangedLinePolicy) { if (!Context.Helpers.IsValidPosition(position)) { throw new ArgumentException( String.Format("Bad \"position\": {0}", position.ToString())); } if (!Context.Helpers.IsValidContextDepth(depth)) { throw new ArgumentException( String.Format("Bad \"depth\": {0}", depth.ToString())); } bool isRightSideContext = Helpers.IsRightSidePosition(position, unchangedLinePolicy); int linenumber = isRightSideContext ? Helpers.GetRightLineNumber(position) : Helpers.GetLeftLineNumber(position); string filename = isRightSideContext ? position.RightPath : position.LeftPath; string sha = isRightSideContext ? position.Refs.RightSHA : position.Refs.LeftSHA; GitShowRevisionArguments arguments = new GitShowRevisionArguments(filename, sha); IEnumerable <string> contents; try { contents = _git?.ShowRevision(arguments); } catch (GitNotAvailableDataException ex) { throw new ContextMakingException("Cannot obtain git revision", ex); } if (contents == null) { throw new ContextMakingException("Cannot obtain git revision", null); } if (linenumber > contents.Count()) { throw new ArgumentException( String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}", linenumber.ToString(), position.ToString())); } return(createDiffContext(linenumber, contents, isRightSideContext, depth)); }