diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2010-01-28 23:49:38 -0500 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2010-01-28 23:49:38 -0500 |
commit | baaa78f1f05d197ba2efefb713f194cd3f09725d (patch) | |
tree | d51fa47a7b9c66cb9839ee5108d82b4c4aa124f9 /org.eclipse.jgit | |
parent | 94599930e75b941869b02d0ea1147d6be0cb4ab4 (diff) | |
parent | 48e9a010ae9cfee5cc2daae2bf20d510ab9c108f (diff) | |
download | jgit-baaa78f1f05d197ba2efefb713f194cd3f09725d.tar.gz jgit-baaa78f1f05d197ba2efefb713f194cd3f09725d.zip |
Merge "Add unsetSection to Config to remove an entire block"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index d66aa74c8e..0d0c377f8f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -577,6 +577,43 @@ public class Config { } /** + * 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. * * <pre> @@ -1104,6 +1141,11 @@ public class Config { && 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; |