public FoundDiff(string fileName, string fullPath, DiffInfo diffInfo, int resultAmount) { Name = fileName; FullPath = fullPath; ResultCount = resultAmount; DiffInfo = diffInfo; }
private void RelistDiffsInCache() { SaveEqualContent(); withUnknownDocumentId = 0; var docidtodiffs = new ConcurrentDictionary <int, IList <DiffInfo> >(); var result = new ConcurrentDictionary <DiffInfo, int>(); IndexSearcher searcher = new IndexSearcher(LuceneIndexDirectory, true); var query = new MatchAllDocsQuery(); var topDocs = searcher.Search(query, int.MaxValue); var hits = topDocs.ScoreDocs; foreach (var hit in hits) { var doc = searcher.Doc(hit.Doc); long revB = long.Parse(doc.Get("revision")); string path = doc.Get("path"); DiffInfo di = new DiffInfo(path, revB); result.TryAdd(di, hit.Doc); docidtodiffs.TryAdd(hit.Doc, new List <DiffInfo> { di }); } IList <DiffInfo> toRemove = new List <DiffInfo>(); foreach (var kv in equalContent) { int did; if (result.TryGetValue(kv.Value, out did)) { IList <DiffInfo> li; if (docidtodiffs.TryGetValue(did, out li)) { li.Add(kv.Key); } } else { Progress.DebugLog("DiffInfo {0} should be linked to {1} but {1} was not found in diffsInCache", kv.Key, kv.Value); toRemove.Add(kv.Key); } } foreach (var e in toRemove) { DiffInfo dc; equalContent.TryRemove(e, out dc); } docIDtoDiffs = docidtodiffs; diffsInCache = result; }
public DiffInfo GetCreation(NodeAtTime nodeAtTime) { if (this.Disposed) { Progress.DebugLog("GetCreation called on closed SubversionSearcher"); return(null); } if (nodeAtTime.IsFolder) { return(null); } long revA = 0; long revC = nodeAtTime.DeleteRevision.HasValue ? nodeAtTime.DeleteRevision.Value - 1 : long.MaxValue; if (nodeAtTime.Actions.Count > 1) { revC = nodeAtTime.Actions[1].Revision - 1; } IList <NodeAtTime> li; if (nodes.TryGetValue(nodeAtTime.Path, out li)) { for (int i = li.Count - 1; i >= 0; i--) { if (li[i] != nodeAtTime) { continue; } if (i > 0) { i--; if (li[i].DeleteRevision.HasValue) { revA = li[i].DeleteRevision.Value; } else { Progress.DebugLog("DeleteRevision is null for {0}@{1}", li[i].Path, li[i].AddRevision); } } break; } } var newDI = new DiffInfo(nodeAtTime.Path, revA, nodeAtTime.AddRevision, revC); newDI.SetNodeAtTime(nodeAtTime); return(newDI); }
// returns document id private int AddToIndex(DiffInfo diffInfo, string content) { int docId; if (diffsInCache.TryGetValue(diffInfo, out docId)) { return(docId); } else { docId = -1; } Document doc = new Document(); doc.Add(new Field("combined", String.Format("{0}@{1}", diffInfo.Path, diffInfo.RevB), Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.Add(new Field("revision", diffInfo.RevB.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("path", diffInfo.Path, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("content", content, Field.Store.YES, Field.Index.ANALYZED)); Writer.AddDocument(doc); withUnknownDocumentId++; diffsInCache.TryAdd(diffInfo, docId); if (++uncommitedDiffs > 100 && IsActive) { uncommitedDiffs = 0; Writer.Commit(); } return(docId); }
/// <summary> /// gets diff content by finding the doc id /// </summary> /// <param name="diffInfo"></param> /// <param name="fromDocID"></param> /// <returns></returns> public string GetDiff(DiffInfo diffInfo, out int fromDocID) { fromDocID = -3; IndexSearcher searcher = new IndexSearcher(LuceneIndexDirectory, true); DiffInfo di; if (!equalContent.TryGetValue(diffInfo, out di)) { di = diffInfo; } int docId; if (diffsInCache.TryGetValue(di, out docId) && docId > -1) { diffsInCache[di] = docId; fromDocID = docId; return(searcher.Doc(docId).Get("content")); } else { Query query = new WildcardQuery(new Term("combined", String.Format("{0}@{1}", di.Path, di.RevB))); var topDocs = searcher.Search(query, int.MaxValue); var hits = topDocs.ScoreDocs; if (hits.Length != 1) { Progress.DebugLog("Found {0} diffs by the name of {1} instead of 1", hits.Length, String.Format("{0}@{1}", di.Path, di.RevB)); } foreach (var hit in hits) { var doc = searcher.Doc(hit.Doc); diffsInCache[di] = hit.Doc; fromDocID = hit.Doc; return(doc.Get("content")); } } return(null); }
public void AddToIndex(DiffInfo diffInfo, Stream stream, ISet <DiffInfo> equalDiffs) { stream.Position = 0; StreamReader sr = new StreamReader(stream); string content = sr.ReadToEnd(); stream.Close(); if (equalDiffs == null) { AddToIndex(diffInfo, content); } else { DiffInfo inCache = null; bool alreadyContains = false; foreach (var e in equalDiffs) { int docID; if (diffsInCache.TryGetValue(e, out docID)) { alreadyContains = true; inCache = e; break; } } if (!alreadyContains) { AddToIndex(inCache = diffInfo, content); } foreach (var e in equalDiffs) { if (e != inCache) { equalContent.TryAdd(e, diffInfo); } } } }
public bool HasDiff(DiffInfo di) { return(diffsInCache.ContainsKey(di) || equalContent.ContainsKey(di)); }
void AddDiffsForNode(NodeAtTime node, long startRevision, long endRevision, ref IList <DiffInfo> diffs, ICollection <long> ignoreRevsions) { if (node.IsFolder) { return; } long prevRev = 0; long nextRev; // finding delete revision of previous node that existed here IList <NodeAtTime> li; if (nodes.TryGetValue(node.Path, out li)) { for (int j = li.Count - 1; j >= 0; j--) { if (li[j] != node) { continue; } if (j-- > 0) { prevRev = li[j].DeleteRevision == null ? long.MaxValue : li[j].DeleteRevision.Value; } break; } } for (int i = 0; i < node.Actions.Count; i++) { var na = node.Actions[i]; // revision span if (na.Revision < startRevision) { continue; } else if (na.Revision > endRevision) { break; } // ignoring delete revision because we don't diff deletes if (ignoreRevsions.Contains(na.Revision) || node.DeleteRevision.HasValue && na.Revision == node.DeleteRevision) { continue; } // finding maximum upper revision if (i < node.Actions.Count - 1) { nextRev = node.Actions[i + 1].Revision - 1; } else { nextRev = node.DeleteRevision.HasValue ? node.DeleteRevision.Value - 1 : HeadRevision; } DiffInfo newDI = null; if (prevRev != na.Revision) { diffs.Add(newDI = new DiffInfo(node.Path, prevRev, na.Revision, nextRev)); } if (newDI != null) { newDI.SetNodeAtTime(node); } prevRev = na.Revision; } }