/// <summary>Write (if necessary) this tree to the object store.</summary>
 /// <remarks>Write (if necessary) this tree to the object store.</remarks>
 /// <param name="cache">the complete cache from DirCache.</param>
 /// <param name="cIdx">
 /// first position of <code>cache</code> that is a member of this
 /// tree. The path of <code>cache[cacheIdx].path</code> for the
 /// range <code>[0,pathOff-1)</code> matches the complete path of
 /// this tree, from the root of the repository.
 /// </param>
 /// <param name="pathOffset">
 /// number of bytes of <code>cache[cacheIdx].path</code> that
 /// matches this tree's path. The value at array position
 /// <code>cache[cacheIdx].path[pathOff-1]</code> is always '/' if
 /// <code>pathOff</code> is &gt; 0.
 /// </param>
 /// <param name="ow">the writer to use when serializing to the store.</param>
 /// <returns>identity of this tree.</returns>
 /// <exception cref="NGit.Errors.UnmergedPathException">
 /// one or more paths contain higher-order stages (stage &gt; 0),
 /// which cannot be stored in a tree object.
 /// </exception>
 /// <exception cref="System.IO.IOException">an unexpected error occurred writing to the object store.
 ///     </exception>
 internal virtual ObjectId WriteTree(DirCacheEntry[] cache, int cIdx, int pathOffset
                                     , ObjectInserter ow)
 {
     if (id == null)
     {
         int           endIdx   = cIdx + entrySpan;
         TreeFormatter fmt      = new TreeFormatter(ComputeSize(cache, cIdx, pathOffset, ow));
         int           childIdx = 0;
         int           entryIdx = cIdx;
         while (entryIdx < endIdx)
         {
             DirCacheEntry e  = cache[entryIdx];
             byte[]        ep = e.path;
             if (childIdx < childCnt)
             {
                 NGit.Dircache.DirCacheTree st = children[childIdx];
                 if (st.Contains(ep, pathOffset, ep.Length))
                 {
                     fmt.Append(st.encodedName, FileMode.TREE, st.id);
                     entryIdx += st.entrySpan;
                     childIdx++;
                     continue;
                 }
             }
             fmt.Append(ep, pathOffset, ep.Length - pathOffset, e.FileMode, e.IdBuffer, e.IdOffset
                        );
             entryIdx++;
         }
         id = ow.Insert(fmt);
     }
     return(id);
 }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private void CommitNoteMap(RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter
                                   inserter, string msg)
        {
            // commit the note
            NGit.CommitBuilder builder = new NGit.CommitBuilder();
            builder.TreeId    = map.WriteTree(inserter);
            builder.Author    = new PersonIdent(repo);
            builder.Committer = builder.Author;
            builder.Message   = msg;
            if (notesCommit != null)
            {
                builder.SetParentIds(notesCommit);
            }
            ObjectId commit = inserter.Insert(builder);

            inserter.Flush();
            RefUpdate refUpdate = repo.UpdateRef(notesRef);

            if (notesCommit != null)
            {
                refUpdate.SetExpectedOldObjectId(notesCommit);
            }
            else
            {
                refUpdate.SetExpectedOldObjectId(ObjectId.ZeroId);
            }
            refUpdate.SetNewObjectId(commit);
            refUpdate.Update(walk);
        }
Beispiel #3
0
        public virtual void TestTrivialTwoWay_rightDFconflict2()
        {
            DirCache treeB = db.ReadDirCache();
            DirCache treeO = db.ReadDirCache();
            DirCache treeT = db.ReadDirCache();
            {
                DirCacheBuilder b = treeB.Builder();
                DirCacheBuilder o = treeO.Builder();
                DirCacheBuilder t = treeT.Builder();
                b.Add(CreateEntry("d", FileMode.REGULAR_FILE));
                o.Add(CreateEntry("d/o", FileMode.REGULAR_FILE));
                t.Add(CreateEntry("d", FileMode.REGULAR_FILE, "t !"));
                b.Finish();
                o.Finish();
                t.Finish();
            }
            ObjectInserter ow        = db.NewObjectInserter();
            ObjectId       b_1       = Commit(ow, treeB, new ObjectId[] {  });
            ObjectId       o_1       = Commit(ow, treeO, new ObjectId[] { b_1 });
            ObjectId       t_1       = Commit(ow, treeT, new ObjectId[] { b_1 });
            Merger         ourMerger = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
                                            (db));
            bool merge = ourMerger.Merge(new ObjectId[] { o_1, t_1 });

            NUnit.Framework.Assert.IsFalse(merge);
        }
Beispiel #4
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 protected internal override void DoFetch(ProgressMonitor monitor, ICollection <Ref
                                                                                > want, ICollection <ObjectId> have)
 {
     VerifyPrerequisites();
     try
     {
         ObjectInserter ins = transport.local.NewObjectInserter();
         try
         {
             PackParser parser = ins.NewPackParser(bin);
             parser.SetAllowThin(true);
             parser.SetObjectChecking(transport.IsCheckFetchedObjects());
             parser.SetLockMessage(lockMessage);
             packLock = parser.Parse(NullProgressMonitor.INSTANCE);
             ins.Flush();
         }
         finally
         {
             ins.Release();
         }
     }
     catch (IOException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
     catch (RuntimeException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
 }
Beispiel #5
0
        /// <exception cref="NGit.Api.Errors.JGitInternalException">upon internal failure</exception>
        public override Note Call()
        {
            CheckCallable();
            RevWalk        walk        = new RevWalk(repo);
            ObjectInserter inserter    = repo.NewObjectInserter();
            NoteMap        map         = NoteMap.NewEmptyMap();
            RevCommit      notesCommit = null;

            try
            {
                Ref @ref = repo.GetRef(notesRef);
                // if we have a notes ref, use it
                if (@ref != null)
                {
                    notesCommit = walk.ParseCommit(@ref.GetObjectId());
                    map         = NoteMap.Read(walk.GetObjectReader(), notesCommit);
                }
                map.Set(id, null, inserter);
                CommitNoteMap(walk, map, notesCommit, inserter, "Notes removed by 'git notes remove'"
                              );
                return(map.GetNote(id));
            }
            catch (IOException e)
            {
                throw new JGitInternalException(e.Message, e);
            }
            finally
            {
                inserter.Release();
                walk.Release();
            }
        }
Beispiel #6
0
 public static ObjectId CreateCommit(NGit.Repository rep, string message, IList <ObjectId> parents, ObjectId indexTreeId, PersonIdent author, PersonIdent committer)
 {
     try {
         ObjectInserter odi = rep.NewObjectInserter();
         try {
             // Create a Commit object, populate it and write it
             NGit.CommitBuilder commit = new NGit.CommitBuilder();
             commit.Committer = committer;
             commit.Author    = author;
             commit.Message   = message;
             commit.SetParentIds(parents);
             commit.TreeId = indexTreeId;
             ObjectId commitId = odi.Insert(commit);
             odi.Flush();
             return(commitId);
         } finally {
             odi.Release();
         }
     } catch (UnmergedPathException) {
         // since UnmergedPathException is a subclass of IOException
         // which should not be wrapped by a JGitInternalException we
         // have to catch and re-throw it here
         throw;
     } catch (IOException e) {
         throw new JGitInternalException("Commit failed", e);
     }
 }
Beispiel #7
0
 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>();
 }
        /// <exception cref="System.IO.IOException"></exception>
        private void ReceivePack(ProgressMonitor monitor)
        {
            OnReceivePack();
            InputStream input = @in;

            if (sideband)
            {
                input = new SideBandInputStream(input, monitor, GetMessageWriter());
            }
            ObjectInserter ins = local.NewObjectInserter();

            try
            {
                PackParser parser = ins.NewPackParser(input);
                parser.SetAllowThin(thinPack);
                parser.SetObjectChecking(transport.IsCheckFetchedObjects());
                parser.SetLockMessage(lockMessage);
                packLock = parser.Parse(monitor);
                ins.Flush();
            }
            finally
            {
                ins.Release();
            }
        }
Beispiel #9
0
        /// <exception cref="System.IO.IOException"></exception>
        private RevObject WriteBlob(Repository repo, string data)
        {
            RevWalk revWalk = new RevWalk(repo);

            byte[]         bytes    = Constants.Encode(data);
            ObjectInserter inserter = repo.NewObjectInserter();
            ObjectId       id;

            try
            {
                id = inserter.Insert(Constants.OBJ_BLOB, bytes);
                inserter.Flush();
            }
            finally
            {
                inserter.Release();
            }
            try
            {
                Parse(id);
                NUnit.Framework.Assert.Fail("Object " + id.Name + " should not exist in test repository"
                                            );
            }
            catch (MissingObjectException)
            {
            }
            // Ok
            return(revWalk.LookupBlob(id));
        }
 public override void SetUp()
 {
     base.SetUp();
     tr       = new TestRepository <Repository>(db);
     reader   = db.NewObjectReader();
     inserter = db.NewObjectInserter();
 }
        /// <exception cref="NGit.Errors.UnmergedPathException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private int ComputeSize(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectInserter
                                ow)
        {
            int endIdx   = cIdx + entrySpan;
            int childIdx = 0;
            int entryIdx = cIdx;
            int size     = 0;

            while (entryIdx < endIdx)
            {
                DirCacheEntry e = cache[entryIdx];
                if (e.Stage != 0)
                {
                    throw new UnmergedPathException(e);
                }
                byte[] ep = e.path;
                if (childIdx < childCnt)
                {
                    NGit.Dircache.DirCacheTree st = children[childIdx];
                    if (st.Contains(ep, pathOffset, ep.Length))
                    {
                        int stOffset = pathOffset + st.NameLength() + 1;
                        st.WriteTree(cache, entryIdx, stOffset, ow);
                        size     += TreeFormatter.EntrySize(FileMode.TREE, st.NameLength());
                        entryIdx += st.entrySpan;
                        childIdx++;
                        continue;
                    }
                }
                size += TreeFormatter.EntrySize(e.FileMode, ep.Length - pathOffset);
                entryIdx++;
            }
            return(size);
        }
Beispiel #12
0
 /// <returns>
 /// an object writer to create objects in
 /// <see cref="GetRepository()">GetRepository()</see>
 /// .
 /// If no inserter has been set on this instance, one will be created
 /// and returned by all future calls.
 /// </returns>
 public virtual ObjectInserter GetObjectInserter()
 {
     if (inserter == null)
     {
         inserter = GetRepository().NewObjectInserter();
     }
     return(inserter);
 }
 /// <exception cref="System.IO.IOException"></exception>
 private PackParser Index(InputStream @in)
 {
     if (inserter == null)
     {
         inserter = db.NewObjectInserter();
     }
     return(inserter.NewPackParser(@in));
 }
 public virtual void Release()
 {
     if (inserter != null)
     {
         inserter.Release();
         inserter = null;
     }
 }
Beispiel #15
0
 /// <exception cref="System.IO.IOException"></exception>
 private PackParser Index(byte[] raw)
 {
     if (inserter == null)
     {
         inserter = repo.NewObjectInserter();
     }
     return(inserter.NewPackParser(new ByteArrayInputStream(raw)));
 }
Beispiel #16
0
 /// <summary>Set the inserter this merger will use to create objects.</summary>
 /// <remarks>
 /// Set the inserter this merger will use to create objects.
 /// <p>
 /// If an inserter was already set on this instance (such as by a prior set,
 /// or a prior call to
 /// <see cref="GetObjectInserter()">GetObjectInserter()</see>
 /// ), the prior inserter will
 /// be released first.
 /// </remarks>
 /// <param name="oi">
 /// the inserter instance to use. Must be associated with the
 /// repository instance returned by
 /// <see cref="GetRepository()">GetRepository()</see>
 /// .
 /// </param>
 public virtual void SetObjectInserter(ObjectInserter oi)
 {
     if (inserter != null)
     {
         inserter.Release();
     }
     inserter = oi;
 }
Beispiel #17
0
 /// <exception cref="System.IO.IOException"></exception>
 private PackParser Index(byte[] packData)
 {
     if (inserter == null)
     {
         inserter = dst.NewObjectInserter();
     }
     return(inserter.NewPackParser(new ByteArrayInputStream(packData)));
 }
Beispiel #18
0
        ObjectId WriteWorkingDirectoryTree(RevTree headTree, DirCache index)
        {
            DirCache        dc = DirCache.NewInCore();
            DirCacheBuilder cb = dc.Builder();

            ObjectInserter oi = _repo.NewObjectInserter();

            try {
                TreeWalk tw = new TreeWalk(_repo);
                tw.Reset();
                tw.AddTree(new FileTreeIterator(_repo));
                tw.AddTree(headTree);
                tw.AddTree(new DirCacheIterator(index));

                while (tw.Next())
                {
                    // Ignore untracked files
                    if (tw.IsSubtree)
                    {
                        tw.EnterSubtree();
                    }
                    else if (tw.GetFileMode(0) != NGit.FileMode.MISSING && (tw.GetFileMode(1) != NGit.FileMode.MISSING || tw.GetFileMode(2) != NGit.FileMode.MISSING))
                    {
                        WorkingTreeIterator f            = tw.GetTree <WorkingTreeIterator>(0);
                        DirCacheIterator    dcIter       = tw.GetTree <DirCacheIterator>(2);
                        DirCacheEntry       currentEntry = dcIter.GetDirCacheEntry();
                        DirCacheEntry       ce           = new DirCacheEntry(tw.PathString);
                        if (!f.IsModified(currentEntry, true))
                        {
                            ce.SetLength(currentEntry.Length);
                            ce.LastModified = currentEntry.LastModified;
                            ce.FileMode     = currentEntry.FileMode;
                            ce.SetObjectId(currentEntry.GetObjectId());
                        }
                        else
                        {
                            long sz = f.GetEntryLength();
                            ce.SetLength(sz);
                            ce.LastModified = f.GetEntryLastModified();
                            ce.FileMode     = f.EntryFileMode;
                            var data = f.OpenEntryStream();
                            try {
                                ce.SetObjectId(oi.Insert(Constants.OBJ_BLOB, sz, data));
                            } finally {
                                data.Close();
                            }
                        }
                        cb.Add(ce);
                    }
                }

                cb.Finish();
                return(dc.WriteTree(oi));
            } finally {
                oi.Release();
            }
        }
Beispiel #19
0
        public Stash Create(string message)
        {
            UserConfig config = _repo.GetConfig().Get(UserConfig.KEY);
            RevWalk    rw     = new RevWalk(_repo);
            ObjectId   headId = _repo.Resolve(Constants.HEAD);
            var        parent = rw.ParseCommit(headId);

            PersonIdent author = new PersonIdent(config.GetAuthorName() ?? "unknown", config.GetAuthorEmail() ?? "unknown@(none).");

            if (string.IsNullOrEmpty(message))
            {
                // Use the commit summary as message
                message = parent.Abbreviate(7).ToString() + " " + parent.GetShortMessage();
                int i = message.IndexOfAny(new char[] { '\r', '\n' });
                if (i != -1)
                {
                    message = message.Substring(0, i);
                }
            }

            // Create the index tree commit
            ObjectInserter inserter = _repo.NewObjectInserter();
            DirCache       dc       = _repo.ReadDirCache();
            var            tree_id  = dc.WriteTree(inserter);

            inserter.Release();

            string   commitMsg   = "index on " + _repo.GetBranch() + ": " + message;
            ObjectId indexCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId }, tree_id, author, author);

            // Create the working dir commit
            tree_id   = WriteWorkingDirectoryTree(parent.Tree, dc);
            commitMsg = "WIP on " + _repo.GetBranch() + ": " + message;
            var wipCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId, indexCommit }, tree_id, author, author);

            string   prevCommit = null;
            FileInfo sf         = StashRefFile;

            if (sf.Exists)
            {
                prevCommit = File.ReadAllText(sf.FullName).Trim(' ', '\t', '\r', '\n');
            }

            Stash s = new Stash(prevCommit, wipCommit.Name, author, commitMsg);

            FileInfo stashLog = StashLogFile;

            File.AppendAllText(stashLog.FullName, s.FullLine + "\n");
            File.WriteAllText(sf.FullName, s.CommitId + "\n");

            // Wipe all local changes
            GitUtil.HardReset(_repo, Constants.HEAD);

            s.StashCollection = this;
            return(s);
        }
        public virtual void TestPick()
        {
            // B---O
            // \----P---T
            //
            // Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
            // was created by "P", nor should it modify "a", which was done by "P".
            //
            DirCache treeB = db.ReadDirCache();
            DirCache treeO = db.ReadDirCache();
            DirCache treeP = db.ReadDirCache();
            DirCache treeT = db.ReadDirCache();
            {
                DirCacheBuilder b = treeB.Builder();
                DirCacheBuilder o = treeO.Builder();
                DirCacheBuilder p = treeP.Builder();
                DirCacheBuilder t = treeT.Builder();
                b.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                o.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                o.Add(MakeEntry("o", FileMode.REGULAR_FILE));
                p.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                p.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("t", FileMode.REGULAR_FILE));
                b.Finish();
                o.Finish();
                p.Finish();
                t.Finish();
            }
            ObjectInserter ow  = db.NewObjectInserter();
            ObjectId       B   = Commit(ow, treeB, new ObjectId[] {  });
            ObjectId       O   = Commit(ow, treeO, new ObjectId[] { B });
            ObjectId       P   = Commit(ow, treeP, new ObjectId[] { B });
            ObjectId       T   = Commit(ow, treeT, new ObjectId[] { P });
            ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
                                      (db));

            twm.SetBase(P);
            bool merge = twm.Merge(new ObjectId[] { O, T });

            NUnit.Framework.Assert.IsTrue(merge);
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.Reset(twm.GetResultTreeId());
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("a", tw.PathString);
            AssertCorrectId(treeO, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("o", tw.PathString);
            AssertCorrectId(treeO, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("t", tw.PathString);
            AssertCorrectId(treeT, tw);
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }
Beispiel #21
0
 /// <summary>
 /// Constructs a NoteMapMerger with custom
 /// <see cref="NoteMerger">NoteMerger</see>
 /// and custom
 /// <see cref="NGit.Merge.MergeStrategy">NGit.Merge.MergeStrategy</see>
 /// .
 /// </summary>
 /// <param name="db">Git repository</param>
 /// <param name="noteMerger">note merger for merging conflicting changes on a note</param>
 /// <param name="nonNotesMergeStrategy">merge strategy for merging non-note entries</param>
 public NoteMapMerger(Repository db, NoteMerger noteMerger, MergeStrategy nonNotesMergeStrategy
                      )
 {
     this.db                    = db;
     this.reader                = db.NewObjectReader();
     this.inserter              = db.NewObjectInserter();
     this.noteMerger            = noteMerger;
     this.nonNotesMergeStrategy = nonNotesMergeStrategy;
     this.objectIdPrefix        = new MutableObjectId();
 }
Beispiel #22
0
 public override void SetUp()
 {
     base.SetUp();
     tr       = new TestRepository <Repository>(db);
     reader   = db.NewObjectReader();
     inserter = db.NewObjectInserter();
     merger   = new DefaultNoteMerger();
     noteOn   = tr.Blob("a");
     baseNote = NewNote("data");
 }
        public virtual void TestRecursiveFiltering()
        {
            ObjectInserter odi  = db.NewObjectInserter();
            ObjectId       aSth = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
                                                 "a.sth"));
            ObjectId aTxt = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
                                           "a.txt"));
            ObjectId bSth = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
                                           "b.sth"));
            ObjectId bTxt = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
                                           "b.txt"));
            DirCache        dc        = db.ReadDirCache();
            DirCacheBuilder builder   = dc.Builder();
            DirCacheEntry   aSthEntry = new DirCacheEntry("a.sth");

            aSthEntry.FileMode = FileMode.REGULAR_FILE;
            aSthEntry.SetObjectId(aSth);
            DirCacheEntry aTxtEntry = new DirCacheEntry("a.txt");

            aTxtEntry.FileMode = FileMode.REGULAR_FILE;
            aTxtEntry.SetObjectId(aTxt);
            builder.Add(aSthEntry);
            builder.Add(aTxtEntry);
            DirCacheEntry bSthEntry = new DirCacheEntry("sub/b.sth");

            bSthEntry.FileMode = FileMode.REGULAR_FILE;
            bSthEntry.SetObjectId(bSth);
            DirCacheEntry bTxtEntry = new DirCacheEntry("sub/b.txt");

            bTxtEntry.FileMode = FileMode.REGULAR_FILE;
            bTxtEntry.SetObjectId(bTxt);
            builder.Add(bSthEntry);
            builder.Add(bTxtEntry);
            builder.Finish();
            ObjectId treeId = dc.WriteTree(odi);

            odi.Flush();
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.Filter    = PathSuffixFilter.Create(".txt");
            tw.AddTree(treeId);
            IList <string> paths = new List <string>();

            while (tw.Next())
            {
                paths.AddItem(tw.PathString);
            }
            IList <string> expected = new List <string>();

            expected.AddItem("a.txt");
            expected.AddItem("sub/b.txt");
            NUnit.Framework.Assert.AreEqual(expected, paths);
        }
        /// <exception cref="System.IO.IOException"></exception>
        private void OpenPack(TemporaryBuffer.Heap buf)
        {
            if (inserter == null)
            {
                inserter = src.NewObjectInserter();
            }
            byte[]     raw = buf.ToByteArray();
            PackParser p   = inserter.NewPackParser(new ByteArrayInputStream(raw));

            p.SetAllowThin(true);
            p.Parse(PM);
        }
Beispiel #25
0
        /// <exception cref="System.Exception"></exception>
        private ObjectId Commit(ObjectInserter odi, DirCache treeB, ObjectId[] parentIds)
        {
            NGit.CommitBuilder c = new NGit.CommitBuilder();
            c.TreeId    = treeB.WriteTree(odi);
            c.Author    = new PersonIdent("A U Thor", "a.u.thor", 1L, 0);
            c.Committer = c.Author;
            c.SetParentIds(parentIds);
            c.Message = "Tree " + c.TreeId.Name;
            ObjectId id = odi.Insert(c);

            odi.Flush();
            return(id);
        }
        public virtual void TestRevert()
        {
            // B---P---T
            //
            // Revert P, this should result in a tree with a
            // from B and t from T as the change to a in P
            // and addition of t in P is reverted.
            //
            // We use the standard merge, but change the order
            // of the sources.
            //
            DirCache treeB = db.ReadDirCache();
            DirCache treeP = db.ReadDirCache();
            DirCache treeT = db.ReadDirCache();
            {
                DirCacheBuilder b = treeB.Builder();
                DirCacheBuilder p = treeP.Builder();
                DirCacheBuilder t = treeT.Builder();
                b.Add(MakeEntry("a", FileMode.REGULAR_FILE));
                p.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                p.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("a", FileMode.REGULAR_FILE, "q"));
                t.Add(MakeEntry("p-fail", FileMode.REGULAR_FILE));
                t.Add(MakeEntry("t", FileMode.REGULAR_FILE));
                b.Finish();
                p.Finish();
                t.Finish();
            }
            ObjectInserter ow  = db.NewObjectInserter();
            ObjectId       B   = Commit(ow, treeB, new ObjectId[] {  });
            ObjectId       P   = Commit(ow, treeP, new ObjectId[] { B });
            ObjectId       T   = Commit(ow, treeT, new ObjectId[] { P });
            ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
                                      (db));

            twm.SetBase(P);
            bool merge = twm.Merge(new ObjectId[] { B, T });

            NUnit.Framework.Assert.IsTrue(merge);
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.Reset(twm.GetResultTreeId());
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("a", tw.PathString);
            AssertCorrectId(treeB, tw);
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("t", tw.PathString);
            AssertCorrectId(treeT, tw);
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }
Beispiel #27
0
 public override void TearDown()
 {
     if (writer != null)
     {
         writer.Release();
         writer = null;
     }
     if (inserter != null)
     {
         inserter.Release();
         inserter = null;
     }
     base.TearDown();
 }
Beispiel #28
0
 /// <param name="local"></param>
 /// <param name="inCore"></param>
 protected internal ResolveMerger(Repository local, bool inCore) : base(local)
 {
     DiffAlgorithm.SupportedAlgorithm diffAlg = local.GetConfig().GetEnum(ConfigConstants
                                                                          .CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm
                                                                          .HISTOGRAM);
     mergeAlgorithm = new MergeAlgorithm(DiffAlgorithm.GetAlgorithm(diffAlg));
     commitNames    = new string[] { "BASE", "OURS", "THEIRS" };
     oi             = GetObjectInserter();
     this.inCore    = inCore;
     if (inCore)
     {
         dircache = DirCache.NewInCore();
     }
 }
Beispiel #29
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="Sharpen.UnsupportedEncodingException"></exception>
        private ObjectId InsertTag(TagBuilder tag)
        {
            ObjectInserter oi = db.NewObjectInserter();

            try
            {
                ObjectId id = oi.Insert(tag);
                oi.Flush();
                return(id);
            }
            finally
            {
                oi.Release();
            }
        }
        /// <summary>Attach a note to an object.</summary>
        /// <remarks>
        /// Attach a note to 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).
        /// </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">
        /// text to store in the note. The text will be UTF-8 encoded when
        /// stored in the repository. If null the note will be deleted, if
        /// the empty string a note with the empty string will be stored.
        /// </param>
        /// <param name="ins">
        /// inserter to write the encoded
        /// <code>noteData</code>
        /// out as a blob.
        /// The caller must ensure the inserter is flushed before the
        /// updated note map is made available for reading.
        /// </param>
        /// <exception cref="System.IO.IOException">the note data could not be stored in the repository.
        ///     </exception>
        public virtual void Set(AnyObjectId noteOn, string noteData, ObjectInserter ins)
        {
            ObjectId dataId;

            if (noteData != null)
            {
                byte[] dataUTF8 = Constants.Encode(noteData);
                dataId = ins.Insert(Constants.OBJ_BLOB, dataUTF8);
            }
            else
            {
                dataId = null;
            }
            Set(noteOn, dataId);
        }