gitsettings.cpp 4.08 KB
Newer Older
1
/**************************************************************************
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
8 9
**
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
28
**
29
**************************************************************************/
30 31

#include "gitsettings.h"
32

33
#include <utils/hostosinfo.h>
34
#include <utils/synchronousprocess.h>
35

36
#include <QCoreApplication>
37 38 39 40

namespace Git {
namespace Internal {

41 42 43 44 45 46 47 48 49
const QLatin1String GitSettings::pathKey("Path");
const QLatin1String GitSettings::pullRebaseKey("PullRebase");
const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate");
const QLatin1String GitSettings::ignoreSpaceChangesInDiffKey("SpaceIgnorantDiff");
const QLatin1String GitSettings::ignoreSpaceChangesInBlameKey("SpaceIgnorantBlame");
const QLatin1String GitSettings::diffPatienceKey("DiffPatience");
const QLatin1String GitSettings::winSetHomeEnvironmentKey("WinSetHomeEnvironment");
const QLatin1String GitSettings::showPrettyFormatKey("DiffPrettyFormat");
const QLatin1String GitSettings::gitkOptionsKey("GitKOptions");
50
const QLatin1String GitSettings::logDiffKey("LogDiff");
51
const QLatin1String GitSettings::repositoryBrowserCmd("RepositoryBrowserCmd");
52

53
GitSettings::GitSettings()
54
{
55
    setSettingsGroup(QLatin1String("Git"));
56

57
    declareKey(binaryPathKey, QLatin1String("git"));
58
    declareKey(timeoutKey, Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
59 60 61 62 63 64 65 66
    declareKey(pathKey, QString());
    declareKey(pullRebaseKey, false);
    declareKey(omitAnnotationDateKey, false);
    declareKey(ignoreSpaceChangesInDiffKey, true);
    declareKey(ignoreSpaceChangesInBlameKey, true);
    declareKey(diffPatienceKey, true);
    declareKey(winSetHomeEnvironmentKey, false);
    declareKey(gitkOptionsKey, QString());
67
    declareKey(showPrettyFormatKey, 2);
68
    declareKey(logDiffKey, false);
69
    declareKey(repositoryBrowserCmd, QString());
70 71
}

72 73 74 75 76 77 78 79
QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
{
    // Locate binary in path if one is specified, otherwise default
    // to pathless binary
    if (ok)
        *ok = true;
    if (errorMessage)
        errorMessage->clear();
80 81

    if (m_binaryPath.isEmpty()) {
82
        const QString binary = binaryPath();
83
        QString currentPath = stringValue(pathKey);
84 85 86
        QString systemPath = QString::fromLocal8Bit(qgetenv("PATH"));
        if (!systemPath.isEmpty()) {
            if (!currentPath.isEmpty())
87
                currentPath.append(Utils::HostOsInfo::pathListSeparator());
88 89
            currentPath.append(systemPath);
        }
90 91 92 93 94 95 96 97 98 99
        // Search in path?
        m_binaryPath = Utils::SynchronousProcess::locateBinary(currentPath, binary);
        if (m_binaryPath.isEmpty()) {
            if (ok)
                *ok = false;
            if (errorMessage)
                *errorMessage = QCoreApplication::translate("Git::Internal::GitSettings",
                                                            "The binary '%1' could not be located in the path '%2'")
                    .arg(binary, currentPath);
        }
100
    }
101 102 103 104 105
    return m_binaryPath;
}

GitSettings &GitSettings::operator = (const GitSettings &s)
{
hjk's avatar
hjk committed
106
    VcsBaseClientSettings::operator =(s);
107
    m_binaryPath.clear();
Tobias Hunger's avatar
Tobias Hunger committed
108
    return *this;
109 110
}

111 112
} // namespace Internal
} // namespace Git