Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
0db21e89
Commit
0db21e89
authored
6 years ago
by
Aleksey Pivovarov
Browse files
Options
Download
Email Patches
Plain Diff
vcs: remove code duplication in NewMappings
parent
7db1ded3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java
+36
-42
...ntellij/openapi/vcs/impl/projectlevelman/NewMappings.java
with
36 additions
and
42 deletions
+36
-42
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/NewMappings.java
+
36
-
42
View file @
0db21e89
...
...
@@ -7,7 +7,6 @@ import com.intellij.openapi.progress.util.BackgroundTaskUtil;
import
com.intellij.openapi.project.DumbAwareRunnable
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.ui.MessageType
;
import
com.intellij.openapi.util.EmptyRunnable
;
import
com.intellij.openapi.util.Pair
;
import
com.intellij.openapi.util.io.FileUtil
;
import
com.intellij.openapi.util.text.StringUtil
;
...
...
@@ -102,11 +101,15 @@ public class NewMappings {
}
public
void
activateActiveVcses
()
{
MyVcsActivator
activator
;
synchronized
(
myLock
)
{
if
(
myActivated
)
return
;
myActivated
=
true
;
activator
=
updateActiveVcsesFromMap
();
}
keepActiveVcs
(
EmptyRunnable
.
getInstance
());
activator
.
activate
();
mappingsChanged
();
}
...
...
@@ -121,38 +124,38 @@ public class NewMappings {
}
}
keepActiveVc
s
(()
->
{
updateVcsMapping
s
(()
->
{
// sorted -> map. sorted mappings are NOT changed;
boolean
switched
=
trySwitchVcs
(
path
,
activeVcsName
);
if
(!
switched
)
{
myVcsToPaths
.
putValue
(
newMapping
.
getVcs
(),
newMapping
);
sortedMappingsByMap
();
}
});
mappingsChanged
();
}
private
void
keepActiveVc
s
(
@NotNull
Runnable
runnable
)
{
final
MyVcsActivator
activator
;
private
void
updateVcsMapping
s
(
@NotNull
Runnable
runnable
)
{
MyVcsActivator
activator
=
null
;
synchronized
(
myLock
)
{
if
(!
myActivated
)
{
runnable
.
run
();
return
;
}
AbstractVcs
[]
oldVcses
=
myActiveVcses
.
clone
();
runnable
.
run
();
restoreActiveVcses
();
AbstractVcs
[]
newVcses
=
myActiveVcses
.
clone
();
updateSortedMappingsFromMap
();
activator
=
new
MyVcsActivator
(
oldVcses
,
newVcses
);
if
(
myActivated
)
{
activator
=
updateActiveVcsesFromMap
();
}
}
activator
.
activate
();
if
(
activator
!=
null
)
{
activator
.
activate
();
}
mappingsChanged
();
}
private
void
restoreActiveVcses
()
{
@NotNull
private
MyVcsActivator
updateActiveVcsesFromMap
()
{
synchronized
(
myLock
)
{
AbstractVcs
[]
oldVcses
=
myActiveVcses
;
final
Set
<
String
>
set
=
myVcsToPaths
.
keySet
();
final
List
<
AbstractVcs
>
list
=
new
ArrayList
<>(
set
.
size
());
for
(
String
s
:
set
)
{
...
...
@@ -163,6 +166,8 @@ public class NewMappings {
}
}
myActiveVcses
=
list
.
toArray
(
new
AbstractVcs
[
0
]);
return
new
MyVcsActivator
(
oldVcses
,
myActiveVcses
);
}
}
...
...
@@ -193,15 +198,12 @@ public class NewMappings {
itemsCopy
=
items
;
}
keepActiveVc
s
(()
->
{
updateVcsMapping
s
(()
->
{
myVcsToPaths
.
clear
();
for
(
VcsDirectoryMapping
mapping
:
itemsCopy
)
{
myVcsToPaths
.
putValue
(
mapping
.
getVcs
(),
mapping
);
}
sortedMappingsByMap
();
});
mappingsChanged
();
}
@Nullable
...
...
@@ -286,14 +288,13 @@ public class NewMappings {
public
void
disposeMe
()
{
LOG
.
debug
(
"dispose me"
);
// if vcses were not mapped, there's nothing to clear
if
((
myActiveVcses
==
null
)
||
(
myActiveVcses
.
length
==
0
))
return
;
keepActiveVcs
(()
->
{
MyVcsActivator
activator
;
synchronized
(
myLock
)
{
myVcsToPaths
.
clear
();
myActiveVcses
=
new
AbstractVcs
[
0
];
mySortedMappings
=
VcsDirectoryMapping
.
EMPTY_ARRAY
;
});
updateSortedMappingsFromMap
();
activator
=
updateActiveVcsesFromMap
();
}
activator
.
activate
();
myFileWatchRequestsManager
.
ping
();
}
...
...
@@ -335,13 +336,9 @@ public class NewMappings {
public
void
removeDirectoryMapping
(
final
VcsDirectoryMapping
mapping
)
{
LOG
.
debug
(
"remove mapping: "
+
mapping
.
getDirectory
());
keepActiveVcs
(()
->
{
if
(
removeVcsFromMap
(
mapping
,
mapping
.
getVcs
()))
{
sortedMappingsByMap
();
}
updateVcsMappings
(()
->
{
removeVcsFromMap
(
mapping
,
mapping
.
getVcs
());
});
mappingsChanged
();
}
// todo area for optimization
...
...
@@ -386,7 +383,7 @@ public class NewMappings {
}
}
s
ortedMappings
By
Map
();
updateS
ortedMappings
From
Map
();
}
private
boolean
trySwitchVcs
(
final
String
path
,
final
String
activeVcsName
)
{
...
...
@@ -403,7 +400,7 @@ public class NewMappings {
return
false
;
}
private
void
s
ortedMappings
By
Map
()
{
private
void
updateS
ortedMappings
From
Map
()
{
mySortedMappings
=
ArrayUtil
.
toObjectArray
(
myVcsToPaths
.
values
(),
VcsDirectoryMapping
.
class
);
Arrays
.
sort
(
mySortedMappings
,
MAPPINGS_COMPARATOR
);
}
...
...
@@ -465,13 +462,10 @@ public class NewMappings {
public
void
beingUnregistered
(
final
String
name
)
{
synchronized
(
myLock
)
{
keepActiveVc
s
(()
->
{
updateVcsMapping
s
(()
->
{
myVcsToPaths
.
remove
(
name
);
sortedMappingsByMap
();
});
}
mappingsChanged
();
}
@NotNull
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help