Наследование: FileBasedConfig
Пример #1
0
        private readonly int tzOffset; // offset in minutes to UTC

        /// <summary>
        /// Creates new PersonIdent from config info in repository, with current time.
        /// This new PersonIdent gets the info from the default committer as available
        /// from the configuration.
        /// </summary>
        /// <param name="repo"></param>
        public PersonIdent(Repository repo)
        {
            RepositoryConfig config = repo.Config;

            Name         = config.getCommitterName();
            EmailAddress = config.getCommitterEmail();
            When         = SystemReader.getInstance().getCurrentTime();
            tzOffset     = SystemReader.getInstance().getTimezone(When);
        }
Пример #2
0
        private static bool ConfigFilemode(Repository repository)
        {
            // temporary til we can actually set parameters. We need to be able
            // to change this for testing.
            if (filemode != null)
            {
                return(filemode.Value);
            }

            RepositoryConfig config = repository.Config;

            return(config.getBoolean("core", null, "filemode", true));
        }
Пример #3
0
        static private List <RepositoryListener> allListeners = new List <RepositoryListener>(); //TODO: make thread safe

        /**
         * Construct a representation of a Git repository.
         *
         * @param d
         *            GIT_DIR (the location of the repository metadata).
         * @throws IOException
         *             the repository appears to already exist but cannot be
         *             accessed.
         */
        public Repository(DirectoryInfo gitDirectory)
        {
            Directory       = gitDirectory;
            _refDb          = new RefDatabase(this);
            _objectDatabase = new ObjectDirectory(new DirectoryInfo(FS.resolve(gitDirectory, "objects").FullName));

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();

                throw new IOException("User config file "
                                      + userConfig.getFile().FullName + " invalid: "
                                      + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(gitDirectory, "config"));

            WorkingDirectory = gitDirectory.Parent;

            if (_objectDatabase.exists())
            {
                try
                {
                    Config.load();
                }
                catch (ConfigInvalidException e1)
                {
                    Dispose();
                    throw new IOException("Unknown repository format", e1);
                }

                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    Dispose();
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }
Пример #4
0
        /**
         * Construct a representation of a Git repository.
         *
         * @param d
         *            GIT_DIR (the location of the repository metadata).
         * @throws IOException
         *             the repository appears to already exist but cannot be
         *             accessed.
         */
        public Repository(DirectoryInfo gitDirectory)
        {
            Directory = gitDirectory;
            _refDb = new RefDatabase(this);
            _objectDatabase = new ObjectDirectory(new DirectoryInfo(FS.resolve(gitDirectory, "objects").FullName));

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                throw new IOException("User config file "
                    + userConfig.getFile().FullName + " invalid: "
                    + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(gitDirectory, "config"));

            WorkingDirectory = gitDirectory.Parent;

            if (_objectDatabase.exists())
            {
                try
                {
                    Config.load();
                }
                catch (ConfigInvalidException e1)
                {
                    throw new IOException("Unknown repository format", e1);
                }

                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Construct a representation of a Git repository using the given parameters possibly overriding default conventions..
        /// </summary>
        /// <param name="d">GIT_DIR (the location of the repository metadata). May be null for default value in which case it depends on GIT_WORK_TREE.</param>
        /// <param name="workTree">GIT_WORK_TREE (the root of the checkout). May be null for default value if GIT_DIR is</param>
        /// <param name="objectDir">GIT_OBJECT_DIRECTORY (where objects and are stored). May be null for default value. Relative names ares resolved against GIT_WORK_TREE</param>
        /// <param name="alternateObjectDir">GIT_ALTERNATE_OBJECT_DIRECTORIES (where more objects are read from). May be null for default value. Relative names ares resolved against GIT_WORK_TREE</param>
        /// <param name="indexFile">GIT_INDEX_FILE (the location of the index file). May be null for default value. Relative names ares resolved against GIT_WORK_TREE.</param>
        public Repository(DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir,
                DirectoryInfo[] alternateObjectDir, FileInfo indexFile)
        {
            if (workTree != null)
            {
                workDir = workTree;
                if (d == null)
                    Directory = PathUtil.CombineDirectoryPath(workTree, Constants.DOT_GIT);
                else
                    Directory = d;
            }
            else
            {
                if (d != null)
                    Directory = d;
                else
                {
                    Dispose();
                    throw new ArgumentException("Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor");
                }
            }

            var userConfig = SystemReader.getInstance().openUserConfig();

            try
            {
                userConfig.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();

                throw new IOException("User config file "
                    + userConfig.getFile().FullName + " invalid: "
                    + e1, e1);
            }

            Config = new RepositoryConfig(userConfig, (FileInfo)FS.resolve(Directory, "config"));

            try
            {
                Config.load();
            }
            catch (ConfigInvalidException e1)
            {
                Dispose();
                throw new IOException("Unknown repository format", e1);
            }

            if (workDir == null)
            {
                String workTreeConfig = Config.getString("core", null, "worktree");
                if (workTreeConfig != null)
                {
                    workDir = (DirectoryInfo)FS.resolve(d, workTreeConfig);
                }
                else
                {
                    workDir = Directory.Parent;
                }
            }

            _refDb = new RefDirectory(this);
            if (objectDir != null)
                _objectDatabase = new ObjectDirectory(PathUtil.CombineDirectoryPath(objectDir, ""),
                        alternateObjectDir);
            else
                _objectDatabase = new ObjectDirectory(PathUtil.CombineDirectoryPath(Directory, "objects"),
                        alternateObjectDir);

            if (indexFile != null)
                this.indexFile = indexFile;
            else
                this.indexFile = PathUtil.CombineFilePath(Directory, "index");

            if (_objectDatabase.exists())
            {
                string repositoryFormatVersion = Config.getString("core", null, "repositoryFormatVersion");

                if (!"0".Equals(repositoryFormatVersion))
                {
                    Dispose();
                    throw new IOException("Unknown repository format \""
                                          + repositoryFormatVersion + "\"; expected \"0\".");
                }
            }
        }