Beispiel #1
0
			internal Entry(byte[] raw, int pos)
			{
				oldId = ObjectId.FromString(raw, pos);
				pos += Constants.OBJECT_ID_STRING_LENGTH;
				if (raw[pos++] != ' ')
				{
					throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
				}
				newId = ObjectId.FromString(raw, pos);
				pos += Constants.OBJECT_ID_STRING_LENGTH;
				if (raw[pos++] != ' ')
				{
					throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
				}
				who = RawParseUtils.ParsePersonIdentOnly(raw, pos);
				int p0 = RawParseUtils.Next(raw, pos, '\t');
				if (p0 >= raw.Length)
				{
					comment = string.Empty;
				}
				else
				{
					// personident has no \t, no comment present
					int p1 = RawParseUtils.NextLF(raw, p0);
					comment = p1 > p0 ? RawParseUtils.Decode(raw, p0, p1 - 1) : string.Empty;
				}
			}
Beispiel #2
0
		/// <summary>Create submodule status</summary>
		/// <param name="type"></param>
		/// <param name="path"></param>
		/// <param name="indexId"></param>
		/// <param name="headId"></param>
		public SubmoduleStatus(SubmoduleStatusType type, string path, ObjectId indexId, ObjectId
			 headId)
		{
			this.type = type;
			this.path = path;
			this.indexId = indexId;
			this.headId = headId;
		}
Beispiel #3
0
        internal TrackingRefUpdate(bool canForceUpdate, string remoteName, string localName
			, AnyObjectId oldValue, AnyObjectId newValue)
        {
            this.remoteName = remoteName;
            this.localName = localName;
            this.forceUpdate = canForceUpdate;
            this.oldObjectId = oldValue.Copy();
            this.newObjectId = newValue.Copy();
        }
		internal static LocalObjectRepresentation NewDelta(PackFile f, long p, long n, ObjectId
			 @base)
		{
			LocalObjectRepresentation r = new LocalObjectRepresentation.Delta();
			r.pack = f;
			r.offset = p;
			r.length = n;
			r.baseId = @base;
			return r;
		}
		/// <exception cref="System.InvalidOperationException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void PrescanTwoTrees(ObjectId head, ObjectId merge)
		{
			DirCache dc = db.LockDirCache();
			try
			{
				dco = new DirCacheCheckout(db, head, dc, merge);
				dco.PreScanTwoTrees();
			}
			finally
			{
				dc.Unlock();
			}
		}
Beispiel #6
0
		private static InputStream Inflate(InputStream @in, long size, ObjectId id)
		{
			Inflater inf = InflaterCache.Get();
			return new _InflaterInputStream_307(size, id, @in, inf);
		}
Beispiel #7
0
        //
        //
        //
        private string MakeDiffHeaderModeChange(string pathA, string pathB, ObjectId aId, 
			ObjectId bId, string modeA, string modeB)
        {
            string a = aId.Abbreviate(8).Name;
            string b = bId.Abbreviate(8).Name;
            return DIFF + "a/" + pathA + " " + "b/" + pathB + "\n" + "old mode " + modeA + "\n"
                 + "new mode " + modeB + "\n" + "index " + a + ".." + b + "\n" + "--- a/" + pathA
                 + "\n" + "+++ b/" + pathB + "\n";
        }
Beispiel #8
0
        private string MakeDiffHeader(string pathA, string pathB, ObjectId aId, ObjectId 
			bId)
        {
            string a = aId.Abbreviate(8).Name;
            string b = bId.Abbreviate(8).Name;
            return DIFF + "a/" + pathA + " " + "b/" + pathB + "\n" + "index " + a + ".." + b
                + " " + REGULAR_FILE + "\n" + "--- a/" + pathA + "\n" + "+++ b/" + pathB + "\n";
        }
Beispiel #9
0
		/// <summary>
		/// Create a new command for
		/// <see cref="BaseReceivePack">BaseReceivePack</see>
		/// .
		/// </summary>
		/// <param name="oldId">
		/// the old object id; must not be null. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// to indicate a ref creation.
		/// </param>
		/// <param name="newId">
		/// the new object id; must not be null. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// to indicate a ref deletion.
		/// </param>
		/// <param name="name">name of the ref being affected.</param>
		/// <param name="type">type of the command.</param>
		/// <since>2.0</since>
		public ReceiveCommand(ObjectId oldId, ObjectId newId, string name, ReceiveCommand.Type
			 type)
		{
			this.oldId = oldId;
			this.newId = newId;
			this.name = name;
			this.type = type;
		}
Beispiel #10
0
		public RevisionObjectIdPair(RevCommit revision, ObjectId objectId)
		{
			this.Commit = revision;
			this.ObjectId = objectId;
		}
		/// <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;
		}
		/// <summary>Set the identity of the object, if its not already set.</summary>
		/// <remarks>Set the identity of the object, if its not already set.</remarks>
		/// <param name="id">the id of the object that is too large to process.</param>
		public virtual void SetObjectId(AnyObjectId id)
		{
			if (objectId == null)
			{
				objectId = id.Copy();
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		private static RawText GetRawText(ObjectId id, Repository db)
		{
			if (id.Equals(ObjectId.ZeroId))
			{
				return new RawText(new byte[] {  });
			}
			return new RawText(db.Open(id, Constants.OBJ_BLOB).GetCachedBytes());
		}
Beispiel #14
0
 /// <exception cref="NGit.Errors.StopWalkException"></exception>
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public override bool Include(RevWalk walker, RevCommit c)
 {
     // Reset the tree filter to scan this commit and parents.
     //
     RevCommit[] pList = c.parents;
     int nParents = pList.Length;
     TreeWalk tw = pathFilter;
     ObjectId[] trees = new ObjectId[nParents + 1];
     for (int i = 0; i < nParents; i++)
     {
         RevCommit p = c.parents[i];
         if ((p.flags & PARSED) == 0)
         {
             p.ParseHeaders(walker);
         }
         trees[i] = p.Tree;
     }
     trees[nParents] = c.Tree;
     tw.Reset(trees);
     if (nParents == 1)
     {
         // We have exactly one parent. This is a very common case.
         //
         int chgs = 0;
         int adds = 0;
         while (tw.Next())
         {
             chgs++;
             if (tw.GetRawMode(0) == 0 && tw.GetRawMode(1) != 0)
             {
                 adds++;
             }
             else
             {
                 break;
             }
         }
         // no point in looking at this further.
         if (chgs == 0)
         {
             // No changes, so our tree is effectively the same as
             // our parent tree. We pass the buck to our parent.
             //
             c.flags |= REWRITE;
             return false;
         }
         else
         {
             // We have interesting items, but neither of the special
             // cases denoted above.
             //
             if (adds > 0 && tw.Filter is FollowFilter)
             {
                 // One of the paths we care about was added in this
                 // commit. We need to update our filter to its older
                 // name, if we can discover it. Find out what that is.
                 //
                 UpdateFollowFilter(trees);
             }
             return true;
         }
     }
     else
     {
         if (nParents == 0)
         {
             // We have no parents to compare against. Consider us to be
             // REWRITE only if we have no paths matching our filter.
             //
             if (tw.Next())
             {
                 return true;
             }
             c.flags |= REWRITE;
             return false;
         }
     }
     // We are a merge commit. We can only be REWRITE if we are same
     // to _all_ parents. We may also be able to eliminate a parent if
     // it does not contribute changes to us. Such a parent may be an
     // uninteresting side branch.
     //
     int[] chgs_1 = new int[nParents];
     int[] adds_1 = new int[nParents];
     while (tw.Next())
     {
         int myMode = tw.GetRawMode(nParents);
         for (int i_1 = 0; i_1 < nParents; i_1++)
         {
             int pMode = tw.GetRawMode(i_1);
             if (myMode == pMode && tw.IdEqual(i_1, nParents))
             {
                 continue;
             }
             chgs_1[i_1]++;
             if (pMode == 0 && myMode != 0)
             {
                 adds_1[i_1]++;
             }
         }
     }
     bool same = false;
     bool diff = false;
     for (int i_2 = 0; i_2 < nParents; i_2++)
     {
         if (chgs_1[i_2] == 0)
         {
             // No changes, so our tree is effectively the same as
             // this parent tree. We pass the buck to only this one
             // parent commit.
             //
             RevCommit p = pList[i_2];
             if ((p.flags & UNINTERESTING) != 0)
             {
                 // This parent was marked as not interesting by the
                 // application. We should look for another parent
                 // that is interesting.
                 //
                 same = true;
                 continue;
             }
             c.flags |= REWRITE;
             c.parents = new RevCommit[] { p };
             return false;
         }
         if (chgs_1[i_2] == adds_1[i_2])
         {
             // All of the differences from this parent were because we
             // added files that they did not have. This parent is our
             // "empty tree root" and thus their history is not relevant.
             // Cut our grandparents to be an empty list.
             //
             pList[i_2].parents = RevCommit.NO_PARENTS;
         }
         // We have an interesting difference relative to this parent.
         //
         diff = true;
     }
     if (diff && !same)
     {
         // We did not abort above, so we are different in at least one
         // way from all of our parents. We have to take the blame for
         // that difference.
         //
         return true;
     }
     // We are the same as all of our parents. We must keep them
     // as they are and allow those parents to flow into pending
     // for further scanning.
     //
     c.flags |= REWRITE;
     return false;
 }
Beispiel #15
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 UpdateFollowFilter(ObjectId[] trees)
 {
     TreeWalk tw = pathFilter;
     FollowFilter oldFilter = (FollowFilter)tw.Filter;
     tw.Filter = TreeFilter.ANY_DIFF;
     tw.Reset(trees);
     IList<DiffEntry> files = DiffEntry.Scan(tw);
     RenameDetector rd = new RenameDetector(repository);
     rd.AddAll(files);
     files = rd.Compute();
     TreeFilter newFilter = oldFilter;
     foreach (DiffEntry ent in files)
     {
         if (IsRename(ent) && ent.GetNewPath().Equals(oldFilter.GetPath()))
         {
             newFilter = FollowFilter.Create(ent.GetOldPath());
             RenameCallback callback = oldFilter.GetRenameCallback();
             if (callback != null)
             {
                 callback.Renamed(ent);
                 // forward the callback to the new follow filter
                 ((FollowFilter)newFilter).SetRenameCallback(callback);
             }
             break;
         }
     }
     tw.Filter = newFilter;
 }
Beispiel #16
0
 /// <exception cref="System.IO.IOException"></exception>
 private void CreateBranch(ObjectId objectId, string branchName)
 {
     RefUpdate updateRef = db.UpdateRef(branchName);
     updateRef.SetNewObjectId(objectId);
     updateRef.Update();
 }
		/// <exception cref="System.IO.IOException"></exception>
		internal override FileObjectDatabase.InsertLooseObjectResult InsertUnpackedObject
			(FilePath tmp, ObjectId objectId, bool createDuplicate)
		{
			FileObjectDatabase.InsertLooseObjectResult result = wrapped.InsertUnpackedObject(
				tmp, objectId, createDuplicate);
			switch (result)
			{
				case FileObjectDatabase.InsertLooseObjectResult.INSERTED:
				case FileObjectDatabase.InsertLooseObjectResult.EXISTS_LOOSE:
				{
					if (!unpackedObjects.Contains(objectId))
					{
						unpackedObjects.Add(objectId);
					}
					break;
				}

				case FileObjectDatabase.InsertLooseObjectResult.EXISTS_PACKED:
				case FileObjectDatabase.InsertLooseObjectResult.FAILURE:
				{
					break;
				}
			}
			return result;
		}
		/// <exception cref="System.Exception"></exception>
		private static byte[] Entry(FileMode mode, string name, ObjectId id)
		{
			ByteArrayOutputStream @out = new ByteArrayOutputStream();
			mode.CopyTo(@out);
			@out.Write(' ');
			@out.Write(Constants.Encode(name));
			@out.Write(0);
			id.CopyRawTo(@out);
			return @out.ToByteArray();
		}
Beispiel #19
0
			public _InflaterInputStream_307(long size, ObjectId id, InputStream baseArg1, Inflater
				 baseArg2) : base(baseArg1, baseArg2)
			{
				this.size = size;
				this.id = id;
				this.remaining = size;
			}
		/// <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(ObjectId id, string type) : base(MessageFormat.Format
			(JGitText.Get().missingObject, type, id.Name))
		{
			missing = id.Copy();
		}
Beispiel #21
0
			internal LargeObject(int type, long size, FilePath path, AnyObjectId id, FileObjectDatabase
				 db)
			{
				this.type = type;
				this.size = size;
				this.path = path;
				this.id = id.Copy();
				this.source = db;
			}
Beispiel #22
0
		public static void HardReset (NGit.Repository repo, ObjectId newHead)
		{
			DirCache dc = null;
			
			try {
				// Reset head to upstream
				RefUpdate ru = repo.UpdateRef (Constants.HEAD);
				ru.SetNewObjectId (newHead);
				ru.SetForceUpdate (true);
				RefUpdate.Result rc = ru.Update ();
	
				switch (rc) {
				case RefUpdate.Result.NO_CHANGE:
				case RefUpdate.Result.NEW:
				case RefUpdate.Result.FAST_FORWARD:
				case RefUpdate.Result.FORCED:
					break;
				
				case RefUpdate.Result.REJECTED:
				case RefUpdate.Result.LOCK_FAILURE:
					throw new ConcurrentRefUpdateException (JGitText.Get ().couldNotLockHEAD, ru.GetRef (), rc);
	
				default:
					throw new JGitInternalException ("Reference update failed: " + rc);
				}
				
				dc = repo.LockDirCache ();
				RevWalk rw = new RevWalk (repo);
				RevCommit c = rw.ParseCommit (newHead);
				DirCacheCheckout checkout = new DirCacheCheckout (repo, null, dc, c.Tree);
				checkout.Checkout ();
			} catch {
				if (dc != null)
					dc.Unlock ();
				throw;
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override bool MergeImpl()
		{
			bool implicitDirCache = false;
			if (dircache == null)
			{
				dircache = GetRepository().LockDirCache();
				implicitDirCache = true;
			}
			try
			{
				builder = dircache.Builder();
				DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
				tw = new NameConflictTreeWalk(db);
				tw.AddTree(MergeBase());
				tw.AddTree(sourceTrees[0]);
				tw.AddTree(sourceTrees[1]);
				tw.AddTree(buildIt);
				if (workingTreeIterator != null)
				{
					tw.AddTree(workingTreeIterator);
				}
				while (tw.Next())
				{
					if (!ProcessEntry(tw.GetTree<CanonicalTreeParser>(T_BASE), tw.GetTree<CanonicalTreeParser
						>(T_OURS), tw.GetTree<CanonicalTreeParser>(T_THEIRS), tw.GetTree<DirCacheBuildIterator
						>(T_INDEX), (workingTreeIterator == null) ? null : tw.GetTree<WorkingTreeIterator
						>(T_FILE)))
					{
						CleanUp();
						return false;
					}
					if (tw.IsSubtree && enterSubtree)
					{
						tw.EnterSubtree();
					}
				}
				if (!inCore)
				{
					// All content-merges are successfully done. If we can now write the
					// new index we are on quite safe ground. Even if the checkout of
					// files coming from "theirs" fails the user can work around such
					// failures by checking out the index again.
					if (!builder.Commit())
					{
						CleanUp();
						throw new IndexWriteException();
					}
					builder = null;
					// No problem found. The only thing left to be done is to checkout
					// all files from "theirs" which have been selected to go into the
					// new index.
					Checkout();
				}
				else
				{
					builder.Finish();
					builder = null;
				}
				if (GetUnmergedPaths().IsEmpty())
				{
					resultTree = dircache.WriteTree(oi);
					return true;
				}
				else
				{
					resultTree = null;
					return false;
				}
			}
			finally
			{
				if (implicitDirCache)
				{
					dircache.Unlock();
				}
			}
		}
Beispiel #24
0
 /// <summary>Write an ObjectId and LF to the temporary file.</summary>
 /// <remarks>Write an ObjectId and LF to the temporary file.</remarks>
 /// <param name="id">
 /// the id to store in the file. The id will be written in hex,
 /// followed by a sole LF.
 /// </param>
 /// <exception cref="System.IO.IOException">
 /// the temporary file could not be written. The lock is released
 /// before throwing the underlying IO exception to the caller.
 /// </exception>
 /// <exception cref="Sharpen.RuntimeException">
 /// the temporary file could not be written. The lock is released
 /// before throwing the underlying exception to the caller.
 /// </exception>
 public virtual void Write(ObjectId id)
 {
     byte[] buf = new byte[Constants.OBJECT_ID_STRING_LENGTH + 1];
     id.CopyTo(buf, 0);
     buf[Constants.OBJECT_ID_STRING_LENGTH] = (byte)('\n');
     Write(buf);
 }
Beispiel #25
0
		/// <exception cref="System.IO.IOException"></exception>
		protected internal virtual void CreateBranch(ObjectId objectId, string branchName
			)
		{
			RefUpdate updateRef = db.UpdateRef(branchName);
			updateRef.SetNewObjectId(objectId);
			updateRef.Update();
		}
Beispiel #26
0
		/// <exception cref="System.IO.IOException"></exception>
		private void WriteReflog(Repository db, ObjectId newId, string msg, string refName
			)
		{
			RefDirectory refs = (RefDirectory)db.RefDatabase;
			RefDirectoryUpdate update = ((RefDirectoryUpdate)refs.NewUpdate(refName, true));
			update.SetNewObjectId(newId);
			refs.Log(update, msg, true);
		}
		/// <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(ObjectId id, int type) : this(id, Constants.TypeString
			(type))
		{
		}
Beispiel #28
0
		/// <summary>Construct a PackedObjectInfo instance for this parser.</summary>
		/// <remarks>Construct a PackedObjectInfo instance for this parser.</remarks>
		/// <param name="id">identity of the object to be tracked.</param>
		/// <param name="delta">
		/// if the object was previously an unresolved delta, this is the
		/// delta object that was tracking it. Otherwise null.
		/// </param>
		/// <param name="deltaBase">
		/// if the object was previously an unresolved delta, this is the
		/// ObjectId of the base of the delta. The base may be outside of
		/// the pack stream if the stream was a thin-pack.
		/// </param>
		/// <returns>info object containing this object's data.</returns>
		protected internal virtual PackedObjectInfo NewInfo(AnyObjectId id, PackParser.UnresolvedDelta
			 delta, ObjectId deltaBase)
		{
			PackedObjectInfo oe = new PackedObjectInfo(id);
			if (delta != null)
			{
				oe.SetCRC(delta.crc);
			}
			return oe;
		}
Beispiel #29
0
		/// <summary>
		/// Create a new command for
		/// <see cref="BaseReceivePack">BaseReceivePack</see>
		/// .
		/// </summary>
		/// <param name="oldId">
		/// the old object id; must not be null. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// to indicate a ref creation.
		/// </param>
		/// <param name="newId">
		/// the new object id; must not be null. Use
		/// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
		/// to indicate a ref deletion.
		/// </param>
		/// <param name="name">name of the ref being affected.</param>
		public ReceiveCommand(ObjectId oldId, ObjectId newId, string name)
		{
			this.oldId = oldId;
			this.newId = newId;
			this.name = name;
			type = ReceiveCommand.Type.UPDATE;
			if (ObjectId.ZeroId.Equals(oldId))
			{
				type = ReceiveCommand.Type.CREATE;
			}
			if (ObjectId.ZeroId.Equals(newId))
			{
				type = ReceiveCommand.Type.DELETE;
			}
			status = ReceiveCommand.Result.NOT_ATTEMPTED;
		}
Beispiel #30
0
 /// <summary>Convert an ObjectId into a hex string representation.</summary>
 /// <remarks>Convert an ObjectId into a hex string representation.</remarks>
 /// <param name="i">the id to convert. May be null.</param>
 /// <returns>the hex string conversion of this id's content.</returns>
 public static string ToString(NGit.ObjectId i)
 {
     return(i != null ? i.Name : ZEROID_STR);
 }
			public _PathEdit_93(ObjectId id, string baseArg1) : base(baseArg1)
			{
				this.id = id;
			}
Beispiel #32
0
 static ObjectId()
 {
     ZEROID     = new NGit.ObjectId(0, 0, 0, 0, 0);
     ZEROID_STR = ZEROID.Name;
 }