Пример #1
0
        private InMemoryNoteBucket Parse()
        {
            InMemoryNoteBucket r = ParseTree();

            r.nonNotes = firstNonNote;
            return(r);
        }
 /// <summary>Construct a new note map from an existing note bucket.</summary>
 /// <remarks>Construct a new note map from an existing note bucket.</remarks>
 /// <param name="root">the root bucket of this note map</param>
 /// <param name="reader">
 /// reader to scan the note branch with. This reader may be
 /// retained by the NoteMap for the life of the map in order to
 /// support lazy loading of entries.
 /// </param>
 /// <returns>the note map built from the note bucket</returns>
 internal static NGit.Notes.NoteMap NewMap(InMemoryNoteBucket root, ObjectReader reader
                                           )
 {
     NGit.Notes.NoteMap map = new NGit.Notes.NoteMap(reader);
     map.root = root;
     return(map);
 }
Пример #3
0
            /// <exception cref="System.IO.IOException"></exception>
            internal InMemoryNoteBucket Load(AnyObjectId prefix, ObjectReader or)
            {
                AbbreviatedObjectId p    = prefix.Abbreviate(this._enclosing.prefixLen + 2);
                InMemoryNoteBucket  self = NoteParser.Parse(p, this.treeId, or);

                this._enclosing.table[this._enclosing.Cell(prefix)] = self;
                return(self);
            }
        /// <summary>Attach (or remove) a note on an object.</summary>
        /// <remarks>
        /// Attach (or remove) a note on an object.
        /// If no note exists, a new note is stored. If a note already exists for the
        /// given object, it is replaced (or removed).
        /// This method only updates the map in memory.
        /// If the caller wants to attach a UTF-8 encoded string message to an
        /// object,
        /// <see cref="Set(NGit.AnyObjectId, string, NGit.ObjectInserter)">Set(NGit.AnyObjectId, string, NGit.ObjectInserter)
        ///     </see>
        /// is a convenient
        /// way to encode and update a note in one step.
        /// </remarks>
        /// <param name="noteOn">
        /// the object to attach the note to. This same ObjectId can later
        /// be used as an argument to
        /// <see cref="Get(NGit.AnyObjectId)">Get(NGit.AnyObjectId)</see>
        /// or
        /// <see cref="GetCachedBytes(NGit.AnyObjectId, int)">GetCachedBytes(NGit.AnyObjectId, int)
        ///     </see>
        /// to read back the
        /// <code>noteData</code>
        /// .
        /// </param>
        /// <param name="noteData">
        /// data to associate with the note. This must be the ObjectId of
        /// a blob that already exists in the repository. If null the note
        /// will be deleted, if present.
        /// </param>
        /// <exception cref="System.IO.IOException">a portion of the note space is not accessible.
        ///     </exception>
        public virtual void Set(AnyObjectId noteOn, ObjectId noteData)
        {
            InMemoryNoteBucket newRoot = root.Set(noteOn, noteData, reader);

            if (newRoot == null)
            {
                newRoot          = new LeafBucket(0);
                newRoot.nonNotes = root.nonNotes;
            }
            root = newRoot;
        }
Пример #5
0
 private FanoutBucket AsFanout(InMemoryNoteBucket bucket)
 {
     if (bucket == null)
     {
         return(EMPTY_FANOUT);
     }
     if (bucket is FanoutBucket)
     {
         return((FanoutBucket)bucket);
     }
     return(((LeafBucket)bucket).Split());
 }
Пример #6
0
 private static InMemoryNoteBucket AddIfNotNull(InMemoryNoteBucket result, Note note
                                                )
 {
     if (note != null)
     {
         return(result.Append(note));
     }
     else
     {
         return(result);
     }
 }
Пример #7
0
 /// <summary>Performs the merge.</summary>
 /// <remarks>Performs the merge.</remarks>
 /// <param name="base">base version of the note tree</param>
 /// <param name="ours">ours version of the note tree</param>
 /// <param name="theirs">theirs version of the note tree</param>
 /// <returns>merge result as a new NoteMap</returns>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual NoteMap Merge(NoteMap @base, NoteMap ours, NoteMap theirs)
 {
     try
     {
         InMemoryNoteBucket mergedBucket = Merge(0, @base.GetRoot(), ours.GetRoot(), theirs
                                                 .GetRoot());
         inserter.Flush();
         return(NoteMap.NewMap(mergedBucket, reader));
     }
     finally
     {
         reader.Release();
         inserter.Release();
     }
 }
Пример #8
0
        /// <summary>
        /// This method is called only when it is known that there is some difference
        /// between base, ours and theirs.
        /// </summary>
        /// <remarks>
        /// This method is called only when it is known that there is some difference
        /// between base, ours and theirs.
        /// </remarks>
        /// <param name="treeDepth"></param>
        /// <param name="base"></param>
        /// <param name="ours"></param>
        /// <param name="theirs"></param>
        /// <returns>merge result as an InMemoryBucket</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        private InMemoryNoteBucket Merge(int treeDepth, InMemoryNoteBucket @base, InMemoryNoteBucket
                                         ours, InMemoryNoteBucket theirs)
        {
            InMemoryNoteBucket result;

            if (@base is FanoutBucket || ours is FanoutBucket || theirs is FanoutBucket)
            {
                result = MergeFanoutBucket(treeDepth, AsFanout(@base), AsFanout(ours), AsFanout(theirs
                                                                                                ));
            }
            else
            {
                result = MergeLeafBucket(treeDepth, (LeafBucket)@base, (LeafBucket)ours, (LeafBucket
                                                                                          )theirs);
            }
            result.nonNotes = MergeNonNotes(NonNotes(@base), NonNotes(ours), NonNotes(theirs)
                                            );
            return(result);
        }
Пример #9
0
        internal override InMemoryNoteBucket Append(Note note)
        {
            int cell             = Cell(note);
            InMemoryNoteBucket b = (InMemoryNoteBucket)table[cell];

            if (b == null)
            {
                LeafBucket n = new LeafBucket(prefixLen + 2);
                table[cell] = n.Append(note);
                cnt++;
            }
            else
            {
                InMemoryNoteBucket n = b.Append(note);
                if (n != b)
                {
                    table[cell] = n;
                }
            }
            return(this);
        }
Пример #10
0
        /// <exception cref="System.IO.IOException"></exception>
        private InMemoryNoteBucket MergeFanoutBucket(int treeDepth, FanoutBucket @base, FanoutBucket
                                                     ours, FanoutBucket theirs)
        {
            FanoutBucket result = new FanoutBucket(treeDepth * 2);

            // walking through entries of base, ours, theirs
            for (int i = 0; i < 256; i++)
            {
                NoteBucket b = @base.GetBucket(i);
                NoteBucket o = ours.GetBucket(i);
                NoteBucket t = theirs.GetBucket(i);
                if (Equals(o, t))
                {
                    AddIfNotNull(result, i, o);
                }
                else
                {
                    if (Equals(b, o))
                    {
                        AddIfNotNull(result, i, t);
                    }
                    else
                    {
                        if (Equals(b, t))
                        {
                            AddIfNotNull(result, i, o);
                        }
                        else
                        {
                            objectIdPrefix.SetByte(treeDepth, i);
                            InMemoryNoteBucket mergedBucket = Merge(treeDepth + 1, FanoutBucket.LoadIfLazy(b,
                                                                                                           objectIdPrefix, reader), FanoutBucket.LoadIfLazy(o, objectIdPrefix, reader), FanoutBucket
                                                                    .LoadIfLazy(t, objectIdPrefix, reader));
                            result.SetBucket(i, mergedBucket);
                        }
                    }
                }
            }
            return(result.ContractIfTooSmall(objectIdPrefix, reader));
        }
Пример #11
0
		/// <summary>Attach (or remove) a note on an object.</summary>
		/// <remarks>
		/// Attach (or remove) a note on an object.
		/// If no note exists, a new note is stored. If a note already exists for the
		/// given object, it is replaced (or removed).
		/// This method only updates the map in memory.
		/// If the caller wants to attach a UTF-8 encoded string message to an
		/// object,
		/// <see cref="Set(NGit.AnyObjectId, string, NGit.ObjectInserter)">Set(NGit.AnyObjectId, string, NGit.ObjectInserter)
		/// 	</see>
		/// is a convenient
		/// way to encode and update a note in one step.
		/// </remarks>
		/// <param name="noteOn">
		/// the object to attach the note to. This same ObjectId can later
		/// be used as an argument to
		/// <see cref="Get(NGit.AnyObjectId)">Get(NGit.AnyObjectId)</see>
		/// or
		/// <see cref="GetCachedBytes(NGit.AnyObjectId, int)">GetCachedBytes(NGit.AnyObjectId, int)
		/// 	</see>
		/// to read back the
		/// <code>noteData</code>
		/// .
		/// </param>
		/// <param name="noteData">
		/// data to associate with the note. This must be the ObjectId of
		/// a blob that already exists in the repository. If null the note
		/// will be deleted, if present.
		/// </param>
		/// <exception cref="System.IO.IOException">a portion of the note space is not accessible.
		/// 	</exception>
		public virtual void Set(AnyObjectId noteOn, ObjectId noteData)
		{
			InMemoryNoteBucket newRoot = root.Set(noteOn, noteData, reader);
			if (newRoot == null)
			{
				newRoot = new LeafBucket(0);
				newRoot.nonNotes = root.nonNotes;
			}
			root = newRoot;
		}
Пример #12
0
 private static NonNoteEntry NonNotes(InMemoryNoteBucket b)
 {
     return(b == null ? null : b.nonNotes);
 }
Пример #13
0
		private static InMemoryNoteBucket AddIfNotNull(InMemoryNoteBucket result, Note note
			)
		{
			if (note != null)
			{
				return result.Append(note);
			}
			else
			{
				return result;
			}
		}
Пример #14
0
		private static NonNoteEntry NonNotes(InMemoryNoteBucket b)
		{
			return b == null ? null : b.nonNotes;
		}
Пример #15
0
		private FanoutBucket AsFanout(InMemoryNoteBucket bucket)
		{
			if (bucket == null)
			{
				return EMPTY_FANOUT;
			}
			if (bucket is FanoutBucket)
			{
				return (FanoutBucket)bucket;
			}
			return ((LeafBucket)bucket).Split();
		}
Пример #16
0
		/// <summary>
		/// This method is called only when it is known that there is some difference
		/// between base, ours and theirs.
		/// </summary>
		/// <remarks>
		/// This method is called only when it is known that there is some difference
		/// between base, ours and theirs.
		/// </remarks>
		/// <param name="treeDepth"></param>
		/// <param name="base"></param>
		/// <param name="ours"></param>
		/// <param name="theirs"></param>
		/// <returns>merge result as an InMemoryBucket</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		private InMemoryNoteBucket Merge(int treeDepth, InMemoryNoteBucket @base, InMemoryNoteBucket
			 ours, InMemoryNoteBucket theirs)
		{
			InMemoryNoteBucket result;
			if (@base is FanoutBucket || ours is FanoutBucket || theirs is FanoutBucket)
			{
				result = MergeFanoutBucket(treeDepth, AsFanout(@base), AsFanout(ours), AsFanout(theirs
					));
			}
			else
			{
				result = MergeLeafBucket(treeDepth, (LeafBucket)@base, (LeafBucket)ours, (LeafBucket
					)theirs);
			}
			result.nonNotes = MergeNonNotes(NonNotes(@base), NonNotes(ours), NonNotes(theirs)
				);
			return result;
		}
Пример #17
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="NGit.Errors.CorruptObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void Load(ObjectId rootTree)
		{
			AbbreviatedObjectId none = AbbreviatedObjectId.FromString(string.Empty);
			root = NoteParser.Parse(none, rootTree, reader);
		}
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void Load(ObjectId rootTree)
        {
            AbbreviatedObjectId none = AbbreviatedObjectId.FromString(string.Empty);

            root = NoteParser.Parse(none, rootTree, reader);
        }
Пример #19
0
 internal virtual void SetBucket(int cell, InMemoryNoteBucket bucket)
 {
     table[cell] = bucket;
     cnt++;
 }