Ejemplo n.º 1
0
        public static RepositoryEntry GetRepository(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            lock (_syncLock)
            {
                // We expect this method to be called very very often with the
                // same path name. Because of this, we cache all path names we
                // receive and map them to a repostory root.

                string repositoryRoot;

                if (!_repositoryRootLookup.TryGetValue(path, out repositoryRoot))
                {
                    GitTools.TryGetRepositoryRoot(path, out repositoryRoot);
                    _repositoryRootLookup.Add(path, repositoryRoot);
                }

                if (repositoryRoot == null)
                    return null;

                RepositoryEntry entry;

                if (!_repositoryCache.TryGetValue(repositoryRoot, out entry))
                {
                    entry = new RepositoryEntry(repositoryRoot);

                    _repositoryCache.Add(repositoryRoot, entry);
                }

                return entry;
            }
        }
Ejemplo n.º 2
0
        public IgnoreManager(RepositoryEntry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            _entry = entry;

            _repositoryPath = entry.Path.TrimEnd(Path.DirectorySeparatorChar);
        }
Ejemplo n.º 3
0
        protected void RaiseMergeResults(RepositoryEntry repositoryEntry, MergeCommandResult mergeResults)
        {
            Debug.Assert(Args is IGitConflictsClientArgs, "Merge results may only be reported on Args that implement IGitConflictsClientArgs");

            // We ignore the merge results for getting a list of conflicts.
            // Instead, we go to the index directly.

            var conflicts = new HashSet<string>(FileSystemUtil.StringComparer);

            using (repositoryEntry.Lock())
            {
                var repository = repositoryEntry.Repository;

                var dirCache = repository.ReadDirCache();

                for (int i = 0, count = dirCache.GetEntryCount(); i < count; i++)
                {
                    var entry = dirCache.GetEntry(i);

                    if (entry.Stage > 0)
                    {
                        string path = entry.PathString;

                        if (!conflicts.Contains(path))
                            conflicts.Add(path);
                    }
                }
            }

            if (conflicts.Count == 0)
                return;

            foreach (var item in conflicts)
            {
                string fullPath = repositoryEntry.Repository.GetAbsoluteRepositoryPath(item);

                var args = new GitConflictEventArgs
                {
                    MergedFile = fullPath,
                    Path = item,
                    ConflictReason = GitConflictReason.Edited
                };

                try
                {
                    Args.OnConflict(args);

                    if (args.Cancel)
                        return;
                    if (args.Choice == GitAccept.Postpone)
                        continue;

                    Client.Resolve(args.MergedFile, args.Choice, new GitResolveArgs
                    {
                        ConflictArgs = args
                    });
                }
                finally
                {
                    args.Cleanup();
                }
            }
        }
Ejemplo n.º 4
0
            public RepositoryLock(RepositoryEntry entry)
            {
                _entry = entry;

                // Prevent deadlocking on the repository. When the repository
                // is already locked, we fail unconditionally.

                if (!Monitor.TryEnter(entry._syncLock, TimeSpan.FromSeconds(5)))
                    throw new GitRepositoryLockedException();
                else
                    _locked = true;
            }