import { AddedCvsResource } from "../../bll/entities/cvsresources/addedcvsresource" ; import { ReplacedCvsResource } from "../../bll/entities/cvsresources/replacedcvsresource" ; import { ModifiedCvsResource } from "../../bll/entities/cvsresources/modifiedcvsresource" ; import { CvsResource } from "../../bll/entities/cvsresources/cvsresource" ; import * as path from "path" ; import { GitCommandArgumentsParser } from "./GitCommandArgumentsParser" ; import { DeletedCvsResource } from "../../bll/entities/cvsresources/deletedcvsresource" ; import { Logger } from "../../bll/utils/logger" ; import { Utils } from "../../bll/utils/utils" ; import { Settings } from "../../bll/entities/settings" ; import { GetFirstMonthRev } from "./GetFirstMonthRev" ; import { GetLastCompatibleMergeBaseRev } from "./GetLastCompatibleMergeBaseRev" ; export class GitStatusRowsParser { private constructor ( private readonly settings , private readonly firstMonthRevHash , private readonly lastRevHash ) { } public static async prepareInstance ( settings , getFirstMonthRevCommand , getLastCompatibleMergeBaseRevCommand ) { let firstMonthRevHash = await getFirstMonthRevCommand . execute ( ) ; firstMonthRevHash = firstMonthRevHash ? firstMonthRevHash + "-" : "" ; const lastRevHash = await getLastCompatibleMergeBaseRevCommand . execute ( ) ; return new GitStatusRowsParser ( settings , firstMonthRevHash , lastRevHash ) ; } public tryParseRows ( workspaceRootPath , statusRows ) { const result = [ ] ; statusRows . forEach ( ( statusRow ) => { try { const resource = this . parseRow ( workspaceRootPath , statusRow ) ; result . push ( resource ) ; } catch ( err ) { Logger . logDebug ( "GitStatusRowsParser#tryParseRows: row was not parsed with error: " + Utils . formatErrorMessage ( err ) ) ; } } ) ; return result ; } private parseRow ( workspaceRootPath , statusRow ) { let isFromIndex = this . settings . shouldCollectGitChangesFromIndex ( ) ; const { relativePath , indexStatus , workingTreeStatus , prevRelativePath } = GitCommandArgumentsParser . parseStatusRow ( statusRow ) ; isFromIndex = isFromIndex || ( ! isFromIndex && workingTreeStatus === undefined ) ; switch ( isFromIndex ? indexStatus : workingTreeStatus ) { case "M" : { const fileAbsPath = path . join ( workspaceRootPath , relativePath ) ; return new ModifiedCvsResource ( fileAbsPath , relativePath , this . getFileServerPath ( relativePath ) ) ; } case "A" : { const fileAbsPath = path . join ( workspaceRootPath , relativePath ) ; return new AddedCvsResource ( fileAbsPath , relativePath , this . getFileServerPath ( relativePath ) ) ; } case "D" : { const fileAbsPath = path . join ( workspaceRootPath , relativePath ) ; return new DeletedCvsResource ( fileAbsPath , relativePath , this . getFileServerPath ( relativePath ) ) ; } case "R" : { const fileAbsPath = path . join ( workspaceRootPath , relativePath ) ; const prevFileAbsPath = path . join ( workspaceRootPath , prevRelativePath ) ; return new ReplacedCvsResource ( fileAbsPath , relativePath , this . getFileServerPath ( relativePath ) , prevFileAbsPath , this . getFileServerPath ( prevRelativePath ) ) ; } case "C" : { const fileAbsPath = path . join ( workspaceRootPath , relativePath ) ; return new AddedCvsResource ( fileAbsPath , relativePath , this . getFileServerPath ( relativePath ) ) ; } default : { throw new Error ( `Resource status for status row ${ statusRow } is ` + `'${ indexStatus }' and not recognised` ) ; } } } private getFileServerPath ( relativePath ) { return `jetbrains.git://${ this . firstMonthRevHash }${ this . lastRevHash }||${ relativePath }` ; } }