public override void SetUp() { base.SetUp(); toLoad = new AList<WindowCacheGetTest.TestObject>(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream( JGitTestUtil.GetTestResourceFile("all_packed_objects.txt")), Constants.CHARSET)); try { string line; while ((line = br.ReadLine()) != null) { string[] parts = line.Split(" {1,}"); WindowCacheGetTest.TestObject o = new WindowCacheGetTest.TestObject(this); o.id = ObjectId.FromString(parts[0]); o.SetType(parts[1]); // parts[2] is the inflate size // parts[3] is the size-in-pack // parts[4] is the offset in the pack toLoad.AddItem(o); } } finally { br.Close(); } NUnit.Framework.Assert.AreEqual(96, toLoad.Count); }
/// <summary>Returns the rev ID of the 'winning' revision of this document, and whether it's deleted.</summary> /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> internal String WinningRevIDOfDoc(Int64 docNumericId, IList<Boolean> outIsDeleted, IList<Boolean> outIsConflict) { Cursor cursor = null; var args = new [] { Convert.ToString(docNumericId) }; String revId = null; var sql = "SELECT revid, deleted FROM revs WHERE doc_id=? and current=1" + " ORDER BY deleted asc, revid desc LIMIT 2"; try { cursor = StorageEngine.RawQuery(sql, args); cursor.MoveToNext(); if (!cursor.IsAfterLast()) { revId = cursor.GetString(0); var deleted = cursor.GetInt(1) > 0; if (deleted) { outIsDeleted.AddItem(true); } // The document is in conflict if there are two+ result rows that are not deletions. var hasNextResult = cursor.MoveToNext(); if (hasNextResult) { var isNextDeleted = cursor.GetInt(1) > 0; var isInConflict = !deleted && hasNextResult && !isNextDeleted; if (isInConflict) { outIsConflict.AddItem(true); } } } } catch (SQLException e) { Log.E(Tag, "Error", e); throw new CouchbaseLiteException("Error", e, new Status(StatusCode.InternalServerError)); } finally { if (cursor != null) { cursor.Close(); } } return revId; }
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> internal IEnumerable<QueryRow> QueryViewNamed(String viewName, QueryOptions options, IList<Int64> outLastSequence) { var before = Runtime.CurrentTimeMillis(); var lastSequence = 0L; IEnumerable<QueryRow> rows; if (!String.IsNullOrEmpty (viewName)) { var view = GetView (viewName); if (view == null) { throw new CouchbaseLiteException (StatusCode.NotFound); } lastSequence = view.LastSequenceIndexed; if (options.GetStale () == IndexUpdateMode.Before || lastSequence <= 0) { view.UpdateIndex (); lastSequence = view.LastSequenceIndexed; } else { if (options.GetStale () == IndexUpdateMode.After && lastSequence < GetLastSequenceNumber()) // NOTE: The exception is handled inside the thread. // TODO: Consider using the async keyword instead. try { view.UpdateIndex(); } catch (CouchbaseLiteException e) { Log.E(Tag, "Error updating view index on background thread", e); } } rows = view.QueryWithOptions (options); } else { // nil view means query _all_docs // note: this is a little kludgy, but we have to pull out the "rows" field from the // result dictionary because that's what we want. should be refactored, but // it's a little tricky, so postponing. var allDocsResult = GetAllDocs (options); rows = (IList<QueryRow>)allDocsResult.Get ("rows"); lastSequence = GetLastSequenceNumber (); } outLastSequence.AddItem(lastSequence); var delta = Runtime.CurrentTimeMillis() - before; Log.D(Tag, String.Format("Query view {0} completed in {1} milliseconds", viewName, delta)); return rows; }
internal WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w) { NGit.Transport.Transport wt = (NGit.Transport.Transport)t; local = wt.local; objCheck = wt.IsCheckFetchedObjects() ? new ObjectChecker() : null; inserter = local.NewObjectInserter(); reader = local.NewObjectReader(); remotes = new AList<WalkRemoteObjectDatabase>(); remotes.AddItem(w); unfetchedPacks = new List<WalkFetchConnection.RemotePack>(); packsConsidered = new HashSet<string>(); noPacksYet = new List<WalkRemoteObjectDatabase>(); noPacksYet.AddItem(w); noAlternatesYet = new List<WalkRemoteObjectDatabase>(); noAlternatesYet.AddItem(w); fetchErrors = new Dictionary<ObjectId, IList<Exception>>(); packLocks = new AList<PackLock>(4); revWalk = new RevWalk(reader); revWalk.SetRetainBody(false); treeWalk = new TreeWalk(reader); COMPLETE = revWalk.NewFlag("COMPLETE"); IN_WORK_QUEUE = revWalk.NewFlag("IN_WORK_QUEUE"); LOCALLY_SEEN = revWalk.NewFlag("LOCALLY_SEEN"); localCommitQueue = new DateRevQueue(); workQueue = new List<ObjectId>(); }
internal string WinningRevIDOfDoc(long docNumericId, IList<bool> outIsDeleted, IList <bool> outIsConflict) { Cursor cursor = null; string sql = "SELECT revid, deleted FROM revs" + " WHERE doc_id=? and current=1" + " ORDER BY deleted asc, revid desc LIMIT 2"; string[] args = new string[] { System.Convert.ToString(docNumericId) }; string revId = null; try { cursor = database.RawQuery(sql, args); cursor.MoveToNext(); if (!cursor.IsAfterLast()) { revId = cursor.GetString(0); bool deleted = cursor.GetInt(1) > 0; if (deleted) { outIsDeleted.AddItem(true); } // The document is in conflict if there are two+ result rows that are not deletions. bool hasNextResult = cursor.MoveToNext(); if (hasNextResult) { bool isNextDeleted = cursor.GetInt(1) > 0; bool isInConflict = !deleted && hasNextResult && isNextDeleted; if (isInConflict) { outIsConflict.AddItem(true); } } } } catch (SQLException e) { Log.E(Database.Tag, "Error", e); throw new CouchbaseLiteException("Error", e, new Status(Status.InternalServerError )); } finally { if (cursor != null) { cursor.Close(); } } return revId; }
public IList<QueryRow> QueryViewNamed(string viewName, QueryOptions options, IList <long> outLastSequence) { long before = Runtime.CurrentTimeMillis(); long lastSequence = 0; IList<QueryRow> rows = null; if (viewName != null && viewName.Length > 0) { View view = GetView(viewName); if (view == null) { throw new CouchbaseLiteException(new Status(Status.NotFound)); } lastSequence = view.GetLastSequenceIndexed(); if (options.GetStale() == Query.IndexUpdateMode.Before || lastSequence <= 0) { view.UpdateIndex(); lastSequence = view.GetLastSequenceIndexed(); } else { if (options.GetStale() == Query.IndexUpdateMode.After && lastSequence < GetLastSequenceNumber ()) { new Sharpen.Thread(new _Runnable_1847(view)).Start(); } } rows = view.QueryWithOptions(options); } else { // nil view means query _all_docs // note: this is a little kludgy, but we have to pull out the "rows" field from the // result dictionary because that's what we want. should be refactored, but // it's a little tricky, so postponing. IDictionary<string, object> allDocsResult = GetAllDocs(options); rows = (IList<QueryRow>)allDocsResult.Get("rows"); lastSequence = GetLastSequenceNumber(); } outLastSequence.AddItem(lastSequence); long delta = Runtime.CurrentTimeMillis() - before; Log.D(Database.Tag, string.Format("Query view %s completed in %d milliseconds", viewName , delta)); return rows; }
public string GetDesignDocFunction(string fnName, string key, IList<string> outLanguageList ) { string[] path = fnName.Split("/"); if (path.Length != 2) { return null; } string docId = string.Format("_design/%s", path[0]); RevisionInternal rev = GetDocumentWithIDAndRev(docId, null, EnumSet.NoneOf<Database.TDContentOptions >()); if (rev == null) { return null; } string outLanguage = (string)rev.GetPropertyForKey("language"); if (outLanguage != null) { outLanguageList.AddItem(outLanguage); } else { outLanguageList.AddItem("javascript"); } IDictionary<string, object> container = (IDictionary<string, object>)rev.GetPropertyForKey (key); return (string)container.Get(path[1]); }
/// <exception cref="System.IO.IOException"></exception> internal virtual void Compute(ProgressMonitor pm) { if (pm == null) { pm = NullProgressMonitor.INSTANCE; } pm.BeginTask(JGitText.Get().renamesFindingByContent, 2 * srcs.Count * dsts.Count); // int mNext = BuildMatrix(pm); @out = new AList<DiffEntry>(Math.Min(mNext, dsts.Count)); // Match rename pairs on a first come, first serve basis until // we have looked at everything that is above our minimum score. // for (--mNext; mNext >= 0; mNext--) { long ent = matrix[mNext]; int sIdx = SrcFile(ent); int dIdx = DstFile(ent); DiffEntry s = srcs[sIdx]; DiffEntry d = dsts[dIdx]; if (d == null) { pm.Update(1); continue; } // was already matched earlier DiffEntry.ChangeType type; if (s.changeType == DiffEntry.ChangeType.DELETE) { // First use of this source file. Tag it as a rename so we // later know it is already been used as a rename, other // matches (if any) will claim themselves as copies instead. // s.changeType = DiffEntry.ChangeType.RENAME; type = DiffEntry.ChangeType.RENAME; } else { type = DiffEntry.ChangeType.COPY; } @out.AddItem(DiffEntry.Pair(type, s, d, Score(ent))); dsts.Set(dIdx, null); // Claim the destination was matched. pm.Update(1); } srcs = CompactSrcList(srcs); dsts = CompactDstList(dsts); pm.EndTask(); }
/// <exception cref="NGit.Errors.InvalidPatternException"></exception> internal GroupHead(string pattern, string wholePattern) : base(false) { this.characterClasses = new AList<GroupHead.CharacterPattern>(); this.inverse = pattern.StartsWith("!"); if (inverse) { pattern = Sharpen.Runtime.Substring(pattern, 1); } Matcher matcher = REGEX_PATTERN.Matcher(pattern); while (matcher.Find()) { string characterClass = matcher.Group(0); if (characterClass.Length == 3 && characterClass[1] == '-') { char start = characterClass[0]; char end = characterClass[2]; characterClasses.AddItem(new GroupHead.CharacterRange(start, end)); } else { if (characterClass.Equals("[:alnum:]")) { characterClasses.AddItem(GroupHead.LetterPattern.INSTANCE); characterClasses.AddItem(GroupHead.DigitPattern.INSTANCE); } else { if (characterClass.Equals("[:alpha:]")) { characterClasses.AddItem(GroupHead.LetterPattern.INSTANCE); } else { if (characterClass.Equals("[:blank:]")) { characterClasses.AddItem(new GroupHead.OneCharacterPattern(' ')); characterClasses.AddItem(new GroupHead.OneCharacterPattern('\t')); } else { if (characterClass.Equals("[:cntrl:]")) { characterClasses.AddItem(new GroupHead.CharacterRange('\u0000', '\u001F')); characterClasses.AddItem(new GroupHead.OneCharacterPattern('\u007F')); } else { if (characterClass.Equals("[:digit:]")) { characterClasses.AddItem(GroupHead.DigitPattern.INSTANCE); } else { if (characterClass.Equals("[:graph:]")) { characterClasses.AddItem(new GroupHead.CharacterRange('\u0021', '\u007E')); characterClasses.AddItem(GroupHead.LetterPattern.INSTANCE); characterClasses.AddItem(GroupHead.DigitPattern.INSTANCE); } else { if (characterClass.Equals("[:lower:]")) { characterClasses.AddItem(GroupHead.LowerPattern.INSTANCE); } else { if (characterClass.Equals("[:print:]")) { characterClasses.AddItem(new GroupHead.CharacterRange('\u0020', '\u007E')); characterClasses.AddItem(GroupHead.LetterPattern.INSTANCE); characterClasses.AddItem(GroupHead.DigitPattern.INSTANCE); } else { if (characterClass.Equals("[:punct:]")) { characterClasses.AddItem(GroupHead.PunctPattern.INSTANCE); } else { if (characterClass.Equals("[:space:]")) { characterClasses.AddItem(GroupHead.WhitespacePattern.INSTANCE); } else { if (characterClass.Equals("[:upper:]")) { characterClasses.AddItem(GroupHead.UpperPattern.INSTANCE); } else { if (characterClass.Equals("[:xdigit:]")) { characterClasses.AddItem(new GroupHead.CharacterRange('0', '9')); characterClasses.AddItem(new GroupHead.CharacterRange('a', 'f')); characterClasses.AddItem(new GroupHead.CharacterRange('A', 'F')); } else { if (characterClass.Equals("[:word:]")) { characterClasses.AddItem(new GroupHead.OneCharacterPattern('_')); characterClasses.AddItem(GroupHead.LetterPattern.INSTANCE); characterClasses.AddItem(GroupHead.DigitPattern.INSTANCE); } else { string message = string.Format(MessageFormat.Format(JGitText.Get().characterClassIsNotSupported , characterClass)); throw new InvalidPatternException(message, wholePattern); } } } } } } } } } } } } } } pattern = matcher.ReplaceFirst(string.Empty); matcher.Reset(pattern); } // pattern contains now no ranges for (int i = 0; i < pattern.Length; i++) { char c = pattern[i]; characterClasses.AddItem(new GroupHead.OneCharacterPattern(c)); } }
/// <summary>Parse a remote block from an existing configuration file.</summary> /// <remarks> /// Parse a remote block from an existing configuration file. /// <p> /// This constructor succeeds even if the requested remote is not defined /// within the supplied configuration file. If that occurs then there will be /// no URIs and no ref specifications known to the new instance. /// </remarks> /// <param name="rc"> /// the existing configuration to get the remote settings from. /// The configuration must already be loaded into memory. /// </param> /// <param name="remoteName">subsection key indicating the name of this remote.</param> /// <exception cref="Sharpen.URISyntaxException">one of the URIs within the remote's configuration is invalid. /// </exception> public RemoteConfig(Config rc, string remoteName) { name = remoteName; oldName = remoteName; string[] vlst; string val; vlst = rc.GetStringList(SECTION, name, KEY_URL); IDictionary<string, string> insteadOf = GetReplacements(rc, KEY_INSTEADOF); uris = new AList<URIish>(vlst.Length); foreach (string s in vlst) { uris.AddItem(new URIish(ReplaceUri(s, insteadOf))); } IDictionary<string, string> pushInsteadOf = GetReplacements(rc, KEY_PUSHINSTEADOF ); vlst = rc.GetStringList(SECTION, name, KEY_PUSHURL); pushURIs = new AList<URIish>(vlst.Length); foreach (string s_1 in vlst) { pushURIs.AddItem(new URIish(ReplaceUri(s_1, pushInsteadOf))); } vlst = rc.GetStringList(SECTION, name, KEY_FETCH); fetch = new AList<RefSpec>(vlst.Length); foreach (string s_2 in vlst) { fetch.AddItem(new RefSpec(s_2)); } vlst = rc.GetStringList(SECTION, name, KEY_PUSH); push = new AList<RefSpec>(vlst.Length); foreach (string s_3 in vlst) { push.AddItem(new RefSpec(s_3)); } val = rc.GetString(SECTION, name, KEY_UPLOADPACK); if (val == null) { val = DEFAULT_UPLOAD_PACK; } uploadpack = val; val = rc.GetString(SECTION, name, KEY_RECEIVEPACK); if (val == null) { val = DEFAULT_RECEIVE_PACK; } receivepack = val; val = rc.GetString(SECTION, name, KEY_TAGOPT); tagopt = NGit.Transport.TagOpt.FromOption(val); mirror = rc.GetBoolean(SECTION, name, KEY_MIRROR, DEFAULT_MIRROR); timeout = rc.GetInt(SECTION, name, KEY_TIMEOUT, 0); }
public virtual IList<string> GetChangedKeys() { if (changedKeys == null) { changedKeys = new AList<string>(); IDictionary<string, object> cur = GetCurrentRevision().GetProperties(); IDictionary<string, object> nuu = newRev.GetProperties(); foreach (string key in cur.Keys) { if (!cur.Get(key).Equals(nuu.Get(key)) && !key.Equals("_rev")) { changedKeys.AddItem(key); } } foreach (string key_1 in nuu.Keys) { if (cur.Get(key_1) == null && !key_1.Equals("_rev") && !key_1.Equals("_id")) { changedKeys.AddItem(key_1); } } } return changedKeys; }