Re: anthill - subversion tags and versions (period not an underscore)
Jim Hague <[email protected]> Tue, 19 Feb 2008 21:25:00 +0000
| Newsgroups | gmane.comp.java.anthill |
|---|---|
| Message-ID | <[email protected]> |
--Boundary-00=_sk0uHIdDPss8cIF Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Saturday 16 Feb 2008, Kenneth Burgener wrote: > > I am inclined to both fix this - run the version label through the same > > edit on checkout - and to remove '.' (and maybe ',' and ';') from the > > troublesome characters. Any thoughts? > > [...] I do fully > agree, if you are going to do an edit on the tagging, there should be > the edit on the checkout as well. The characters '.', ',' and ';' all > appear to be acceptable as folder names (with the exception of '.' > starting and ending a file name), so they should probably all be > acceptable. I'm away from my Anthill setup at the moment, so I haven't tested it, but the attached patch builds and looks about right. Unfortunately it's a patch to Anthill + the other patches I have, so it will probably need a bit of wiggling to go onto your sources (and you won't have the Mercurial repository adapter). It follows the above suggestion and leaves commas and semi-colons alone, and only troubles periods when they start or end a tag. Of course, this also means that your old tags still have to be entered in post-processed form, but at least the new tags should work. Alternatively, if you grok Mercurial (http://www.selenic.com/mercurial) hg qclone http://hg.lunch.org.uk/Anthill will get you the Anthill CVS converted to Mercurial and all my changes on top of that as mq patches. Does that help at all? -- Jim Hague - [email protected] Never trust a computer you can't lift. --Boundary-00=_sk0uHIdDPss8cIF Content-Type: text/x-diff; charset="iso-8859-1"; name="sanitise.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sanitise.patch" # HG changeset patch # User Jim Hague <jim.hague-70XMh/ZFPwTe9wHmmfpqLFaTQe2KTcn/@public.gmane.org> # Date 1203455940 0 # Node ID 27903d0d1466d43a60248c1151620f940e9d915b # Parent bd2275d147e9a0560eee53938c8bbc7a0fb62f12 Sanitise tags before labelling and before checking out labelled version. Subversion and (to a lesser extent) Mercurial both remove potentially dangerous characters from a tag before labelling. Ensure that sanitising happens both when the label is created and when checking out a specific versioned build. diff -r bd2275d147e9 -r 27903d0d1466 source/main/java/com/urbancode/anthill/adapter/MercurialRepositoryAdapter.java --- a/source/main/java/com/urbancode/anthill/adapter/MercurialRepositoryAdapter.java Tue Feb 19 21:19:00 2008 +0000 +++ b/source/main/java/com/urbancode/anthill/adapter/MercurialRepositoryAdapter.java Tue Feb 19 21:19:00 2008 +0000 @@ -90,6 +90,20 @@ public class MercurialRepositoryAdapter localProjectDirName = project.getProperties().getProperty(REPO_DIR_KEY); branchName = project.getProperties().getProperty(BRANCHNAME_KEY); anthillUserName = project.getProperties().getProperty(USERNAME_KEY); + } + + /** + * Check a tag for characters that might prove troublesome in a + * branch name and replace any such. + * + * Troublesome characters are any :. + * + * @param tag the tag. + * @return a filesystem sanitised tag. + */ + protected String sanitiseTag(String tag) + { + return tag.replace(':', '_'); } /** @@ -191,7 +205,7 @@ public class MercurialRepositoryAdapter tempMap.put("AtChange", getRevisionFromBuildId(buildId)); if (def.getVersionedBuildFlag()){ log.info("Retrieving project version " + def.getVersion()); - tempMap.put("Version", def.getVersion().trim()); + tempMap.put("Version", sanitiseTag(def.getVersion().trim())); } Pagelet pagelet = getPageletFactory().getPagelet(makeProfilePageletName(WORKING_PROJECT_PAGELET)); @@ -520,7 +534,7 @@ public class MercurialRepositoryAdapter throw (new RepositoryException("No label specified")); } - tag = tag.replace(':', '_'); + tag = sanitiseTag(tag); log.info("Tagging entire project with label: " + tag); diff -r bd2275d147e9 -r 27903d0d1466 source/main/java/com/urbancode/anthill/adapter/SubversionRepositoryAdapter.java --- a/source/main/java/com/urbancode/anthill/adapter/SubversionRepositoryAdapter.java Tue Feb 19 21:19:00 2008 +0000 +++ b/source/main/java/com/urbancode/anthill/adapter/SubversionRepositoryAdapter.java Tue Feb 19 21:19:00 2008 +0000 @@ -127,6 +127,34 @@ public class SubversionRepositoryAdapter calculateWorkDirName(WORK_DIR_KEY); localProjectDirName = workDirName; } + + /** + * Check a tag for characters that might prove troublesome in a + * filesystem, and replace any such. + * + * Troublesome characters are any $ : or @, and a . as the first + * or last character. + * + * @param tag the tag. + * @return a filesystem sanitised tag. + */ + protected String sanitiseTag(String tag) + { + StringBuffer buf = new StringBuffer(tag); + + for ( int i = 0; i < buf.length(); i++ ) + { + char c = buf.charAt(i); + + if ( c == '$' || c == ':' || c == '@' || + ( c == '.' && ( i == 0 || i == buf.length() - 1 ) ) ) + buf.setCharAt(i, '_'); + } + + return buf.toString(); + } + + /** * checks out entire project and notes the revision the local @@ -150,7 +178,7 @@ public class SubversionRepositoryAdapter tempMap.put("Properties", project.getProperties()); if (def.getVersionedBuildFlag()){ log.info("Retrieving project version " + def.getVersion()); - tempMap.put("Version", def.getVersion().trim()); + tempMap.put("Version", sanitiseTag(def.getVersion().trim())); } Pagelet pagelet = getPageletFactory().getPagelet(makeProfilePageletName(WORKING_PROJECT_PAGELET)); @@ -496,8 +524,7 @@ public class SubversionRepositoryAdapter throw (new RepositoryException("No label specified")); } - tag = tag.replace('$', '_').replace(',', '_').replace('.', '_') - .replace(':', '_').replace(';', '_').replace('@', '_'); + tag = sanitiseTag(tag); log.info("Tagging entire project with label: " + tag); --Boundary-00=_sk0uHIdDPss8cIF Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Anthill mailing list Anthill-IWHQxnLZ/[email protected] http://lists.urbancode.com/mailman/listinfo/anthill --Boundary-00=_sk0uHIdDPss8cIF--