summaryrefslogtreecommitdiffstats
path: root/plugins/fossil/fossilclient.cpp
blob: aea3fdd65f7f3f716a39509ce74c41a2eeb77b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
/****************************************************************************
**
** Copyright (c) 2018 Artur Shepilko
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "fossilclient.h"
#include "fossileditor.h"
#include "constants.h"

#include <coreplugin/id.h>

#include <vcsbase/vcsbaseplugin.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseeditorconfig.h>
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcscommand.h>

#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>

#include <QSyntaxHighlighter>

#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <QMap>
#include <QRegularExpression>

namespace Fossil {
namespace Internal {

// Parameter widget controlling whitespace diff mode, associated with a parameter
class FossilDiffConfig : public VcsBase::VcsBaseEditorConfig
{
    Q_OBJECT

public:
    FossilDiffConfig(FossilClient *client, QToolBar *toolBar) :
        VcsBase::VcsBaseEditorConfig(toolBar)
    {
        QTC_ASSERT(client, return);

        VcsBase::VcsBaseClientSettings &settings = client->settings();
        FossilClient::SupportedFeatures features = client->supportedFeatures();

        addButton(tr("Reload"), Utils::Icons::RELOAD.icon());
        if (features.testFlag(FossilClient::DiffIgnoreWhiteSpaceFeature)) {
            mapSetting(addToggleButton("-w", tr("Ignore All Whitespace")),
                       settings.boolPointer(FossilSettings::diffIgnoreAllWhiteSpaceKey));
            mapSetting(addToggleButton("--strip-trailing-cr", tr("Strip Trailing CR")),
                       settings.boolPointer(FossilSettings::diffStripTrailingCRKey));
        }
    }
};

// Parameter widget controlling annotate/blame mode
class FossilAnnotateConfig : public VcsBase::VcsBaseEditorConfig
{
    Q_OBJECT

public:
    FossilAnnotateConfig(FossilClient *client, QToolBar *toolBar) :
        VcsBase::VcsBaseEditorConfig(toolBar)
    {
        QTC_ASSERT(client, return);

        VcsBase::VcsBaseClientSettings &settings = client->settings();
        FossilClient::SupportedFeatures features = client->supportedFeatures();

        if (features.testFlag(FossilClient::AnnotateBlameFeature)) {
            mapSetting(addToggleButton("|BLAME|", tr("Show Committers")),
                       settings.boolPointer(FossilSettings::annotateShowCommittersKey));
        }

        // Force listVersions setting to false by default.
        // This way the annotated line number would not get offset by the version list.
        settings.setValue(FossilSettings::annotateListVersionsKey, false);

        mapSetting(addToggleButton("--log", tr("List Versions")),
                   settings.boolPointer(FossilSettings::annotateListVersionsKey));
    }
};

class FossilLogCurrentFileConfig : public VcsBase::VcsBaseEditorConfig
{
    Q_OBJECT

public:
    FossilLogCurrentFileConfig(FossilClient *client, QToolBar *toolBar) :
        VcsBase::VcsBaseEditorConfig(toolBar)
    {
        QTC_ASSERT(client, return);

        addButton(tr("Reload"), Utils::Icons::RELOAD.icon());
    }

};

class FossilLogConfig : public VcsBase::VcsBaseEditorConfig
{
    Q_OBJECT

public:
    FossilLogConfig(FossilClient *client, QToolBar *toolBar) :
        VcsBase::VcsBaseEditorConfig(toolBar),
        m_client(client)
    {
        QTC_ASSERT(client, return);

        addButton(tr("Reload"), Utils::Icons::RELOAD.icon());
        addLineageComboBox();
        addVerboseToggleButton();
        addItemTypeComboBox();
    }

    void addLineageComboBox()
    {
        VcsBase::VcsBaseClientSettings &settings = m_client->settings();

        // ancestors/descendants filter
        // This is a positional argument not an option.
        // Normally it takes the checkin/branch/tag as an additional parameter
        // (trunk by default)
        // So we kludge this by coding it as a meta-option (pipe-separated),
        // then parse it out in arguments.
        // All-choice is a blank argument with no additional parameters
        QList<ComboBoxItem> lineageFilterChoices;
        lineageFilterChoices << ComboBoxItem(tr("Ancestors"), "ancestors")
                        << ComboBoxItem(tr("Descendants"), "descendants")
                        << ComboBoxItem(tr("Unfiltered"), "");
        mapSetting(addComboBox(QStringList("|LINEAGE|%1|current"), lineageFilterChoices),
                   settings.stringPointer(FossilSettings::timelineLineageFilterKey));
    }

    void addVerboseToggleButton()
    {
        VcsBase::VcsBaseClientSettings &settings = m_client->settings();

        // show files
        mapSetting(addToggleButton("-showfiles", tr("Verbose"),
                                   tr("Show files changed in each revision")),
                   settings.boolPointer(FossilSettings::timelineVerboseKey));
    }

    void addItemTypeComboBox()
    {
        VcsBase::VcsBaseClientSettings &settings = m_client->settings();

        // option: -t <val>
        const QList<ComboBoxItem> itemTypeChoices = {
            ComboBoxItem(tr("All Items"), "all"),
            ComboBoxItem(tr("File Commits"), "ci"),
            ComboBoxItem(tr("Technical Notes"), "e"),
            ComboBoxItem(tr("Tags"), "g"),
            ComboBoxItem(tr("Tickets"), "t"),
            ComboBoxItem(tr("Wiki Commits"), "w")
        };

        // here we setup the ComboBox to map to the "-t <val>", which will produce
        // the enquoted option-values (e.g "-t all").
        // Fossil expects separate arguments for option and value ( i.e. "-t" "all")
        // so we need to handle the splitting explicitly in arguments().
        mapSetting(addComboBox(QStringList("-t %1"), itemTypeChoices),
                   settings.stringPointer(FossilSettings::timelineItemTypeKey));
    }

    QStringList arguments() const final
    {
        QStringList args;

        // split "-t val" => "-t" "val"
        foreach (const QString &arg, VcsBaseEditorConfig::arguments()) {
            if (arg.startsWith("-t")) {
                args << arg.split(' ');

            } else if (arg.startsWith('|')){
                // meta-option: "|OPT|val|extra1|..."
                QStringList params = arg.split('|');
                QString option = params[1];
                for (int i = 2; i < params.size(); ++i) {
                    if (option == "LINEAGE" && params[i].isEmpty()) {
                        // empty lineage filter == Unfiltered
                        break;
                    }
                    args << params[i];
                }

            } else {
                args << arg;
            }
        }

        return args;
    }

private:
    FossilClient *m_client;
};

unsigned FossilClient::makeVersionNumber(int major, int minor, int patch)
{
    return (QString().setNum(major).toUInt(0,16) << 16) +
           (QString().setNum(minor).toUInt(0,16) << 8) +
           (QString().setNum(patch).toUInt(0,16));
}

static inline QString versionPart(unsigned part)
{
    return QString::number(part & 0xff, 16);
}

QString FossilClient::makeVersionString(unsigned version)
{
    return QString::fromLatin1("%1.%2.%3")
                    .arg(versionPart(version >> 16))
                    .arg(versionPart(version >> 8))
                    .arg(versionPart(version));
}

FossilClient::FossilClient() : VcsBase::VcsBaseClient(new FossilSettings)
{
    setDiffConfigCreator([this](QToolBar *toolBar) {
        return new FossilDiffConfig(this, toolBar);
    });
}

unsigned int FossilClient::synchronousBinaryVersion() const
{
    if (settings().binaryPath().isEmpty())
        return 0;

    QStringList args("version");

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(QString(), args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return 0;

    QString output = response.stdOut();
    output = output.trimmed();

    // fossil version:
    // "This is fossil version 1.27 [ccdefa355b] 2013-09-30 11:47:18 UTC"
    QRegularExpression versionPattern("(\\d+)\\.(\\d+)");
    QTC_ASSERT(versionPattern.isValid(), return 0);
    QRegularExpressionMatch versionMatch = versionPattern.match(output);
    QTC_ASSERT(versionMatch.hasMatch(), return 0);
    const int major = versionMatch.captured(1).toInt();
    const int minor = versionMatch.captured(2).toInt();
    const int patch = 0;
    return makeVersionNumber(major,minor,patch);
}

QList<BranchInfo> FossilClient::branchListFromOutput(const QString &output, const BranchInfo::BranchFlags defaultFlags)
{
    // Branch list format:
    // "  branch-name"
    // "* current-branch"
    return Utils::transform(output.split('\n', QString::SkipEmptyParts), [=](const QString& l) {
        const QString &name = l.mid(2);
        QTC_ASSERT(!name.isEmpty(), return BranchInfo());
        const BranchInfo::BranchFlags flags = (l.startsWith("* ") ? defaultFlags | BranchInfo::Current : defaultFlags);
        return BranchInfo(name, flags);
    });
}

BranchInfo FossilClient::synchronousCurrentBranch(const QString &workingDirectory)
{
    if (workingDirectory.isEmpty())
        return BranchInfo();

    // First try to get the current branch from the list of open branches
    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, {"branch", "list"});
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return BranchInfo();

    const QString output = sanitizeFossilOutput(response.stdOut());
    BranchInfo currentBranch = Utils::findOrDefault(branchListFromOutput(output), [](const BranchInfo &b) {
        return b.isCurrent();
    });

    if (!currentBranch.isCurrent()) {
        // If not available from open branches, request it from the list of closed branches.
        const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, {"branch", "list", "--closed"});
        if (response.result != Utils::SynchronousProcessResponse::Finished)
            return BranchInfo();

        const QString output = sanitizeFossilOutput(response.stdOut());
        currentBranch = Utils::findOrDefault(branchListFromOutput(output, BranchInfo::Closed), [](const BranchInfo &b) {
            return b.isCurrent();
        });
    }

    return currentBranch;
}

QList<BranchInfo> FossilClient::synchronousBranchQuery(const QString &workingDirectory)
{
    // Return a list of all branches, including the closed ones.
    // Sort the list by branch name.

    if (workingDirectory.isEmpty())
        return QList<BranchInfo>();

    // First get list of open branches
    Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, {"branch", "list"});
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return QList<BranchInfo>();

    QString output = sanitizeFossilOutput(response.stdOut());
    QList<BranchInfo> branches = branchListFromOutput(output);

    // Append a list of closed branches.
    response = vcsFullySynchronousExec(workingDirectory, {"branch", "list", "--closed"});
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return QList<BranchInfo>();

    output = sanitizeFossilOutput(response.stdOut());
    branches.append(branchListFromOutput(output, BranchInfo::Closed));

    std::sort(branches.begin(), branches.end(),
          [](const BranchInfo &a, const BranchInfo &b) { return a.name() < b.name(); });
    return branches;
}

QStringList FossilClient::parseRevisionCommentLine(const QString &commentLine)
{
    // "comment:      This is a (test) commit message (user: the.name)"

    const QRegularExpression commentRx("^comment:\\s+(.*)\\s\\(user:\\s(.*)\\)$",
                                       QRegularExpression::CaseInsensitiveOption);
    QTC_ASSERT(commentRx.isValid(), return QStringList());

    const QRegularExpressionMatch match = commentRx.match(commentLine);
    if (!match.hasMatch())
        return QStringList();

    return QStringList({match.captured(1), match.captured(2)});
}

RevisionInfo FossilClient::synchronousRevisionQuery(const QString &workingDirectory, const QString &id,
                                                    bool getCommentMsg) const
{
    // Query details of the given revision/check-out id,
    // if none specified, provide information about current revision
    if (workingDirectory.isEmpty())
        return RevisionInfo();

    QStringList args("info");
    if (!id.isEmpty())
        args << id;

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(
                workingDirectory, args, Utils::ShellCommand::SuppressCommandLogging);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return RevisionInfo();

    const QString output = sanitizeFossilOutput(response.stdOut());

    QString revisionId;
    QString parentId;
    QStringList mergeParentIds;
    QString commentMsg;
    QString committer;

    const QRegularExpression idRx("([0-9a-f]{5,40})");
    QTC_ASSERT(idRx.isValid(), return RevisionInfo());

    for (const QString &l : output.split('\n', QString::SkipEmptyParts)) {
        if (l.startsWith("checkout: ", Qt::CaseInsensitive)
            || l.startsWith("uuid: ", Qt::CaseInsensitive)) {
            const QRegularExpressionMatch idMatch = idRx.match(l);
            QTC_ASSERT(idMatch.hasMatch(), return RevisionInfo());
            revisionId = idMatch.captured(1);

        } else if (l.startsWith("parent: ", Qt::CaseInsensitive)){
            const QRegularExpressionMatch idMatch = idRx.match(l);
            if (idMatch.hasMatch())
                parentId = idMatch.captured(1);
        } else if (l.startsWith("merged-from: ", Qt::CaseInsensitive)) {
            const QRegularExpressionMatch idMatch = idRx.match(l);
            if (idMatch.hasMatch())
                mergeParentIds.append(idMatch.captured(1));
        } else if (getCommentMsg
                   && l.startsWith("comment: ", Qt::CaseInsensitive)) {
            const QStringList commentLineParts = parseRevisionCommentLine(l);
            commentMsg = commentLineParts.value(0);
            committer = commentLineParts.value(1);
        }
    }

    // make sure id at least partially matches the retrieved revisionId
    QTC_ASSERT(revisionId.startsWith(id, Qt::CaseInsensitive), return RevisionInfo());

    if (parentId.isEmpty())
        parentId = revisionId;  // root

    return RevisionInfo(revisionId, parentId, mergeParentIds, commentMsg, committer);
}

QStringList FossilClient::synchronousTagQuery(const QString &workingDirectory, const QString &id)
{
    // Return a list of tags for the given revision.
    // If no revision specified, all defined tags are listed.
    // Tag list includes branch names.

    if (workingDirectory.isEmpty())
        return QStringList();

    QStringList args({"tag", "list"});

    if (!id.isEmpty())
        args << id;

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return QStringList();

    const QString output = sanitizeFossilOutput(response.stdOut());

    return output.split('\n', QString::SkipEmptyParts);
}

RepositorySettings FossilClient::synchronousSettingsQuery(const QString &workingDirectory)
{
    if (workingDirectory.isEmpty())
        return RepositorySettings();

    RepositorySettings repoSettings;

    repoSettings.user = synchronousUserDefaultQuery(workingDirectory);
    if (repoSettings.user.isEmpty())
        repoSettings.user = settings().stringValue(FossilSettings::userNameKey);

    const QStringList args("settings");

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return RepositorySettings();

    const QString output = sanitizeFossilOutput(response.stdOut());

    for (const QString &line : output.split('\n', QString::SkipEmptyParts)) {
        // parse settings line:
        // <property> <(local|global)> <value>
        // Fossil properties are case-insensitive; force them to lower-case.
        // Values may be in mixed-case; force lower-case for fixed values.
        const QStringList fields = line.split(' ', QString::SkipEmptyParts);

        const QString property = fields.at(0).toLower();
        const QString value = (fields.size() >= 3 ? fields.at(2) : QString());
        const QString lcValue = value.toLower();

        if (property == "autosync") {
            if (lcValue == "on"
                || lcValue == "1")
                repoSettings.autosync = RepositorySettings::AutosyncOn;
            else if (lcValue == "off"
                     || lcValue == "0")
                repoSettings.autosync = RepositorySettings::AutosyncOff;
            else if (lcValue == "pullonly"
                     || lcValue == "2")
                repoSettings.autosync = RepositorySettings::AutosyncPullOnly;
        }
        else if (property == "ssl-identity") {
            repoSettings.sslIdentityFile = value;
        }
    }

    return repoSettings;
}

bool FossilClient::synchronousSetSetting(const QString &workingDirectory,
                                         const QString &property, const QString &value, bool isGlobal)
{
    // set a repository property to the given value
    // if no value is given, unset the property

    if (workingDirectory.isEmpty() || property.isEmpty())
        return false;

    QStringList args;
    if (value.isEmpty())
        args << "unset" << property;
    else
        args << "settings" << property << value;

    if (isGlobal)
        args << "--global";

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    return (response.result == Utils::SynchronousProcessResponse::Finished);
}


bool FossilClient::synchronousConfigureRepository(const QString &workingDirectory, const RepositorySettings &newSettings,
                                                  const RepositorySettings &currentSettings)
{
    if (workingDirectory.isEmpty())
        return false;

    // apply updated settings vs. current setting if given
    const bool applyAll = (currentSettings == RepositorySettings());

    if (!newSettings.user.isEmpty()
        && (applyAll
            || newSettings.user != currentSettings.user)
        && !synchronousSetUserDefault(workingDirectory, newSettings.user)){
        return false;
    }

    if ((applyAll
         || newSettings.sslIdentityFile != currentSettings.sslIdentityFile)
        && !synchronousSetSetting(workingDirectory, "ssl-identity", newSettings.sslIdentityFile)){
        return false;
    }

    if (applyAll
        || newSettings.autosync != currentSettings.autosync) {
        QString value;
        switch (newSettings.autosync) {
        case RepositorySettings::AutosyncOff:
            value = "off";
            break;
        case RepositorySettings::AutosyncOn:
            value = "on";
            break;
        case RepositorySettings::AutosyncPullOnly:
            value = "pullonly";
            break;
        }

        if (!synchronousSetSetting(workingDirectory, "autosync", value))
            return false;
    }

    return true;
}

QString FossilClient::synchronousUserDefaultQuery(const QString &workingDirectory)
{
    if (workingDirectory.isEmpty())
        return QString();

    const QStringList args({"user", "default"});

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return QString();

    QString output = sanitizeFossilOutput(response.stdOut());

    return output.trimmed();
}

bool FossilClient::synchronousSetUserDefault(const QString &workingDirectory, const QString &userName)
{
    if (workingDirectory.isEmpty() || userName.isEmpty())
        return false;

    // set repository-default user
    const QStringList args({"user", "default", userName, "--user", userName});
    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    return (response.result == Utils::SynchronousProcessResponse::Finished);
}

QString FossilClient::synchronousGetRepositoryURL(const QString &workingDirectory)
{
    if (workingDirectory.isEmpty())
        return QString();

    const QStringList args("remote-url");

    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return QString();

    QString output = sanitizeFossilOutput(response.stdOut());
    output = output.trimmed();

    // Fossil returns "off" when no remote-url is set.
    if (output.isEmpty() || output.toLower() == "off")
        return QString();

    return output;
}

QString FossilClient::synchronousTopic(const QString &workingDirectory)
{
    if (workingDirectory.isEmpty())
        return QString();

    // return current branch name

    const BranchInfo branchInfo = synchronousCurrentBranch(workingDirectory);
    if (branchInfo.name().isEmpty())
        return QString();

    return branchInfo.name();
}

bool FossilClient::synchronousCreateRepository(const QString &workingDirectory, const QStringList &extraOptions)
{
    VcsBase::VcsOutputWindow *outputWindow = VcsBase::VcsOutputWindow::instance();

    // init repository file of the same name as the working directory
    // use the configured default repository location for path
    // use the configured default user for admin

    const QString repoName = QDir(workingDirectory).dirName().simplified();
    const QString repoPath = settings().stringValue(FossilSettings::defaultRepoPathKey);
    const QString adminUser = settings().stringValue(FossilSettings::userNameKey);

    if (repoName.isEmpty() || repoPath.isEmpty())
        return false;

    // @TODO: handle spaces in the path
    // @TODO: what about --template options?

    const Utils::FileName fullRepoName = Utils::FileName::fromStringWithExtension(repoName, Constants::FOSSIL_FILE_SUFFIX);
    const Utils::FileName repoFilePath = Utils::FileName::fromString(repoPath)
            .appendPath(fullRepoName.toString());
    QStringList args(vcsCommandString(CreateRepositoryCommand));
    if (!adminUser.isEmpty())
        args << "--admin-user" << adminUser;
    args << extraOptions << repoFilePath.toUserOutput();
    Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return false;

    QString output = sanitizeFossilOutput(response.stdOut());
    outputWindow->append(output);

    // check out the created repository file into the working directory

    args.clear();
    response.clear();
    output.clear();

    args << "open" << repoFilePath.toUserOutput();
    response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return false;

    output = sanitizeFossilOutput(response.stdOut());
    outputWindow->append(output);

    // set user default to admin if specified

    if (!adminUser.isEmpty()) {
        args.clear();
        response.clear();
        output.clear();

        args << "user" << "default" << adminUser << "--user" << adminUser;
        response = vcsFullySynchronousExec(workingDirectory, args);
        if (response.result != Utils::SynchronousProcessResponse::Finished)
            return false;

        QString output = sanitizeFossilOutput(response.stdOut());
        outputWindow->append(output);
    }

    resetCachedVcsInfo(workingDirectory);

    return true;
}

bool FossilClient::synchronousMove(const QString &workingDir,
                                   const QString &from, const QString &to,
                                   const QStringList &extraOptions)
{
    // Fossil move does not rename actual file on disk, only changes it in repo
    // So try to move the actual file first, then move it in repo to preserve
    // history in case actual move fails.

    if (!QFile::rename(from, to))
        return false;

    QStringList args(vcsCommandString(MoveCommand));
    args << extraOptions << from << to;
    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDir, args);
    return (response.result == Utils::SynchronousProcessResponse::Finished);
}

bool FossilClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions)
{
    const QString remoteLocation = (!srcLocation.isEmpty() ? srcLocation : synchronousGetRepositoryURL(workingDir));
    if (remoteLocation.isEmpty())
        return false;

    QStringList args({vcsCommandString(PullCommand), remoteLocation});
    args << extraOptions;
    // Disable UNIX terminals to suppress SSH prompting
    const unsigned flags =
            VcsBase::VcsCommand::SshPasswordPrompt
            | VcsBase::VcsCommand::ShowStdOut
            | VcsBase::VcsCommand::ShowSuccessMessage;
    const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
    const bool success = (resp.result == Utils::SynchronousProcessResponse::Finished);
    if (success)
        emit changed(QVariant(workingDir));
    return success;
}

bool FossilClient::synchronousPush(const QString &workingDir, const QString &dstLocation, const QStringList &extraOptions)
{
    const QString remoteLocation = (!dstLocation.isEmpty() ? dstLocation : synchronousGetRepositoryURL(workingDir));
    if (remoteLocation.isEmpty())
        return false;

    QStringList args({vcsCommandString(PushCommand), remoteLocation});
    args << extraOptions;
    // Disable UNIX terminals to suppress SSH prompting
    const unsigned flags =
            VcsBase::VcsCommand::SshPasswordPrompt
            | VcsBase::VcsCommand::ShowStdOut
            | VcsBase::VcsCommand::ShowSuccessMessage;
    const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
    return (resp.result == Utils::SynchronousProcessResponse::Finished);
}

void FossilClient::commit(const QString &repositoryRoot, const QStringList &files,
                          const QString &commitMessageFile, const QStringList &extraOptions)
{
    VcsBaseClient::commit(repositoryRoot, files, commitMessageFile,
                          QStringList(extraOptions) << "-M" << commitMessageFile);
}

VcsBase::VcsBaseEditorWidget *FossilClient::annotate(
        const QString &workingDir, const QString &file, const QString &revision,
        int lineNumber, const QStringList &extraOptions)
{
    // 'fossil annotate' command has a variant 'fossil blame'.
    // blame command attributes a committing username to source lines,
    // annotate shows line numbers

    QString vcsCmdString = vcsCommandString(AnnotateCommand);
    const Core::Id kind = vcsEditorKind(AnnotateCommand);
    const QString id = VcsBase::VcsBaseEditor::getTitleId(workingDir, QStringList(file), revision);
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VcsBase::VcsBaseEditor::getSource(workingDir, file);

    VcsBase::VcsBaseEditorWidget *editor = createVcsEditor(kind, title, source,
                                                  VcsBase::VcsBaseEditor::getCodec(source),
                                                  vcsCmdString.toLatin1().constData(), id);

    auto *fossilEditor = qobject_cast<FossilEditorWidget *>(editor);
    QTC_ASSERT(fossilEditor, return editor);

    if (!fossilEditor->editorConfig()) {
        if (VcsBase::VcsBaseEditorConfig *editorConfig = createAnnotateEditor(fossilEditor)) {
            editorConfig->setBaseArguments(extraOptions);
            // editor has been just created, createVcsEditor() didn't set a configuration widget yet
            connect(editorConfig, &VcsBase::VcsBaseEditorConfig::commandExecutionRequested,
                    [=]() {
                        const int line = VcsBase::VcsBaseEditor::lineNumberOfCurrentEditor();
                        return this->annotate(workingDir, file, revision, line, editorConfig->arguments());
                    } );
            fossilEditor->setEditorConfig(editorConfig);
        }
    }
    QStringList effectiveArgs = extraOptions;
    if (VcsBase::VcsBaseEditorConfig *editorConfig = fossilEditor->editorConfig())
        effectiveArgs = editorConfig->arguments();

    VcsBase::VcsCommand *cmd = createCommand(workingDir, fossilEditor);

    // here we introduce a "|BLAME|" meta-option to allow both annotate and blame modes
    int pos = effectiveArgs.indexOf("|BLAME|");
    if (pos != -1) {
        vcsCmdString = "blame";
        effectiveArgs.removeAt(pos);
    }
    QStringList args(vcsCmdString);
    if (!revision.isEmpty()
        && supportedFeatures().testFlag(AnnotateRevisionFeature))
        args << "-r" << revision;

    args << effectiveArgs << file;

    // When version list requested, ignore the source line.
    if (args.contains("--log"))
        lineNumber = -1;
    cmd->setCookie(lineNumber);

    enqueueJob(cmd, args);
    return fossilEditor;
}

bool FossilClient::isVcsFileOrDirectory(const Utils::FileName &fileName) const
{
    // false for any dir or file other than fossil checkout db-file
    return fileName.toFileInfo().isFile()
           && !fileName.fileName().compare(Constants::FOSSILREPO,
                                           Utils::HostOsInfo::fileNameCaseSensitivity());
}

QString FossilClient::findTopLevelForFile(const QFileInfo &file) const
{
    const QString repositoryCheckFile = Constants::FOSSILREPO;
    return file.isDir() ?
                VcsBase::VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(),
                                                                   repositoryCheckFile) :
                VcsBase::VcsBasePlugin::findRepositoryForDirectory(file.absolutePath(),
                                                                   repositoryCheckFile);
}

bool FossilClient::managesFile(const QString &workingDirectory, const QString &fileName) const
{
    const QStringList args({"finfo", fileName});
    const Utils::SynchronousProcessResponse response = vcsFullySynchronousExec(workingDirectory, args);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return false;
    QString output = sanitizeFossilOutput(response.stdOut());
    return !output.startsWith("no history for file", Qt::CaseInsensitive);
}

unsigned int FossilClient::binaryVersion() const
{
    static unsigned int cachedBinaryVersion = 0;
    static QString cachedBinaryPath;

    const QString currentBinaryPath = settings().binaryPath().toString();

    if (currentBinaryPath.isEmpty())
        return 0;

    // Invalidate cache on failed version result.
    // Assume that fossil client options have been changed and will change again.
    if (!cachedBinaryVersion
        || currentBinaryPath != cachedBinaryPath) {
        cachedBinaryVersion = synchronousBinaryVersion();
        if (cachedBinaryVersion)
            cachedBinaryPath = currentBinaryPath;
        else
            cachedBinaryPath.clear();
    }

    return cachedBinaryVersion;
}

QString FossilClient::binaryVersionString() const
{
    const unsigned int version = binaryVersion();

    // Fossil itself does not report patch version, only maj.min
    // Here we include the patch part for general convention consistency

    return makeVersionString(version);
}

FossilClient::SupportedFeatures FossilClient::supportedFeatures() const
{
    // use for legacy client support to test for feature presence
    // e.g. supportedFeatures().testFlag(TimelineWidthFeature)

    SupportedFeatures features = AllSupportedFeatures; // all inclusive by default (~0U)

    const unsigned int version = binaryVersion();

    if (version < 0x20400) {
        features &= ~AnnotateRevisionFeature;
        if (version < 0x13000)
            features &= ~TimelinePathFeature;
        if (version < 0x12900)
            features &= ~DiffIgnoreWhiteSpaceFeature;
        if (version < 0x12800) {
            features &= ~AnnotateBlameFeature;
            features &= ~TimelineWidthFeature;
        }
    }

    return features;
}

void FossilClient::view(const QString &source, const QString &id, const QStringList &extraOptions)
{
    QStringList args("diff");

    const QFileInfo fi(source);
    const QString workingDirectory = fi.isFile() ? fi.absolutePath() : source;

    RevisionInfo revisionInfo = synchronousRevisionQuery(workingDirectory,id);

    args << "--from" << revisionInfo.parentId
         << "--to" << revisionInfo.id
         << "-v"
         << extraOptions;

    const Core::Id kind = vcsEditorKind(DiffCommand);
    const QString title = vcsEditorTitle(vcsCommandString(DiffCommand), id);

    VcsBase::VcsBaseEditorWidget *editor = createVcsEditor(kind, title, source,
                                                           VcsBase::VcsBaseEditor::getCodec(source), "view", id);
    editor->setWorkingDirectory(workingDirectory);

    enqueueJob(createCommand(workingDirectory, editor), args);
}

class FossilLogHighlighter : QSyntaxHighlighter
{
public:
    explicit FossilLogHighlighter(QTextDocument *parent);
    virtual void highlightBlock(const QString &text) final;

private:
    const QRegularExpression m_revisionIdRx;
    const QRegularExpression m_dateRx;
};

FossilLogHighlighter::FossilLogHighlighter(QTextDocument * parent) :
    QSyntaxHighlighter(parent),
    m_revisionIdRx(Constants::CHANGESET_ID),
    m_dateRx("([0-9]{4}-[0-9]{2}-[0-9]{2})")
{
    QTC_CHECK(m_revisionIdRx.isValid());
    QTC_CHECK(m_dateRx.isValid());
}

void FossilLogHighlighter::highlightBlock(const QString &text)
{
    // Match the revision-ids and dates -- highlight them for convenience.

    // Format revision-ids
    QRegularExpressionMatchIterator i = m_revisionIdRx.globalMatch(text);
    while (i.hasNext()) {
        const QRegularExpressionMatch revisionIdMatch = i.next();
        QTextCharFormat charFormat = format(0);
        charFormat.setForeground(Qt::darkBlue);
        //charFormat.setFontItalic(true);
        setFormat(revisionIdMatch.capturedStart(0), revisionIdMatch.capturedLength(0), charFormat);
    }

    // Format dates
    i = m_dateRx.globalMatch(text);
    while (i.hasNext()) {
        const QRegularExpressionMatch dateMatch = i.next();
        QTextCharFormat charFormat = format(0);
        charFormat.setForeground(Qt::darkBlue);
        charFormat.setFontWeight(QFont::DemiBold);
        setFormat(dateMatch.capturedStart(0), dateMatch.capturedLength(0), charFormat);
    }
}

void FossilClient::log(const QString &workingDir, const QStringList &files,
                       const QStringList &extraOptions,
                       bool enableAnnotationContextMenu)
{
    // Show timeline for both repository and a file or path (--path <file-or-path>)
    // When used for log repository, the files list is empty

    // LEGACY:fallback to log current file with legacy clients
    SupportedFeatures features = supportedFeatures();
    if (!files.isEmpty()
        && !features.testFlag(TimelinePathFeature)) {
        logCurrentFile(workingDir, files, extraOptions, enableAnnotationContextMenu);
        return;
    }

    const QString vcsCmdString = vcsCommandString(LogCommand);
    const Core::Id kind = vcsEditorKind(LogCommand);
    const QString id = VcsBase::VcsBaseEditor::getTitleId(workingDir, files);
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VcsBase::VcsBaseEditor::getSource(workingDir, files);
    VcsBase::VcsBaseEditorWidget *editor = createVcsEditor(kind, title, source,
                                                           VcsBase::VcsBaseEditor::getCodec(source),
                                                           vcsCmdString.toLatin1().constData(), id);

    auto *fossilEditor = qobject_cast<FossilEditorWidget *>(editor);
    QTC_ASSERT(fossilEditor, return);

    fossilEditor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);

    if (!fossilEditor->editorConfig()) {
        if (VcsBase::VcsBaseEditorConfig *editorConfig = createLogEditor(fossilEditor)) {
            editorConfig->setBaseArguments(extraOptions);
            // editor has been just created, createVcsEditor() didn't set a configuration widget yet
            connect(editorConfig, &VcsBase::VcsBaseEditorConfig::commandExecutionRequested,
                [=]() { this->log(workingDir, files, editorConfig->arguments(), enableAnnotationContextMenu); } );
            fossilEditor->setEditorConfig(editorConfig);
        }
    }
    QStringList effectiveArgs = extraOptions;
    if (VcsBase::VcsBaseEditorConfig *editorConfig = fossilEditor->editorConfig())
        effectiveArgs = editorConfig->arguments();

    //@TODO: move highlighter and widgets to fossil editor sources.

    new FossilLogHighlighter(fossilEditor->document());

    QStringList args(vcsCmdString);
    args << effectiveArgs;
    if (!files.isEmpty())
         args << "--path" << files;
    enqueueJob(createCommand(workingDir, fossilEditor), args);
}

void FossilClient::logCurrentFile(const QString &workingDir, const QStringList &files,
                                  const QStringList &extraOptions,
                                  bool enableAnnotationContextMenu)
{
    // Show commit history for the given file/file-revision
    // NOTE: 'fossil finfo' shows full history from all branches.

    // With newer clients, 'fossil timeline' can handle both repository and file
    SupportedFeatures features = supportedFeatures();
    if (features.testFlag(TimelinePathFeature)) {
        log(workingDir, files, extraOptions, enableAnnotationContextMenu);
        return;
    }

    const QString vcsCmdString = "finfo";
    const Core::Id kind = vcsEditorKind(LogCommand);
    const QString id = VcsBase::VcsBaseEditor::getTitleId(workingDir, files);
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VcsBase::VcsBaseEditor::getSource(workingDir, files);
    VcsBase::VcsBaseEditorWidget *editor = createVcsEditor(kind, title, source,
                                                           VcsBase::VcsBaseEditor::getCodec(source),
                                                           vcsCmdString.toLatin1().constData(), id);

    auto *fossilEditor = qobject_cast<FossilEditorWidget *>(editor);
    QTC_ASSERT(fossilEditor, return);

    fossilEditor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);

    if (!fossilEditor->editorConfig()) {
        if (VcsBase::VcsBaseEditorConfig *editorConfig = createLogCurrentFileEditor(fossilEditor)) {
            editorConfig->setBaseArguments(extraOptions);
            // editor has been just created, createVcsEditor() didn't set a configuration widget yet
            connect(editorConfig, &VcsBase::VcsBaseEditorConfig::commandExecutionRequested,
                [=]() { this->logCurrentFile(workingDir, files, editorConfig->arguments(), enableAnnotationContextMenu); } );
            fossilEditor->setEditorConfig(editorConfig);
        }
    }
    QStringList effectiveArgs = extraOptions;
    if (VcsBase::VcsBaseEditorConfig *editorConfig = fossilEditor->editorConfig())
        effectiveArgs = editorConfig->arguments();

    //@TODO: move highlighter and widgets to fossil editor sources.

    new FossilLogHighlighter(fossilEditor->document());

    QStringList args(vcsCmdString);
    args << effectiveArgs << files;
    enqueueJob(createCommand(workingDir, fossilEditor), args);
}

void FossilClient::revertFile(const QString &workingDir,
                              const QString &file,
                              const QString &revision,
                              const QStringList &extraOptions)
{
    QStringList args(vcsCommandString(RevertCommand));
    if (!revision.isEmpty())
        args << "-r" << revision;

    args << extraOptions << file;

    // Indicate file list
    VcsBase::VcsCommand *cmd = createCommand(workingDir);
    cmd->setCookie(QStringList(workingDir + "/" + file));
    connect(cmd, &VcsBase::VcsCommand::success, this, &VcsBase::VcsBaseClient::changed, Qt::QueuedConnection);
    enqueueJob(cmd, args);
}

void FossilClient::revertAll(const QString &workingDir, const QString &revision, const QStringList &extraOptions)
{
    // Fossil allows whole tree revert to latest revision (effectively undoing uncommitted changes).
    // However it disallows revert to a specific revision for the whole tree, only for selected files.
    // Use checkout --force command for such case.
    // NOTE: all uncommitted changes will not be backed up by checkout, unlike revert.
    //       Thus undo for whole tree revert should not be possible.

    QStringList args;
    if (revision.isEmpty()) {
        args << vcsCommandString(RevertCommand)
             << extraOptions;

    } else {
        args << "checkout" << revision
             << "--force"
             << extraOptions;
    }

    // Indicate repository change
    VcsBase::VcsCommand *cmd = createCommand(workingDir);
    cmd->setCookie(QStringList(workingDir));
    connect(cmd, &VcsBase::VcsCommand::success, this, &VcsBase::VcsBaseClient::changed, Qt::QueuedConnection);
    enqueueJob(createCommand(workingDir), args);
}

QString FossilClient::sanitizeFossilOutput(const QString &output) const
{
#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
    // Strip possible extra '\r' in output from the Fossil client on Windows.

    // Fossil client contained a long-standing bug which caused an extraneous '\r'
    // added to output lines from certain commands in excess of the expected <CR/LF>.
    // While the output appeared normal on a terminal, in non-interactive context
    // it would get incorrectly split, resulting in extra empty lines.
    // Bug fix is fairly recent, so for compatibility we need to strip the '\r'.
    QString result(output);
    return result.remove('\r');
#else
    return output;
#endif
}

QString FossilClient::vcsCommandString(VcsCommandTag cmd) const
{
    // override specific client commands
    // otherwise return baseclient command

    switch (cmd) {
    case RemoveCommand: return QString("rm");
    case MoveCommand: return QString("mv");
    case LogCommand: return QString("timeline");

    default: return VcsBaseClient::vcsCommandString(cmd);
    }
}

Core::Id FossilClient::vcsEditorKind(VcsCommandTag cmd) const
{
    switch (cmd) {
    case AnnotateCommand:
        return Constants::ANNOTATELOG_ID;
    case DiffCommand:
        return Constants::DIFFLOG_ID;
    case LogCommand:
        return Constants::FILELOG_ID;
    default:
        return Core::Id();
    }
}

QStringList FossilClient::revisionSpec(const QString &revision) const
{
    // Pass the revision verbatim.
    // Fossil uses a variety of ways to spec the revisions.
    // In most cases revision is passed directly (SHA1) or via tag.
    // Tag name may need to be prefixed with tag: to disambiguate it from hex (beef).
    // Handle the revision option per specific command (e.g. diff, revert ).

    QStringList args;
    if (!revision.isEmpty())
        args << revision;
    return args;
}

FossilClient::StatusItem FossilClient::parseStatusLine(const QString &line) const
{
    StatusItem item;

    // Ref: fossil source 'src/checkin.c' status_report()
    // Expect at least one non-leading blank space.

    int pos = line.indexOf(' ');

    if (line.isEmpty() || pos < 1)
        return StatusItem();

    QString label(line.left(pos));
    QString flags;

    if (label == "EDITED")
        flags = Constants::FSTATUS_EDITED;
    else if (label == "ADDED")
        flags = Constants::FSTATUS_ADDED;
    else if (label == "RENAMED")
        flags = Constants::FSTATUS_RENAMED;
    else if (label == "DELETED")
        flags = Constants::FSTATUS_DELETED;
    else if (label == "MISSING")
        flags = "Missing";
    else if (label == "ADDED_BY_MERGE")
        flags = Constants::FSTATUS_ADDED_BY_MERGE;
    else if (label == "UPDATED_BY_MERGE")
        flags = Constants::FSTATUS_UPDATED_BY_MERGE;
    else if (label == "ADDED_BY_INTEGRATE")
        flags = Constants::FSTATUS_ADDED_BY_INTEGRATE;
    else if (label == "UPDATED_BY_INTEGRATE")
        flags = Constants::FSTATUS_UPDATED_BY_INTEGRATE;
    else if (label == "CONFLICT")
        flags = "Conflict";
    else if (label == "EXECUTABLE")
        flags = "Set Exec";
    else if (label == "SYMLINK")
        flags = "Set Symlink";
    else if (label == "UNEXEC")
        flags = "Unset Exec";
    else if (label == "UNLINK")
        flags = "Unset Symlink";
    else if (label == "NOT_A_FILE")
        flags = Constants::FSTATUS_UNKNOWN;


    if (flags.isEmpty())
        return StatusItem();

    // adjust the position to the last space before the file name
    for (int size = line.size(); (pos+1) < size && line[pos+1].isSpace(); ++pos) {}

    item.flags = flags;
    item.file = line.mid(pos + 1);

    return item;
}

VcsBase::VcsBaseEditorConfig *FossilClient::createAnnotateEditor(VcsBase::VcsBaseEditorWidget *editor)
{
    return new FossilAnnotateConfig(this, editor->toolBar());
}

VcsBase::VcsBaseEditorConfig *FossilClient::createLogCurrentFileEditor(VcsBase::VcsBaseEditorWidget *editor)
{
    SupportedFeatures features = supportedFeatures();

    if (features.testFlag(TimelinePathFeature))
        return createLogEditor(editor);

    return new FossilLogCurrentFileConfig(this, editor->toolBar());
}

VcsBase::VcsBaseEditorConfig *FossilClient::createLogEditor(VcsBase::VcsBaseEditorWidget *editor)
{
    return new FossilLogConfig(this, editor->toolBar());
}

} // namespace Internal
} // namespace Fossil

#include "fossilclient.moc"