1
1
import { workspace } from "vscode" ;
2
2
import { Svn , CpOptions } from "./svn" ;
3
3
import { IFileStatus , parseStatusXml } from "./statusParser" ;
4
+ import { parseInfoXml , ISvnInfo } from "./infoParser" ;
4
5
5
6
export class Repository {
7
+ private _info ?: ISvnInfo ;
8
+
6
9
constructor (
7
10
private svn : Svn ,
8
11
public root : string ,
@@ -15,6 +18,22 @@ export class Repository {
15
18
return await parseStatusXml ( result . stdout ) ;
16
19
}
17
20
21
+ async getInfo ( ) : Promise < ISvnInfo > {
22
+ if ( this . _info ) {
23
+ return this . _info ;
24
+ }
25
+ const result = await this . svn . info ( this . workspaceRoot ) ;
26
+
27
+ this . _info = await parseInfoXml ( result . stdout ) ;
28
+
29
+ //Cache for 30 seconds
30
+ setTimeout ( ( ) => {
31
+ this . _info = undefined ;
32
+ } , 30000 ) ;
33
+
34
+ return this . _info ;
35
+ }
36
+
18
37
async show (
19
38
path : string ,
20
39
revision ?: string ,
@@ -46,11 +65,7 @@ export class Repository {
46
65
}
47
66
48
67
async getCurrentBranch ( ) : Promise < string > {
49
- const info = await this . svn . info ( this . workspaceRoot ) ;
50
-
51
- if ( info . exitCode !== 0 ) {
52
- throw new Error ( info . stderr ) ;
53
- }
68
+ const info = await this . getInfo ( ) ;
54
69
55
70
const config = workspace . getConfiguration ( "svn" ) ;
56
71
const trunkLayout = config . get < string > ( "layout.trunk" ) ;
@@ -60,11 +75,9 @@ export class Repository {
60
75
const trees = [ trunkLayout , branchesLayout , tagsLayout ] . filter (
61
76
x => x != null
62
77
) ;
63
- const regex = new RegExp (
64
- "<url>(.*?)/(" + trees . join ( "|" ) + ")(/([^/]+))?.*?</url>"
65
- ) ;
78
+ const regex = new RegExp ( "(.*?)/(" + trees . join ( "|" ) + ")(/([^/]+))?.*?" ) ;
66
79
67
- const match = info . stdout . match ( regex ) ;
80
+ const match = info . url . match ( regex ) ;
68
81
69
82
if ( match ) {
70
83
if ( match [ 4 ] && match [ 2 ] !== trunkLayout ) {
@@ -87,16 +100,12 @@ export class Repository {
87
100
const trees = [ trunkLayout , branchesLayout , tagsLayout ] . filter (
88
101
x => x != null
89
102
) ;
90
- const regex = new RegExp ( "<url> (.*?)/(" + trees . join ( "|" ) + ").*?</url> " ) ;
103
+ const regex = new RegExp ( "(.*?)/(" + trees . join ( "|" ) + ").*?" ) ;
91
104
92
- const info = await this . svn . info ( this . workspaceRoot ) ;
93
-
94
- if ( info . exitCode !== 0 ) {
95
- throw new Error ( info . stderr ) ;
96
- }
105
+ const info = await this . getInfo ( ) ;
97
106
98
- let repoUrl = info . stdout . match ( / < r o o t > ( . * ? ) < \/ r o o t > / ) [ 1 ] ;
99
- const match = info . stdout . match ( regex ) ;
107
+ let repoUrl = info . repository . root ;
108
+ const match = info . url . match ( regex ) ;
100
109
101
110
if ( match && match [ 1 ] ) {
102
111
repoUrl = match [ 1 ] ;
@@ -188,14 +197,10 @@ export class Repository {
188
197
189
198
const repoUrl = await this . getRepoUrl ( ) ;
190
199
const newBranch = repoUrl + "/" + branchesLayout + "/" + name ;
191
- const resultBranch = await this . svn . info ( this . workspaceRoot ) ;
192
- const currentBranch = resultBranch . stdout . match ( / < u r l > ( . * ? ) < \/ u r l > / ) [ 1 ] ;
200
+ const info = await this . getInfo ( ) ;
201
+ const currentBranch = info . url ;
193
202
const result = await this . svn . copy ( currentBranch , newBranch , name ) ;
194
203
195
- if ( result . exitCode !== 0 ) {
196
- throw new Error ( result . stderr ) ;
197
- }
198
-
199
204
const switchBranch = await this . svn . switchBranch (
200
205
this . workspaceRoot ,
201
206
newBranch
0 commit comments