public ActionResult FileDiff(string path, string fromSha1, string toSha1) { var nGit = TM_UserData_Git.Current.NGit; Func <Repository, string, string, string, string> getDiff = (gitRepo, repoPath, fromCommitId, toCommitId) => { var fromCommit = gitRepo.Resolve(fromCommitId); var toCommit = gitRepo.Resolve(toCommitId); var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>(); //return "diffing from {0} to {1}".format(fromCommit, toCommit); var diffFormater = new DiffFormatter(outputStream); var pathFilter = PathFilter.Create(repoPath); diffFormater.SetRepository(gitRepo); diffFormater.SetPathFilter(pathFilter); //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId()); diffFormater.Format(fromCommit, toCommit); return("result: " + outputStream.str()); }; Func <Repository, string, string, string> getFistValue = (gitRepo, commitSha1, repoPath) => { var revCommit = nGit.commit(commitSha1); var outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast <OutputStream>(); var diffFormater = new DiffFormatter(outputStream); var pathFilter = PathFilter.Create(repoPath); diffFormater.SetRepository(gitRepo); diffFormater.SetPathFilter(pathFilter); var revWalk = new RevWalk(gitRepo); var canonicalTreeParser = new CanonicalTreeParser(null, revWalk.GetObjectReader(), revCommit.Tree); diffFormater.Format(new EmptyTreeIterator(), canonicalTreeParser); return(outputStream.str().fix_CRLF()); }; var rawDiff = fromSha1 == NGit_Consts.EMPTY_SHA1 ? getFistValue(nGit.repository(), fromSha1, path) : getDiff(nGit.repository(), path, fromSha1, toSha1); var viewFile = new View_GitFileDiff() { FilePath = path, FromSha1 = fromSha1, ToSha1 = toSha1, Diff = rawDiff }; return(View(viewFile)); }
// hasMismatches is just used to return a second value if you want // one. I would have used MutableBoxedBoolean if such had been provided. /// <exception cref="System.IO.IOException"/> public static IList <FileStatus> LocalGlobber(FileContext fc, Path root, string tail , PathFilter filter, AtomicBoolean hasFlatFiles) { if (tail.Equals(string.Empty)) { return(ListFilteredStatus(fc, root, filter)); } if (tail.StartsWith("/*")) { Path[] subdirs = FilteredStat2Paths(RemoteIterToList(fc.ListStatus(root)), true, hasFlatFiles); IList <IList <FileStatus> > subsubdirs = new List <IList <FileStatus> >(); int subsubdirCount = 0; if (subdirs.Length == 0) { return(new List <FileStatus>()); } string newTail = Sharpen.Runtime.Substring(tail, 2); for (int i = 0; i < subdirs.Length; ++i) { subsubdirs.AddItem(LocalGlobber(fc, subdirs[i], newTail, filter, null)); // subsubdirs.set(i, localGlobber(fc, subdirs[i], newTail, filter, // null)); subsubdirCount += subsubdirs[i].Count; } IList <FileStatus> result = new List <FileStatus>(); for (int i_1 = 0; i_1 < subsubdirs.Count; ++i_1) { Sharpen.Collections.AddAll(result, subsubdirs[i_1]); } return(result); } if (tail.StartsWith("/")) { int split = tail.IndexOf('/', 1); if (split < 0) { return(ListFilteredStatus(fc, new Path(root, Sharpen.Runtime.Substring(tail, 1)), filter)); } else { string thisSegment = Sharpen.Runtime.Substring(tail, 1, split); string newTail = Sharpen.Runtime.Substring(tail, split); return(LocalGlobber(fc, new Path(root, thisSegment), newTail, filter, hasFlatFiles )); } } IOException e = new IOException("localGlobber: bad tail"); throw e; }
/// <exception cref="System.IO.IOException"/> internal virtual void Init(string filePattern, PathFilter filter) { try { userFilter = filter; pattern = new GlobPattern(filePattern); } catch (PatternSyntaxException e) { // Existing code expects IOException startWith("Illegal file pattern") throw new IOException("Illegal file pattern: " + e.Message, e); } }
/* ----------------------------------------------------------------- */ /// /// DocumentName /// /// <summary> /// Initializes a new instance of the DocumentName class with the /// specified arguments. /// </summary> /// /// <param name="src">Document name.</param> /// <param name="alternate">Default filename.</param> /// <param name="io">I/O handler.</param> /// /* ----------------------------------------------------------------- */ public DocumentName(string src, string alternate, IO io) { IO = io; DefaultName = alternate; Filter = new PathFilter(src) { AllowCurrentDirectory = false, AllowDriveLetter = false, AllowInactivation = false, AllowParentDirectory = false, AllowUnc = false, }; }
public void RemovePath(int layer, PathFilter filter) { int from, to; for (int i = mLinks[layer].Count - 1; i >= 0; i--) { PathAt(layer, i, out from, out to); if (filter(from, to)) { mLinks[layer].RemoveAt(i); } } }
private ISsrsObjectRewriter BuildReplacementRule(ReplacementRuleDef def) { var filter = PathFilter.ParseGlob(def.Filter) ?? PathFilter.MatchAll; switch (def.Target) { case "DataSet.DataSourceReference": return(new SsrsDataSetDataSourceReferenceRewriter(filter, def.Replacement)); default: throw new FormatException($"Unrecognised replacement target: {def.Target}"); } }
/* ----------------------------------------------------------------- */ /// /// DocumentName /// /// <summary> /// Initializes a new instance of the DocumentName class with the /// specified arguments. /// </summary> /// /// <param name="src">Original document name.</param> /// <param name="alternate">Default filename.</param> /// <param name="io">I/O handler.</param> /// /* ----------------------------------------------------------------- */ public DocumentName(string src, string alternate, IO io) { _filter = new PathFilter(src) { AllowCurrentDirectory = false, AllowDriveLetter = false, AllowInactivation = false, AllowParentDirectory = false, AllowUnc = false, }; Value = GetValue(alternate, io); }
/// <summary>Determine the differences between two trees.</summary> /// <remarks> /// Determine the differences between two trees. /// No output is created, instead only the file paths that are different are /// returned. Callers may choose to format these paths themselves, or convert /// them into /// <see cref="NGit.Patch.FileHeader">NGit.Patch.FileHeader</see> /// instances with a complete edit list by /// calling /// <see cref="ToFileHeader(DiffEntry)">ToFileHeader(DiffEntry)</see> /// . /// </remarks> /// <param name="a">the old (or previous) side.</param> /// <param name="b">the new (or updated) side.</param> /// <returns>the paths that are different.</returns> /// <exception cref="System.IO.IOException">trees cannot be read or file contents cannot be read. /// </exception> public virtual IList <DiffEntry> Scan(AbstractTreeIterator a, AbstractTreeIterator b) { AssertHaveRepository(); TreeWalk walk = new TreeWalk(reader); walk.AddTree(a); walk.AddTree(b); walk.Recursive = true; TreeFilter filter = GetDiffTreeFilterFor(a, b); if (pathFilter is FollowFilter) { walk.Filter = AndTreeFilter.Create(PathFilter.Create(((FollowFilter)pathFilter).GetPath ()), filter); } else { walk.Filter = AndTreeFilter.Create(pathFilter, filter); } source = new ContentSource.Pair(Source(a), Source(b)); IList <DiffEntry> files = DiffEntry.Scan(walk); if (pathFilter is FollowFilter && IsAdd(files)) { // The file we are following was added here, find where it // came from so we can properly show the rename or copy, // then continue digging backwards. // a.Reset(); b.Reset(); walk.Reset(); walk.AddTree(a); walk.AddTree(b); walk.Filter = filter; if (renameDetector == null) { SetDetectRenames(true); } files = UpdateFollowFilter(DetectRenames(DiffEntry.Scan(walk))); } else { if (renameDetector != null) { files = DetectRenames(files); } } return(files); }
public void DeeplyNestedFilters() { Modification[] modlist = new Modification[] { ModificationMother.CreateModification("x.cs", "/working/sources"), ModificationMother.CreateModification("Entries", "/working/sources/CVS"), ModificationMother.CreateModification("x.build", "/working/build"), ModificationMother.CreateModification("x.dll", "/working/build/target/sources") }; PathFilter filter = new PathFilter(); filter.Pattern = "**/sources/**/*.*"; filter.Accept(modlist[0]); }
public static bool Apply(this PathFilter pathFilter, string path) { switch (pathFilter.FilterPatternType) { case FilterPatternType.Glob: return(pathFilter.GetSafeGlob().IsMatch(path)); case FilterPatternType.Regexp: return(pathFilter.GetSafeRegexp().IsMatch(path)); default: throw new ArgumentException(String.Format("FilterPatternType {0} not supported", (int)pathFilter.FilterPatternType), "pathFilter.FilterPatternType"); } }
internal FakeFileSystemWatcher([NotNull] FakeFileSystem owner, [NotNull] FakeFileSystemChangeTracker changeTracker, [CanBeNull] AbsolutePath path, [NotNull] string filter) { Guard.NotNull(owner, nameof(owner)); Guard.NotNull(changeTracker, nameof(changeTracker)); Guard.NotNull(filter, nameof(filter)); this.owner = owner; this.changeTracker = changeTracker; directoryToWatch = path; pathFilter = new PathFilter(filter, true); consumerThread = new Thread(() => ConsumerLoop(consumerCancellationTokenSource.Token)) { IsBackground = true }; }
/// <exception cref="System.IO.IOException"></exception> private DiffEntry FindRename(RevCommit parent, RevCommit commit, PathFilter path) { if (renameDetector == null) { return(null); } treeWalk.Filter = TreeFilter.ANY_DIFF; treeWalk.Reset(parent.Tree, commit.Tree); renameDetector.AddAll(DiffEntry.Scan(treeWalk)); foreach (DiffEntry ent in renameDetector.Compute()) { if (IsRename(ent) && ent.GetNewPath().Equals(path.GetPath())) { return(ent); } } return(null); }
public void Directory_Filter_Should_Apply() { var PathFilter = new PathFilter(); var directory = new DirectoryInfo("/Static/Test/"); var directories = new[] { directory }; var filter = new FilterConfig { Entries = new List <string> { "Static/" } }; var result = PathFilter.Filter(filter, directories); Assert.Empty(result); }
public void Directory_File_Combination_Should_Apply() { var PathFilter = new PathFilter(); var file = new FileInfo("/bin/test.csproj"); var files = new[] { file }; var filter = new FilterConfig { Entries = new List <string> { "bin/*.csproj" } }; var result = PathFilter.Filter(filter, files); Assert.Empty(result); }
public IJob CreateJob() { if (String.IsNullOrWhiteSpace(SsrsUriString)) { throw new InvalidArgumentsException("No SSRS URI specified."); } if (!Uri.TryCreate(SsrsUriString, UriKind.Absolute, out _)) { throw new InvalidArgumentsException($"Not a valid absolute URI: {SsrsUriString}"); } var source = GetObjectSource(); if (!source.HasManifest && Site != null) { throw new InvalidArgumentsException("--site was specified but no manifest was found."); } if (!new SsrsObjectTypesParser().ValidateTypes(ObjectFilter.TypeFilter, out var invalidTypes)) { throw new InvalidArgumentsException($"Invalid object types: {invalidTypes}"); } var filter = new SsrsObjectFilter { ObjectTypes = new SsrsObjectTypesParser().GetTypeFilter(ObjectFilter.TypeFilter), Path = new PathFilterExpression( PathFilter.ParseGlob(ObjectFilter.IncludePaths) ?? PathFilter.MatchAll, PathFilter.ParseGlob(ObjectFilter.ExcludePaths) ), Site = Site }; var ssrsUri = new Uri(SsrsUriString, UriKind.Absolute); var service = ReportingServiceClientFactory.CreateFromShorthandUri(ssrsUri); var job = new ImportJob(service, source, filter) { Overwrite = Overwrite, BackupTarget = GetBackupTarget() }; foreach (var rule in RewriteRules) { var rewriter = new RewriteRuleParser().Parse(rule); job.Rewriters.Add(rewriter); } return(job); }
public static void ListZipFile(string fileName, string fileFilter, string directoryFilter) { using (ZipFile zipFile = new ZipFile(fileName)) { PathFilter localFileFilter = new PathFilter(fileFilter); PathFilter localDirFilter = new PathFilter(directoryFilter); if (zipFile.Count == 0) { Console.WriteLine("No entries to list"); } else { for (int i = 0; i < zipFile.Count; ++i) { ZipEntry e = zipFile[i]; if (e.IsFile) { string path = Path.GetDirectoryName(e.Name); if (localDirFilter.IsMatch(path)) { if (localFileFilter.IsMatch(Path.GetFileName(e.Name))) { Console.WriteLine(e.Name); } } } else if (e.IsDirectory) { if (localDirFilter.IsMatch(e.Name)) { Console.WriteLine(e.Name); } } else { Console.WriteLine(e.Name); } } } } }
/// <exception cref="System.IO.IOException"></exception> private void Seek(string path) { if (!path.Equals(current)) { iterator.Reset(); tw.Reset(); tw.AddTree(iterator); tw.Filter = PathFilter.Create(path); current = path; if (!tw.Next()) { throw new FileNotFoundException(path); } ptr = tw.GetTree <WorkingTreeIterator>(0); if (ptr == null) { throw new FileNotFoundException(path); } } }
/// <param name="conf">configuration for the job</param> /// <param name="dirs">the initial list of paths</param> /// <param name="recursive">whether to traverse the patchs recursively</param> /// <param name="inputFilter">inputFilter to apply to the resulting paths</param> /// <param name="newApi">whether using the mapred or mapreduce API</param> /// <exception cref="System.Exception"/> /// <exception cref="System.IO.IOException"/> public LocatedFileStatusFetcher(Configuration conf, Path[] dirs, bool recursive, PathFilter inputFilter, bool newApi) { processInitialInputPathCallback = new LocatedFileStatusFetcher.ProcessInitialInputPathCallback (this); processInputDirCallback = new LocatedFileStatusFetcher.ProcessInputDirCallback(this ); int numThreads = conf.GetInt(FileInputFormat.ListStatusNumThreads, FileInputFormat .DefaultListStatusNumThreads); rawExec = Executors.NewFixedThreadPool(numThreads, new ThreadFactoryBuilder().SetDaemon (true).SetNameFormat("GetFileInfo #%d").Build()); exec = MoreExecutors.ListeningDecorator(rawExec); resultQueue = new LinkedBlockingQueue <IList <FileStatus> >(); this.conf = conf; this.inputDirs = dirs; this.recursive = recursive; this.inputFilter = inputFilter; this.newApi = newApi; }
public virtual void GeneratorFilteredToOneOfTwoSubmodules() { ObjectId id1 = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); string path1 = "sub1"; ObjectId id2 = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1235"); string path2 = "sub2"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_271(id1, path1)); editor.Add(new _PathEdit_278(id2, path2)); editor.Commit(); SubmoduleWalk gen = SubmoduleWalk.ForIndex(db); gen.SetFilter(PathFilter.Create(path1)); NUnit.Framework.Assert.IsTrue(gen.Next()); NUnit.Framework.Assert.AreEqual(path1, gen.GetPath()); NUnit.Framework.Assert.AreEqual(id1, gen.GetObjectId()); NUnit.Framework.Assert.IsFalse(gen.Next()); }
/// <summary>Construct a list of StatusPair objects</summary> /// <param name="fs">The FileSystem where 'path' lives</param> /// <param name="path">The directory to query</param> /// <param name="filter">A possible filter for entries in the directory</param> /// <exception cref="System.IO.IOException"/> public StatusPairs(FileSystem fs, Path path, PathFilter filter) { /* Grab all the file statuses at once in an array */ FileStatus[] fileStatuses = fs.ListStatus(path, filter); /* We'll have an array of StatusPairs of the same length */ AclStatus aclStatus = null; statusPairs = new FSOperations.StatusPair[fileStatuses.Length]; /* * For each FileStatus, attempt to acquire an AclStatus. If the * getAclStatus throws an exception, we assume that ACLs are turned * off entirely and abandon the attempt. */ bool useAcls = true; // Assume ACLs work until proven otherwise for (int i = 0; i < fileStatuses.Length; i++) { if (useAcls) { try { aclStatus = fs.GetAclStatus(fileStatuses[i].GetPath()); } catch (AclException) { /* Almost certainly due to an "ACLs not enabled" exception */ aclStatus = null; useAcls = false; } catch (NotSupportedException) { /* Ditto above - this is the case for a local file system */ aclStatus = null; useAcls = false; } } statusPairs[i] = new FSOperations.StatusPair(fileStatuses[i], aclStatus); } }
/* ----------------------------------------------------------------- */ /// /// Invoke /// /// <summary> /// 情報を更新します。 /// </summary> /// /* ----------------------------------------------------------------- */ public void Invoke(RefreshableInfo src) { RawName = GetPath(src.Source); Encrypted = Get <bool>(src.Source, ItemPropId.Encrypted); src.Exists = true; src.IsDirectory = Get <bool>(src.Source, ItemPropId.IsDirectory); src.Attributes = (System.IO.FileAttributes)Get <uint>(src.Source, ItemPropId.Attributes); src.Length = (long)Get <ulong>(src.Source, ItemPropId.Size); src.CreationTime = Get <DateTime>(src.Source, ItemPropId.CreationTime); src.LastWriteTime = Get <DateTime>(src.Source, ItemPropId.LastWriteTime); src.LastAccessTime = Get <DateTime>(src.Source, ItemPropId.LastAccessTime); _filter = new PathFilter(RawName) { AllowParentDirectory = false, AllowDriveLetter = false, AllowCurrentDirectory = false, AllowInactivation = false, AllowUnc = false, }; src.FullName = _filter.EscapedPath; if (string.IsNullOrEmpty(_filter.EscapedPath)) { return; } var info = _io.Get(_filter.EscapedPath); src.Name = info.Name; src.NameWithoutExtension = info.NameWithoutExtension; src.Extension = info.Extension; src.DirectoryName = info.DirectoryName; if (src.FullName != RawName) { this.LogDebug($"Escape:{src.FullName}\tRaw:{RawName}"); } }
/// <exception cref="System.IO.IOException"></exception> private bool Find(RevCommit commit, PathFilter path) { treeWalk.Filter = path; treeWalk.Reset(commit.Tree); while (treeWalk.Next()) { if (path.IsDone(treeWalk)) { if (treeWalk.GetFileMode(0).GetObjectType() != Constants.OBJ_BLOB) { return(false); } treeWalk.GetObjectId(idBuf, 0); return(true); } if (treeWalk.IsSubtree) { treeWalk.EnterSubtree(); } } return(false); }
public virtual void TestSameDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder"); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder change"); df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); oldTree = new DirCacheIterator(db.ReadDirCache()); newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); }
public virtual void TestDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "folder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "folder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df.GetCalulatedPatchId ().Name); }
public IJob CreateJob() { var source = GetObjectSource(); if (!source.HasManifest && Site != null) { throw new InvalidArgumentsException("--site was specified but no manifest was found."); } if (!new SsrsObjectTypesParser().ValidateTypes(ObjectFilter.TypeFilter, out var invalidTypes)) { throw new InvalidArgumentsException($"Invalid object types: {invalidTypes}"); } var filter = new SsrsObjectFilter { ObjectTypes = new SsrsObjectTypesParser().GetTypeFilter(ObjectFilter.TypeFilter), Path = new PathFilterExpression( PathFilter.ParseGlob(ObjectFilter.IncludePaths) ?? PathFilter.MatchAll, PathFilter.ParseGlob(ObjectFilter.ExcludePaths) ), Site = Site }; return(new InspectJob(source, filter)); }
public SyncPromptModel(TransferPromptController controller, Transfer transfer) : base(controller, transfer) { _filter = new SyncPathFilter(transfer); }
public abstract FileStatus[] GlobStatus(Path arg1, PathFilter arg2);
internal BlobCandidate(string name, PathFilter path) : base(null, path) { description = name; }
internal override Candidate Create(RevCommit commit, PathFilter path) { return(new Candidate.ReverseCandidate((ReverseWalk.ReverseCommit)commit, path)); }
internal ReverseCandidate(ReverseWalk.ReverseCommit commit, PathFilter path) : base (commit, path) { }
internal virtual NGit.Blame.Candidate Create(RevCommit commit, PathFilter path) { return(new NGit.Blame.Candidate(commit, path)); }
public FilterWrapper(PathFilter del) { _del = del; }