Skip to content

Commit 803f8a8

Browse files
authored
Merge pull request #124 from edgardmessias/improved_status_parser
Improved statusParser
2 parents cba68b2 + 9a50a8c commit 803f8a8

File tree

4 files changed

+67
-35
lines changed

4 files changed

+67
-35
lines changed

src/repository.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as path from "path";
2020
import * as micromatch from "micromatch";
2121
import { setInterval, clearInterval } from "timers";
2222
import { toSvnUri } from "./uri";
23-
import { Status } from "./svn";
23+
import { Status, PropStatus } from "./svn";
2424

2525
export class Repository {
2626
public watcher: FileSystemWatcher;
@@ -188,10 +188,15 @@ export class Repository {
188188
? Uri.file(path.join(this.workspaceRoot, status.rename))
189189
: undefined;
190190

191-
if (status.status === Status.UNVERSIONED) {
192-
unversioned.push(new Resource(uri, status.status, renameUri));
191+
const resouce = new Resource(uri, status.status, renameUri, status.props);
192+
193+
if (status.status === Status.NORMAL && status.props === PropStatus.NONE) {
194+
// On commit, `svn status` return all locked files with status="normal" and props="none"
195+
return;
196+
} else if (status.status === Status.UNVERSIONED) {
197+
unversioned.push(resouce);
193198
} else if (status.status === Status.EXTERNAL) {
194-
external.push(new Resource(uri, status.status, renameUri));
199+
external.push(resouce);
195200
} else {
196201
if (status.status === Status.UNVERSIONED) {
197202
const matches = status.path.match(
@@ -209,13 +214,13 @@ export class Repository {
209214
}
210215

211216
if (!status.changelist) {
212-
changes.push(new Resource(uri, status.status, renameUri));
217+
changes.push(resouce);
213218
} else {
214219
let changelist = changelists.get(status.changelist);
215220
if (!changelist) {
216221
changelist = [];
217222
}
218-
changelist.push(new Resource(uri, status.status, renameUri));
223+
changelist.push(resouce);
219224
changelists.set(status.changelist, changelist);
220225
}
221226
}

src/resource.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Command
77
} from "vscode";
88
import * as path from "path";
9-
import { Status } from "./svn";
9+
import { Status, PropStatus } from "./svn";
1010
import { memoize } from "./decorators";
1111

1212
const iconsRootPath = path.join(__dirname, "..", "icons");
@@ -44,7 +44,8 @@ export class Resource implements SourceControlResourceState {
4444
constructor(
4545
private _resourceUri: Uri,
4646
private _type: String,
47-
private _renameResourceUri?: Uri
47+
private _renameResourceUri?: Uri,
48+
private _props?: String
4849
) {}
4950

5051
@memoize
@@ -58,6 +59,9 @@ export class Resource implements SourceControlResourceState {
5859
get renameResourceUri(): Uri | undefined {
5960
return this._renameResourceUri;
6061
}
62+
get props(): String | undefined {
63+
return this._props;
64+
}
6165

6266
get decorations(): SourceControlResourceDecorations {
6367
const light = { iconPath: this.getIconPath("light") };
@@ -97,6 +101,16 @@ export class Resource implements SourceControlResourceState {
97101
return "Renamed from " + this.renameResourceUri.fsPath;
98102
}
99103

104+
if (
105+
this.type === Status.NORMAL &&
106+
this.props &&
107+
this.props !== PropStatus.NONE
108+
) {
109+
return (
110+
"Property " + this.props.charAt(0).toUpperCase() + this.props.slice(1)
111+
);
112+
}
113+
100114
return this.type.charAt(0).toUpperCase() + this.type.slice(1);
101115
}
102116

src/statusParser.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as xml2js from "xml2js";
22

33
export 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

1617
export 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

4034
function 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+
97100
export 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) {

src/svn.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export enum Status {
2525
UNVERSIONED = "unversioned"
2626
}
2727

28+
export enum PropStatus {
29+
CONFLICTED = "conflicted",
30+
MODIFIED = "modified",
31+
NONE = "none",
32+
NORMAL = "normal"
33+
}
34+
2835
export interface CpOptions {
2936
cwd?: string;
3037
encoding?: string;

0 commit comments

Comments
 (0)