Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jgit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Faculty of Technology
Software Engineering
tools
cms
jgit
Commits
baaa78f1
Commit
baaa78f1
authored
15 years ago
by
Robin Rosenberg
Committed by
Code Review
15 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Add unsetSection to Config to remove an entire block"
parents
94599930
48e9a010
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
+41
-0
41 additions, 0 deletions
...t.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+42
-0
42 additions, 0 deletions
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
with
83 additions
and
0 deletions
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
+
41
−
0
View file @
baaa78f1
...
...
@@ -271,6 +271,47 @@ public void testEmptyString() throws ConfigInvalidException {
assertEquals
(
"[my]\n\tempty =\n"
,
c
.
toText
());
}
public
void
testUnsetBranchSection
()
throws
ConfigInvalidException
{
Config
c
=
parse
(
""
//
+
"[branch \"keep\"]\n"
+
" merge = master.branch.to.keep.in.the.file\n"
+
"\n"
+
"[branch \"remove\"]\n"
+
" merge = this.will.get.deleted\n"
+
" remote = origin-for-some-long-gone-place\n"
+
"\n"
+
"[core-section-not-to-remove-in-test]\n"
+
" packedGitLimit = 14\n"
);
c
.
unsetSection
(
"branch"
,
"does.not.exist"
);
c
.
unsetSection
(
"branch"
,
"remove"
);
assertEquals
(
""
//
+
"[branch \"keep\"]\n"
+
" merge = master.branch.to.keep.in.the.file\n"
+
"\n"
+
"[core-section-not-to-remove-in-test]\n"
+
" packedGitLimit = 14\n"
,
c
.
toText
());
}
public
void
testUnsetSingleSection
()
throws
ConfigInvalidException
{
Config
c
=
parse
(
""
//
+
"[branch \"keep\"]\n"
+
" merge = master.branch.to.keep.in.the.file\n"
+
"\n"
+
"[single]\n"
+
" merge = this.will.get.deleted\n"
+
" remote = origin-for-some-long-gone-place\n"
+
"\n"
+
"[core-section-not-to-remove-in-test]\n"
+
" packedGitLimit = 14\n"
);
c
.
unsetSection
(
"single"
,
null
);
assertEquals
(
""
//
+
"[branch \"keep\"]\n"
+
" merge = master.branch.to.keep.in.the.file\n"
+
"\n"
+
"[core-section-not-to-remove-in-test]\n"
+
" packedGitLimit = 14\n"
,
c
.
toText
());
}
private
void
assertReadLong
(
long
exp
)
throws
ConfigInvalidException
{
assertReadLong
(
exp
,
String
.
valueOf
(
exp
));
}
...
...
This diff is collapsed.
Click to expand it.
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+
42
−
0
View file @
baaa78f1
...
...
@@ -576,6 +576,43 @@ public void unset(final String section, final String subsection,
.<
String
>
emptyList
());
}
/**
* Remove all configuration values under a single section.
*
* @param section
* section name, e.g "branch"
* @param subsection
* optional subsection value, e.g. a branch name
*/
public
void
unsetSection
(
String
section
,
String
subsection
)
{
State
src
,
res
;
do
{
src
=
state
.
get
();
res
=
unsetSection
(
src
,
section
,
subsection
);
}
while
(!
state
.
compareAndSet
(
src
,
res
));
}
private
State
unsetSection
(
final
State
srcState
,
final
String
section
,
final
String
subsection
)
{
final
int
max
=
srcState
.
entryList
.
size
();
final
ArrayList
<
Entry
>
r
=
new
ArrayList
<
Entry
>(
max
);
boolean
lastWasMatch
=
false
;
for
(
Entry
e
:
srcState
.
entryList
)
{
if
(
e
.
match
(
section
,
subsection
))
{
// Skip this record, it's for the section we are removing.
lastWasMatch
=
true
;
continue
;
}
if
(
lastWasMatch
&&
e
.
section
==
null
&&
e
.
subsection
==
null
)
continue
;
// skip this padding line in the section.
r
.
add
(
e
);
}
return
newState
(
r
);
}
/**
* Set a configuration value.
*
...
...
@@ -1104,6 +1141,11 @@ && eqSameCase(subsection, aSubsection)
&&
eqIgnoreCase
(
name
,
aKey
);
}
boolean
match
(
final
String
aSection
,
final
String
aSubsection
)
{
return
eqIgnoreCase
(
section
,
aSection
)
&&
eqSameCase
(
subsection
,
aSubsection
);
}
private
static
boolean
eqIgnoreCase
(
final
String
a
,
final
String
b
)
{
if
(
a
==
null
&&
b
==
null
)
return
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment