Git: dereference topic result

sometimes tags are annotated, and have different hash than head - now
all will be good with them too.

Change-Id: Ibd66b78e6dbc7f181ba05f45339f2d97bb611602
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Petar Perisin
2013-04-04 12:28:53 +02:00
parent 19a4810ce8
commit 42547062af

View File

@@ -1186,7 +1186,8 @@ bool GitClient::synchronousHeadRefs(const QString &workingDirectory, QStringList
QString *errorMessage)
{
QStringList args;
args << QLatin1String("show-ref") << QLatin1String("--head") << QLatin1String("--abbrev=10");
args << QLatin1String("show-ref") << QLatin1String("--head")
<< QLatin1String("--abbrev=10") << QLatin1String("--dereference");
QByteArray outputText;
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
@@ -1258,15 +1259,21 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
if (!synchronousHeadRefs(workingDirectory, &references))
return QString();
QString tagStart = QLatin1String("refs/tags/");
QString remoteStart = QLatin1String("refs/remotes/");
const QString tagStart(QLatin1String("refs/tags/"));
const QString remoteStart(QLatin1String("refs/remotes/"));
const QString dereference(QLatin1String("^{}"));
QString remoteBranch;
foreach (const QString &ref, references) {
if (ref.startsWith(tagStart))
return data.topic = ref.mid(10);
if (ref.startsWith(remoteStart))
remoteBranch = ref.mid(13);
int derefInd = ref.indexOf(dereference);
if (ref.startsWith(tagStart)) {
return data.topic = ref.mid(tagStart.size(),
(derefInd == -1) ? -1 : derefInd - tagStart.size());
}
if (ref.startsWith(remoteStart)) {
remoteBranch = ref.mid(remoteStart.size(),
(derefInd == -1) ? -1 : derefInd - remoteStart.size());
}
}
// No tag