@@ -2,6 +2,7 @@ import * as xml2js from "xml2js";
22
33export interface IFileStatus {
44 status : string ;
5+ props : string ;
56 path : string ;
67 changelist ?: string ;
78 rename ?: string ;
@@ -14,27 +15,20 @@ export interface IFileStatus {
1415}
1516
1617export interface IEntry {
17- $ : {
18- path : string ;
19- } ;
20- "wc-status" : {
21- $ : {
22- item : string ;
23- revision : string ;
24- props : string ;
25- "moved-to" ?: string ;
26- "moved-from" ?: string ;
27- } ;
18+ path : string ;
19+ wcStatus : {
20+ item : string ;
21+ revision : string ;
22+ props : string ;
23+ movedTo ?: string ;
24+ movedFrom ?: string ;
25+ wcLocked ?: string ;
2826 commit : {
29- $ : {
30- revision : string ;
31- } ;
27+ revision : string ;
3228 author : string ;
3329 date : string ;
3430 } ;
3531 } ;
36- path : string ;
37- rename ?: string ;
3832}
3933
4034function processEntry (
@@ -54,21 +48,22 @@ function processEntry(
5448
5549 let r : IFileStatus = {
5650 changelist : changelist ,
57- path : entry [ "$" ] . path ,
58- status : entry [ "wc-status" ] . $ . item
51+ path : entry . path ,
52+ status : entry . wcStatus . item ,
53+ props : entry . wcStatus . props
5954 } ;
6055
61- if ( entry [ "wc-status" ] . $ [ "moved-to" ] && r . status === "deleted" ) {
56+ if ( entry . wcStatus . movedTo && r . status === "deleted" ) {
6257 return [ ] ;
6358 }
64- if ( entry [ "wc-status" ] . $ [ "moved-from" ] && r . status === "added" ) {
65- r . rename = entry [ "wc-status" ] . $ [ "moved-from" ] ;
59+ if ( entry . wcStatus . movedFrom && r . status === "added" ) {
60+ r . rename = entry . wcStatus . movedFrom ;
6661 }
67- if ( entry [ "wc-status" ] . commit ) {
62+ if ( entry . wcStatus . commit ) {
6863 r . commit = {
69- revision : entry [ "wc-status" ] . commit . $ . revision ,
70- author : entry [ "wc-status" ] . commit . author ,
71- date : entry [ "wc-status" ] . commit . date
64+ revision : entry . wcStatus . commit . revision ,
65+ author : entry . wcStatus . commit . author ,
66+ date : entry . wcStatus . commit . date
7267 } ;
7368 }
7469
@@ -87,20 +82,31 @@ function xmlToStatus(xml: any) {
8782 }
8883
8984 xml . changelist . forEach ( ( change : any ) => {
90- statusList . push ( ...processEntry ( change . entry , change . $ . name ) ) ;
85+ statusList . push ( ...processEntry ( change . entry , change . name ) ) ;
9186 } ) ;
9287 }
9388
9489 return statusList ;
9590}
9691
92+ function camelcase ( name : string ) {
93+ return name
94+ . replace ( / (?: ^ \w | [ A - Z ] | \b \w ) / g, function ( letter , index ) {
95+ return index == 0 ? letter . toLowerCase ( ) : letter . toUpperCase ( ) ;
96+ } )
97+ . replace ( / [ \s \- ] + / g, "" ) ;
98+ }
99+
97100export async function parseStatusXml ( content : string ) : Promise < IFileStatus [ ] > {
98101 return new Promise < IFileStatus [ ] > ( ( resolve , reject ) => {
99102 xml2js . parseString (
100103 content ,
101104 {
105+ mergeAttrs : true ,
102106 explicitRoot : false ,
103- explicitArray : false
107+ explicitArray : false ,
108+ attrNameProcessors : [ camelcase ] ,
109+ tagNameProcessors : [ camelcase ]
104110 } ,
105111 ( err , result ) => {
106112 if ( err ) {
0 commit comments