diff src/org/tmatesoft/hg/repo/HgInternals.java @ 409:0f5696623512 smartgit3

Support glob path pattern rewrite to facilitate use of globs with Windows path separator
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Mar 2012 20:14:47 +0100
parents 82336b7c54f4
children 63c5a9d7ca3f
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgInternals.java	Fri Mar 16 15:06:44 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgInternals.java	Fri Mar 16 20:14:47 2012 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2012 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,7 +29,9 @@
 import org.tmatesoft.hg.core.HgInvalidRevisionException;
 import org.tmatesoft.hg.core.SessionContext;
 import org.tmatesoft.hg.internal.Experimental;
+import org.tmatesoft.hg.internal.Internals;
 import org.tmatesoft.hg.internal.RelativePathRewrite;
+import org.tmatesoft.hg.internal.WinToNixPathRewrite;
 import org.tmatesoft.hg.util.FileIterator;
 import org.tmatesoft.hg.util.FileWalker;
 import org.tmatesoft.hg.util.Path;
@@ -87,8 +89,22 @@
 		return hgRepo.getRepositoryRoot();
 	}
 	
-	public static HgIgnore newHgIgnore(Reader source) throws IOException {
-		HgIgnore hgIgnore = new HgIgnore();
+	/**
+	 * @param source where to read definitions from
+	 * @param globPathRewrite <code>null</code> to use default, or pass an instance to override defaults
+	 * @return
+	 * @throws IOException
+	 */
+	public static HgIgnore newHgIgnore(Reader source, PathRewrite globPathRewrite) throws IOException {
+		if (globPathRewrite == null) {
+			// shall match that of HgRepository#getIgnore() (Internals#buildNormalizePathRewrite())
+			if (Internals.runningOnWindows()) {
+				globPathRewrite = new WinToNixPathRewrite();
+			} else {
+				globPathRewrite = new PathRewrite.Empty();
+			}
+		}
+		HgIgnore hgIgnore = new HgIgnore(globPathRewrite);
 		BufferedReader br = source instanceof BufferedReader ? (BufferedReader) source : new BufferedReader(source);
 		hgIgnore.read(br);
 		br.close();