/// <summary>Construct a MissingObjectException for the specified object id.</summary>
		/// <remarks>
		/// Construct a MissingObjectException for the specified object id. Expected
		/// type is reported to simplify tracking down the problem.
		/// </remarks>
		/// <param name="id">SHA-1</param>
		/// <param name="candidates">the candidate matches returned by the ObjectReader.</param>
		public AmbiguousObjectException(AbbreviatedObjectId id, ICollection<ObjectId> candidates
			) : base(MessageFormat.Format(JGitText.Get().ambiguousObjectAbbreviation, id.Name
			))
		{
			this.missing = id;
			this.candidates = candidates;
		}
Esempio n. 2
0
		/// <exception cref="System.IO.IOException"></exception>
		public override ICollection<ObjectId> Resolve(AbbreviatedObjectId id)
		{
			if (id.IsComplete)
			{
				return Sharpen.Collections.Singleton(id.ToObjectId());
			}
			HashSet<ObjectId> matches = new HashSet<ObjectId>();
			db.Resolve(matches, id);
			return matches;
		}
		/// <summary>Construct a MissingObjectException for the specified object id.</summary>
		/// <remarks>
		/// Construct a MissingObjectException for the specified object id. Expected
		/// type is reported to simplify tracking down the problem.
		/// </remarks>
		/// <param name="id">SHA-1</param>
		/// <param name="type">object type</param>
		public MissingObjectException(AbbreviatedObjectId id, int type) : base(MessageFormat
			.Format(JGitText.Get().missingObject, Constants.TypeString(type), id.Name))
		{
			missing = null;
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override void Resolve(ICollection<ObjectId> matches, AbbreviatedObjectId
			 id)
		{
			// In theory we could accelerate the loose object scan using our
			// unpackedObjects map, but its not worth the huge code complexity.
			// Scanning a single loose directory is fast enough, and this is
			// unlikely to be called anyway.
			//
			wrapped.Resolve(matches, id);
		}
Esempio n. 5
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void Resolve(ICollection<ObjectId> matches, AbbreviatedObjectId id
			, int matchLimit)
		{
			int[] data = names[id.FirstByte];
			int max = (int)(((uint)offset32[id.FirstByte].Length) >> 2);
			int high = max;
			if (high == 0)
			{
				return;
			}
			int low = 0;
			do
			{
				int p = (int)(((uint)(low + high)) >> 1);
				int cmp = id.PrefixCompare(data, IdOffset(p));
				if (cmp < 0)
				{
					high = p;
				}
				else
				{
					if (cmp == 0)
					{
						// We may have landed in the middle of the matches.  Move
						// backwards to the start of matches, then walk forwards.
						//
						while (0 < p && id.PrefixCompare(data, IdOffset(p - 1)) == 0)
						{
							p--;
						}
						for (; p < max && id.PrefixCompare(data, IdOffset(p)) == 0; p++)
						{
							matches.AddItem(ObjectId.FromRaw(data, IdOffset(p)));
							if (matches.Count > matchLimit)
							{
								break;
							}
						}
						return;
					}
					else
					{
						low = p + 1;
					}
				}
			}
			while (low < high);
		}
Esempio n. 6
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override void Resolve(ICollection<ObjectId> matches, AbbreviatedObjectId
			 id)
		{
			// Go through the packs once. If we didn't find any resolutions
			// scan for new packs and check once more.
			//
			int oldSize = matches.Count;
			ObjectDirectory.PackList pList = packList.Get();
			for (; ; )
			{
				foreach (PackFile p in pList.packs)
				{
					try
					{
						p.Resolve(matches, id, RESOLVE_ABBREV_LIMIT);
					}
					catch (IOException)
					{
						// Assume the pack is corrupted.
						//
						RemovePack(p);
					}
					if (matches.Count > RESOLVE_ABBREV_LIMIT)
					{
						return;
					}
				}
				if (matches.Count == oldSize)
				{
					ObjectDirectory.PackList nList = ScanPacks(pList);
					if (nList == pList || nList.packs.Length == 0)
					{
						break;
					}
					pList = nList;
					continue;
				}
				break;
			}
			string fanOut = Sharpen.Runtime.Substring(id.Name, 0, 2);
			string[] entries = new FilePath(GetDirectory(), fanOut).List();
			if (entries != null)
			{
				foreach (string e in entries)
				{
					if (e.Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
					{
						continue;
					}
					try
					{
						ObjectId entId = ObjectId.FromString(fanOut + e);
						if (id.PrefixCompare(entId) == 0)
						{
							matches.AddItem(entId);
						}
					}
					catch (ArgumentException)
					{
						continue;
					}
					if (matches.Count > RESOLVE_ABBREV_LIMIT)
					{
						return;
					}
				}
			}
			foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
			{
				alt.db.Resolve(matches, id);
				if (matches.Count > RESOLVE_ABBREV_LIMIT)
				{
					return;
				}
			}
		}
Esempio n. 7
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract void Resolve(ICollection<ObjectId> matches, AbbreviatedObjectId
			 id);
Esempio n. 8
0
		/// <summary>
		/// Parse a tree object into a
		/// <see cref="NoteBucket">NoteBucket</see>
		/// instance.
		/// The type of note tree is automatically detected by examining the items
		/// within the tree, and allocating the proper storage type based on the
		/// first note-like entry encountered. Since the method parses by guessing
		/// the type on the first element, malformed note trees can be read as the
		/// wrong type of tree.
		/// This method is not recursive, it parses the one tree given to it and
		/// returns the bucket. If there are subtrees for note storage, they are
		/// setup as lazy pointers that will be resolved at a later time.
		/// </summary>
		/// <param name="prefix">
		/// common hex digits that all notes within this tree share. The
		/// root tree has
		/// <code>prefix.length() == 0</code>
		/// , the first-level
		/// subtrees should be
		/// <code>prefix.length()==2</code>
		/// , etc.
		/// </param>
		/// <param name="treeId">the tree to read from the repository.</param>
		/// <param name="reader">reader to access the tree object.</param>
		/// <returns>bucket to holding the notes of the specified tree.</returns>
		/// <exception cref="System.IO.IOException">
		/// <code>treeId</code>
		/// cannot be accessed.
		/// </exception>
		internal static InMemoryNoteBucket Parse(AbbreviatedObjectId prefix, ObjectId treeId
			, ObjectReader reader)
		{
			return new NGit.Notes.NoteParser(prefix, reader, treeId).Parse();
		}
Esempio n. 9
0
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private NoteParser(AbbreviatedObjectId p, ObjectReader r, ObjectId t) : base(Constants.EncodeASCII
			(p.Name), r, t)
		{
			prefix = p;
			// Our path buffer has a '/' that we don't want after the prefix.
			// Drop it by shifting the path down one position.
			pathPadding = 0 < prefix.Length ? 1 : 0;
			if (0 < pathPadding)
			{
				System.Array.Copy(path, 0, path, pathPadding, prefix.Length);
			}
		}
Esempio n. 10
0
 /// <summary>Tests if this ObjectId starts with the given abbreviation.</summary>
 /// <remarks>Tests if this ObjectId starts with the given abbreviation.</remarks>
 /// <param name="abbr">the abbreviation.</param>
 /// <returns>true if this ObjectId begins with the abbreviation; else false.</returns>
 public virtual bool StartsWith(AbbreviatedObjectId abbr)
 {
     return abbr.PrefixCompare(this) == 0;
 }