11'use strict' ;
2- import { commands , Range , TextDocumentShowOptions , TextEditor , Uri , window } from 'vscode' ;
2+ import { commands , TextDocumentShowOptions , TextEditor , Uri , window } from 'vscode' ;
33import { ActiveEditorCommand , Commands , getCommandUri } from './common' ;
4- import { BuiltInCommands , GlyphChars } from '../constants' ;
5- import { DiffWithPreviousCommandArgs } from './diffWithPrevious' ;
6- import { DiffWithWorkingCommandArgs } from './diffWithWorking' ;
4+ import { DiffWithCommandArgs } from './diffWith' ;
75import { GitCommit , GitService , GitUri } from '../gitService' ;
86import { Logger } from '../logger' ;
97import { Messages } from '../messages' ;
10- import * as path from 'path' ;
118
129export interface DiffLineWithPreviousCommandArgs {
1310 commit ?: GitCommit ;
11+
1412 line ?: number ;
1513 showOptions ?: TextDocumentShowOptions ;
1614}
@@ -43,56 +41,26 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
4341 if ( blame === undefined ) return Messages . showFileNotUnderSourceControlWarningMessage ( 'Unable to open compare' ) ;
4442
4543 args . commit = blame . commit ;
46-
47- // If we don't have a sha or the current commit matches the blame, show the previous
48- if ( gitUri . sha === undefined || gitUri . sha === args . commit . sha ) {
49- return commands . executeCommand ( Commands . DiffWithPrevious , new GitUri ( uri , args . commit ) , {
50- line : args . line ,
51- showOptions : args . showOptions
52- } as DiffWithPreviousCommandArgs ) ;
53- }
54-
55- // If the line is uncommitted, find the previous commit and treat it as a DiffWithWorking
56- if ( args . commit . isUncommitted ) {
57- uri = args . commit . uri ;
58- args . commit = new GitCommit ( args . commit . type , args . commit . repoPath , args . commit . previousSha ! , args . commit . previousFileName ! , args . commit . author , args . commit . date , args . commit . message ) ;
59- args . line = ( blame . line . line + 1 ) + gitUri . offset ;
60-
61- return commands . executeCommand ( Commands . DiffWithWorking , uri , {
62- commit : args . commit ,
63- line : args . line ,
64- showOptions : args . showOptions
65- } as DiffWithWorkingCommandArgs ) ;
66- }
6744 }
6845 catch ( ex ) {
69- Logger . error ( ex , 'DiffWithPreviousLineCommand ' , `getBlameForLine(${ blameline } )` ) ;
46+ Logger . error ( ex , 'DiffLineWithPreviousCommand ' , `getBlameForLine(${ blameline } )` ) ;
7047 return window . showErrorMessage ( `Unable to open compare. See output channel for more details` ) ;
7148 }
7249 }
7350
74- try {
75- const [ rhs , lhs ] = await Promise . all ( [
76- this . git . getVersionedFile ( gitUri . repoPath , gitUri . fsPath , gitUri . sha ! ) ,
77- this . git . getVersionedFile ( args . commit . repoPath , args . commit . uri . fsPath , args . commit . sha )
78- ] ) ;
79-
80- if ( args . line !== undefined && args . line !== 0 ) {
81- if ( args . showOptions === undefined ) {
82- args . showOptions = { } ;
83- }
84- args . showOptions . selection = new Range ( args . line , 0 , args . line , 0 ) ;
85- }
86-
87- await commands . executeCommand ( BuiltInCommands . Diff ,
88- Uri . file ( lhs ) ,
89- Uri . file ( rhs ) ,
90- `${ path . basename ( args . commit . uri . fsPath ) } (${ args . commit . shortSha } ) ${ GlyphChars . ArrowLeftRight } ${ path . basename ( gitUri . fsPath ) } (${ gitUri . shortSha } )` ,
91- args . showOptions ) ;
92- }
93- catch ( ex ) {
94- Logger . error ( ex , 'DiffWithPreviousLineCommand' , 'getVersionedFile' ) ;
95- return window . showErrorMessage ( `Unable to open compare. See output channel for more details` ) ;
96- }
51+ const diffArgs : DiffWithCommandArgs = {
52+ repoPath : args . commit . repoPath ,
53+ lhs : {
54+ sha : args . commit . previousSha !== undefined ? args . commit . previousSha : GitService . fakeSha ,
55+ uri : args . commit . previousUri
56+ } ,
57+ rhs : {
58+ sha : args . commit . sha ,
59+ uri : args . commit . uri
60+ } ,
61+ line : args . line ,
62+ showOptions : args . showOptions
63+ } ;
64+ return commands . executeCommand ( Commands . DiffWith , diffArgs ) ;
9765 }
9866}
0 commit comments