internal RepositoryStatus(NGit.Repository repository, IEnumerable<string> singleFiles, string rootDir, bool recursive) { Repository = repository; _root_path = rootDir; _recursive = recursive; _file_paths = singleFiles; Update(); }
internal RepositoryStatus(NGit.Repository repository, string singleFile, string rootDir, bool recursive) { Repository = repository; _root_path = rootDir; _recursive = recursive; _file_path = singleFile; Update(); }
public RebaseOperation (NGit.Repository repo, string upstreamRef, IProgressMonitor monitor) { this.monitor = monitor; this.repo = repo; this.upstreamRef = upstreamRef; rw = new RevWalk (repo); branch = repo.GetBranch (); starting = true; }
/// <summary> /// Compares two commits and returns a list of files that have changed /// </summary> public static IEnumerable<DiffEntry> CompareCommits (NGit.Repository repo, RevCommit reference, RevCommit compared) { var changes = new List<DiffEntry>(); if (reference == null && compared == null) return changes; ObjectId refTree = (reference != null ? reference.Tree.Id : ObjectId.ZeroId); ObjectId comparedTree = (compared != null ? compared.Tree.Id : ObjectId.ZeroId); return CompareCommits (repo, refTree, comparedTree); }
/// <summary> /// Returns a list of files that have changed in a commit /// </summary> public static IEnumerable<Change> GetCommitChanges (NGit.Repository repo, RevCommit commit) { var treeIds = new[] { commit.Tree.Id }.Concat (commit.Parents.Select (c => c.Tree.Id)).ToArray (); var walk = new TreeWalk (repo); walk.Reset (treeIds); walk.Recursive = true; walk.Filter = AndTreeFilter.Create (AndTreeFilter.ANY_DIFF, AndTreeFilter.ALL); return CalculateCommitDiff (repo, walk, new[] { commit }.Concat (commit.Parents).ToArray ()); }
/// <summary> /// 設定 /// </summary> /// <param name="hc">ホスト</param> /// <param name="session">セッション</param> protected override void Configure(NGit.Transport.OpenSshConfig.Host hc, NSch.Session session) { var config = new Properties(); config["StrictHostKeyChecking"] = "no"; config["PreferredAuthentications"] = "publickey"; session.SetConfig(config); var jsch = this.GetJSch(hc, FS.DETECTED); jsch.AddIdentity("KeyPair", Encoding.UTF8.GetBytes(PrivateKey), Encoding.UTF8.GetBytes(PublicKey), null); }
protected override NSch.JSch GetJSch(OpenSshConfig.Host hc, NGit.Util.FS fs) { var jsch = base.GetJSch(hc, fs); foreach (var certificate in GitCertificates.GetAllCertificates()) { jsch.AddIdentity(certificate.Path); } // Set the known hosts file. jsch.SetKnownHosts(GetKnownHostsFilename()); return jsch; }
public static List<string> GetConflictedFiles (NGit.Repository repo) { List<string> list = new List<string> (); TreeWalk treeWalk = new TreeWalk (repo); treeWalk.Reset (); treeWalk.Recursive = true; DirCache dc = repo.ReadDirCache (); treeWalk.AddTree (new DirCacheIterator (dc)); while (treeWalk.Next()) { DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(0); var ce = dirCacheIterator.GetDirCacheEntry (); if (ce != null && ce.Stage == 1) list.Add (ce.PathString); } return list; }
/// <summary> /// Compares two commits and returns a list of files that have changed /// </summary> public static IEnumerable<Change> CompareCommits (NGit.Repository repo, RevCommit reference, RevCommit compared) { var changes = new List<Change>(); if (reference == null && compared == null) return changes; ObjectId refTree = (reference != null ? reference.Tree.Id : ObjectId.ZeroId); ObjectId comparedTree = (compared != null ? compared.Tree.Id : ObjectId.ZeroId); var walk = new TreeWalk (repo); if (reference == null || compared == null) walk.Reset ((reference ?? compared).Tree.Id); else walk.Reset (new AnyObjectId[] {refTree, comparedTree}); walk.Recursive = true; walk.Filter = AndTreeFilter.Create(TreeFilter.ANY_DIFF, TreeFilter.ALL); return CalculateCommitDiff (repo, walk, new[] { reference, compared }); }
/// <exception cref="NGit.Errors.TransportException"></exception> internal BundleFetchConnection(NGit.Transport.Transport transportBundle, InputStream src) { transport = transportBundle; bin = new BufferedInputStream(src); try { switch (ReadSignature()) { case 2: { ReadBundleV2(); break; } default: { throw new TransportException(transport.uri, JGitText.Get().notABundle); } } } catch (TransportException err) { Close(); throw; } catch (IOException err) { Close(); throw new TransportException(transport.uri, err.Message, err); } catch (RuntimeException err) { Close(); throw new TransportException(transport.uri, err.Message, err); } }
/// <summary>Check if the current entry of both iterators has the same id.</summary> /// <remarks> /// Check if the current entry of both iterators has the same id. /// <p> /// This method is faster than /// <see cref="EntryObjectId()">EntryObjectId()</see> /// as it does not /// require copying the bytes out of the buffers. A direct /// <see cref="IdBuffer()">IdBuffer()</see> /// compare operation is performed. /// </remarks> /// <param name="otherIterator">the other iterator to test against.</param> /// <returns>true if both iterators have the same object id; false otherwise.</returns> public virtual bool IdEqual(NGit.Treewalk.AbstractTreeIterator otherIterator) { return ObjectId.Equals(IdBuffer, IdOffset, otherIterator.IdBuffer, otherIterator. IdOffset); }
private static int AlreadyMatch(NGit.Treewalk.AbstractTreeIterator a, NGit.Treewalk.AbstractTreeIterator b) { for (; ; ) { NGit.Treewalk.AbstractTreeIterator ap = a.parent; NGit.Treewalk.AbstractTreeIterator bp = b.parent; if (ap == null || bp == null) { return 0; } if (ap.matches == bp.matches) { return a.pathOffset; } a = ap; b = bp; } }
internal virtual int PathCompare(NGit.Treewalk.AbstractTreeIterator p, int pMode) { // Its common when we are a subtree for both parents to match; // when this happens everything in path[0..cPos] is known to // be equal and does not require evaluation again. // int cPos = AlreadyMatch(this, p); return PathCompare(p.path, cPos, p.pathLen, pMode, cPos); }
/// <summary>Compare the path of this current entry to another iterator's entry.</summary> /// <remarks>Compare the path of this current entry to another iterator's entry.</remarks> /// <param name="p">the other iterator to compare the path against.</param> /// <returns> /// -1 if this entry sorts first; 0 if the entries are equal; 1 if /// p's entry sorts first. /// </returns> public virtual int PathCompare(NGit.Treewalk.AbstractTreeIterator p) { return PathCompare(p, p.mode); }
/// <summary>Create an iterator for a subtree of an existing iterator.</summary> /// <remarks> /// Create an iterator for a subtree of an existing iterator. /// <p> /// The caller is responsible for setting up the path of the child iterator. /// </remarks> /// <param name="p">parent tree iterator.</param> /// <param name="childPath"> /// path array to be used by the child iterator. This path must /// contain the path from the top of the walk to the first child /// and must end with a '/'. /// </param> /// <param name="childPathOffset"> /// position within <code>childPath</code> where the child can /// insert its data. The value at /// <code>childPath[childPathOffset-1]</code> must be '/'. /// </param> protected internal AbstractTreeIterator(NGit.Treewalk.AbstractTreeIterator p, byte [] childPath, int childPathOffset) { parent = p; path = childPath; pathOffset = childPathOffset; }
/// <summary>Create an iterator for a subtree of an existing iterator.</summary> /// <remarks>Create an iterator for a subtree of an existing iterator.</remarks> /// <param name="p">parent tree iterator.</param> protected internal AbstractTreeIterator(NGit.Treewalk.AbstractTreeIterator p) { parent = p; path = p.path; pathOffset = p.pathLen + 1; try { path[pathOffset - 1] = (byte)('/'); } catch (IndexOutOfRangeException) { GrowPath(p.pathLen); path[pathOffset - 1] = (byte)('/'); } }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="Sharpen.UnsupportedEncodingException"></exception> private ObjectId InsertCommit(NGit.CommitBuilder builder) { ObjectInserter oi = db.NewObjectInserter(); try { ObjectId id = oi.Insert(builder); oi.Flush(); return id; } finally { oi.Release(); } }
/// <summary>Reconfigure this queue to share the same free list as another.</summary> /// <remarks> /// Reconfigure this queue to share the same free list as another. /// <p/> /// Multiple revision queues can be connected to the same free list, making /// it less expensive for applications to shuttle commits between them. This /// method arranges for the receiver to take from / return to the same free /// list as the supplied queue. /// <p/> /// Free lists are not thread-safe. Applications must ensure that all queues /// sharing the same free list are doing so from only a single thread. /// </remarks> /// <param name="q">the other queue we will steal entries from.</param> internal override void ShareFreeList(NGit.Revwalk.BlockRevQueue q) { free = q.free; }
void GetDirectoryVersionInfoCore (NGit.Repository repository, GitRevision rev, FilePath [] localPaths, HashSet<FilePath> existingFiles, HashSet<FilePath> nonVersionedMissingFiles, List<VersionInfo> versions) { var status = new FilteredStatus (repository, repository.ToGitPath (localPaths)).Call (); HashSet<string> added = new HashSet<string> (); Action<IEnumerable<string>, VersionStatus> AddFiles = delegate(IEnumerable<string> files, VersionStatus fstatus) { foreach (string file in files) { if (!added.Add (file)) continue; FilePath statFile = repository.FromGitPath (file); existingFiles.Remove (statFile.CanonicalPath); nonVersionedMissingFiles.Remove (statFile.CanonicalPath); versions.Add (new VersionInfo (statFile, "", false, fstatus, rev, VersionStatus.Versioned, null)); } }; AddFiles (status.GetAdded (), VersionStatus.Versioned | VersionStatus.ScheduledAdd); AddFiles (status.GetChanged (), VersionStatus.Versioned | VersionStatus.Modified); AddFiles (status.GetModified (), VersionStatus.Versioned | VersionStatus.Modified); AddFiles (status.GetRemoved (), VersionStatus.Versioned | VersionStatus.ScheduledDelete); AddFiles (status.GetMissing (), VersionStatus.Versioned | VersionStatus.ScheduledDelete); AddFiles (status.GetConflicting (), VersionStatus.Versioned | VersionStatus.Conflicted); AddFiles (status.GetUntracked (), VersionStatus.Unversioned); }
RevCommit GetHeadCommit (NGit.Repository repository) { RevWalk rw = new RevWalk (repository); ObjectId headId = repository.Resolve (Constants.HEAD); if (headId == null) return null; return rw.ParseCommit (headId); }
public GitRevision (Repository repo, NGit.Repository gitRepository, string rev) : base(repo) { this.rev = rev; GitRepository = gitRepository; }
static RawText GetRawText(NGit.Repository repo, string file, RevCommit commit) { TreeWalk tw = TreeWalk.ForPath (repo, file, commit.Tree); ObjectId objectID = tw.GetObjectId(0); byte[] data = repo.ObjectDatabase.Open (objectID).GetBytes (); return new RawText (data); }
public static MergeCommandResult MergeTrees (NGit.Repository repo, RevCommit srcBase, RevCommit srcCommit, string sourceDisplayName, bool commitResult) { RevCommit newHead = null; RevWalk revWalk = new RevWalk(repo); try { // get the head commit Ref headRef = repo.GetRef(Constants.HEAD); if (headRef == null) { throw new NoHeadException(JGitText.Get().commitOnRepoWithoutHEADCurrentlyNotSupported ); } RevCommit headCommit = revWalk.ParseCommit(headRef.GetObjectId()); ResolveMerger merger = (ResolveMerger)((ThreeWayMerger)MergeStrategy.RESOLVE.NewMerger (repo)); // CherryPick command sets the working tree, but this should not be necessary, and when setting it // untracked files are deleted during the merge // merger.SetWorkingTreeIterator(new FileTreeIterator(repo)); merger.SetBase(srcBase); bool noProblems; IDictionary<string, MergeResult<NGit.Diff.Sequence>> lowLevelResults = null; IDictionary<string, ResolveMerger.MergeFailureReason> failingPaths = null; IList<string> modifiedFiles = null; ResolveMerger resolveMerger = (ResolveMerger)merger; resolveMerger.SetCommitNames(new string[] { "BASE", "HEAD", sourceDisplayName }); noProblems = merger.Merge(headCommit, srcCommit); lowLevelResults = resolveMerger.GetMergeResults(); modifiedFiles = resolveMerger.GetModifiedFiles(); failingPaths = resolveMerger.GetFailingPaths(); if (noProblems) { if (modifiedFiles != null && modifiedFiles.Count == 0) { return new MergeCommandResult(headCommit, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.ALREADY_UP_TO_DATE, MergeStrategy.RESOLVE, null, null); } DirCacheCheckout dco = new DirCacheCheckout(repo, headCommit.Tree, repo.LockDirCache (), merger.GetResultTreeId()); dco.SetFailOnConflict(true); dco.Checkout(); if (commitResult) { newHead = new NGit.Api.Git(repo).Commit().SetMessage(srcCommit.GetFullMessage() ).SetAuthor(srcCommit.GetAuthorIdent()).Call(); return new MergeCommandResult(newHead.Id, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.MERGED, MergeStrategy.RESOLVE, null, null); } else { return new MergeCommandResult(headCommit, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.MERGED, MergeStrategy.RESOLVE, null, null); } } else { if (failingPaths != null) { return new MergeCommandResult(null, merger.GetBaseCommit(0, 1), new ObjectId[] { headCommit.Id, srcCommit.Id }, MergeStatus.FAILED, MergeStrategy.RESOLVE, lowLevelResults , null); } else { return new MergeCommandResult(null, merger.GetBaseCommit(0, 1), new ObjectId[] { headCommit.Id, srcCommit.Id }, MergeStatus.CONFLICTING, MergeStrategy.RESOLVE, lowLevelResults , null); } } } finally { revWalk.Release(); } }
static int SetBlameLines (NGit.Repository repo, RevCommit[] lines, RevCommit commit, RawText curText, RawText ancestorText) { int lineCount = 0; var differ = MyersDiff<RawText>.INSTANCE; foreach (Edit e in differ.Diff (RawTextComparator.DEFAULT, ancestorText, curText)) { for (int n = e.GetBeginB (); n < e.GetEndB (); n++) { if (lines [n] == null) { lines [n] = commit; lineCount ++; } } } return lineCount; }
public GitRevision (Repository repo, NGit.Repository gitRepository, string rev, DateTime time, string author, string message) : base(repo, time, author, message) { this.rev = rev; GitRepository = gitRepository; }
/// <summary>Breaks apart a DiffEntry into two entries, one DELETE and one ADD.</summary> /// <remarks>Breaks apart a DiffEntry into two entries, one DELETE and one ADD.</remarks> /// <param name="entry">the DiffEntry to break apart.</param> /// <returns> /// a list containing two entries. Calling /// <see cref="GetChangeType()">GetChangeType()</see> /// on the first entry will return ChangeType.DELETE. Calling it on /// the second entry will return ChangeType.ADD. /// </returns> internal static IList<NGit.Diff.DiffEntry> BreakModify(NGit.Diff.DiffEntry entry) { NGit.Diff.DiffEntry del = new NGit.Diff.DiffEntry(); del.oldId = entry.GetOldId(); del.oldMode = entry.GetOldMode(); del.oldPath = entry.GetOldPath(); del.newId = A_ZERO; del.newMode = FileMode.MISSING; del.newPath = NGit.Diff.DiffEntry.DEV_NULL; del.changeType = DiffEntry.ChangeType.DELETE; NGit.Diff.DiffEntry add = new NGit.Diff.DiffEntry(); add.oldId = A_ZERO; add.oldMode = FileMode.MISSING; add.oldPath = NGit.Diff.DiffEntry.DEV_NULL; add.newId = entry.GetNewId(); add.newMode = entry.GetNewMode(); add.newPath = entry.GetNewPath(); add.changeType = DiffEntry.ChangeType.ADD; return Arrays.AsList(del, add); }
public StashCollection GetStashes (NGit.Repository repository) { return new StashCollection (repository); }
internal static NGit.Diff.DiffEntry Pair(DiffEntry.ChangeType changeType, NGit.Diff.DiffEntry src, NGit.Diff.DiffEntry dst, int score) { NGit.Diff.DiffEntry r = new NGit.Diff.DiffEntry(); r.oldId = src.oldId; r.oldMode = src.oldMode; r.oldPath = src.oldPath; r.newId = dst.newId; r.newMode = dst.newMode; r.newPath = dst.newPath; r.changeType = changeType; r.score = score; return r; }
private CanonicalTreeParser(NGit.Treewalk.CanonicalTreeParser p) : base(p) { }
/// <summary>Insert a single commit into the store, returning its unique name.</summary> /// <remarks>Insert a single commit into the store, returning its unique name.</remarks> /// <param name="builder">the builder containing the proposed commit's data.</param> /// <returns>the name of the commit object.</returns> /// <exception cref="System.IO.IOException">the object could not be stored.</exception> public ObjectId Insert(NGit.CommitBuilder builder) { return Insert(Constants.OBJ_COMMIT, builder.Build()); }