@@ -64,11 +64,12 @@ class FastImportRepository : public Repository
64
64
void deleteFile (const QString &path);
65
65
QIODevice *addFile (const QString &path, int mode, qint64 length);
66
66
67
- void commitNote (const QByteArray ¬eText, bool append,
67
+ bool commitNote (const QByteArray ¬eText, bool append,
68
68
const QByteArray &commit = QByteArray());
69
69
};
70
70
FastImportRepository (const Rules::Repository &rule);
71
71
int setupIncremental (int &cutoff);
72
+ void restoreBranchNotes ();
72
73
void restoreLog ();
73
74
~FastImportRepository ();
74
75
@@ -82,6 +83,7 @@ class FastImportRepository : public Repository
82
83
const QByteArray &author, uint dt,
83
84
const QByteArray &log);
84
85
void finalizeTags ();
86
+ void saveBranchNotes ();
85
87
void commit ();
86
88
87
89
bool branchExists (const QString& branch) const ;
@@ -98,7 +100,6 @@ class FastImportRepository : public Repository
98
100
int created;
99
101
QVector<int > commits;
100
102
QVector<int > marks;
101
- QByteArray note;
102
103
};
103
104
struct AnnotatedTag
104
105
{
@@ -111,6 +112,7 @@ class FastImportRepository : public Repository
111
112
};
112
113
113
114
QHash<QString, Branch> branches;
115
+ QHash<QString, QByteArray> branchNotes;
114
116
QHash<QString, AnnotatedTag> annotatedTags;
115
117
QString name;
116
118
QString prefix;
@@ -175,14 +177,15 @@ class ForwardingRepository : public Repository
175
177
QIODevice *addFile (const QString &path, int mode, qint64 length)
176
178
{ return txn->addFile (prefix + path, mode, length); }
177
179
178
- void commitNote (const QByteArray ¬eText, bool append,
180
+ bool commitNote (const QByteArray ¬eText, bool append,
179
181
const QByteArray &commit)
180
182
{ return txn->commitNote (noteText, append, commit); }
181
183
};
182
184
183
185
ForwardingRepository (const QString &n, Repository *r, const QString &p) : name(n), repo(r), prefix(p) {}
184
186
185
187
int setupIncremental (int &) { return 1 ; }
188
+ void restoreBranchNotes () {}
186
189
void restoreLog () {}
187
190
188
191
void reloadBranches () { return repo->reloadBranches (); }
@@ -204,6 +207,7 @@ class ForwardingRepository : public Repository
204
207
const QByteArray &log)
205
208
{ repo->createAnnotatedTag (name, svnprefix, revnum, author, dt, log); }
206
209
void finalizeTags () { /* loop that called this will invoke it on 'repo' too */ }
210
+ void saveBranchNotes () { /* loop that called this will invoke it on 'repo' too */ }
207
211
void commit () { repo->commit (); }
208
212
209
213
bool branchExists (const QString& branch) const
@@ -267,6 +271,13 @@ static QString marksFileName(QString name)
267
271
return name;
268
272
}
269
273
274
+ static QString branchNotesFileName (QString name)
275
+ {
276
+ name.replace (' /' , ' _' );
277
+ name.prepend (" branchNotes-" );
278
+ return name;
279
+ }
280
+
270
281
FastImportRepository::FastImportRepository (const Rules::Repository &rule)
271
282
: name(rule.name), prefix(rule.forwardTo), fastImport(name), commitCount(0 ), outstandingTransactions(0 ),
272
283
last_commit_mark(0 ), next_file_mark(maxMark - 1 ), processHasStarted(false )
@@ -451,6 +462,17 @@ int FastImportRepository::setupIncremental(int &cutoff)
451
462
return cutoff;
452
463
}
453
464
465
+ void FastImportRepository::restoreBranchNotes ()
466
+ {
467
+ QFile branchNotesFile (name + " /" + branchNotesFileName (name));
468
+ if (!branchNotesFile.exists ())
469
+ return ;
470
+ branchNotesFile.open (QIODevice::ReadOnly);
471
+ QDataStream branchNotesStream (&branchNotesFile);
472
+ branchNotesStream >> branchNotes;
473
+ branchNotesFile.close ();
474
+ }
475
+
454
476
void FastImportRepository::restoreLog ()
455
477
{
456
478
QString file = logFileName (name);
@@ -578,7 +600,7 @@ int FastImportRepository::createBranch(const QString &branch, int revnum,
578
600
qDebug () << " Creating branch:" << branch << " from" << branchFrom << " (" << branchRevNum << branchFromDesc << " )" ;
579
601
580
602
// Preserve note
581
- branches [branch]. note = branches .value (branchFrom). note ;
603
+ branchNotes [branch] = branchNotes .value (branchFrom);
582
604
583
605
return resetBranch (branch, revnum, mark, branchFromRef, branchFromDesc);
584
606
}
@@ -748,10 +770,10 @@ void FastImportRepository::finalizeTags()
748
770
Repository::Transaction *txn = newTransaction (tag.supportingRef , tag.svnprefix , tag.revnum );
749
771
txn->setAuthor (tag.author );
750
772
txn->setDateTime (tag.dt );
751
- txn->commitNote (formatMetadataMessage (tag.svnprefix , tag.revnum , tagName.toUtf8 ()), true );
773
+ bool written = txn->commitNote (formatMetadataMessage (tag.svnprefix , tag.revnum , tagName.toUtf8 ()), true );
752
774
delete txn;
753
775
754
- if (!fastImport.waitForBytesWritten (-1 ))
776
+ if (written && !fastImport.waitForBytesWritten (-1 ))
755
777
qFatal (" Failed to write to process: %s" , qPrintable (fastImport.errorString ()));
756
778
}
757
779
@@ -765,6 +787,17 @@ void FastImportRepository::finalizeTags()
765
787
printf (" \n " );
766
788
}
767
789
790
+ void FastImportRepository::saveBranchNotes ()
791
+ {
792
+ if (branchNotes.isEmpty ())
793
+ return ;
794
+
795
+ QFile branchNotesFile (name + " /" + branchNotesFileName (name));
796
+ branchNotesFile.open (QIODevice::WriteOnly);
797
+ QDataStream branchNotesStream (&branchNotesFile);
798
+ branchNotesStream << branchNotes;
799
+ branchNotesFile.close ();
800
+ }
768
801
769
802
QByteArray
770
803
FastImportRepository::msgFilter (QByteArray msg)
@@ -834,13 +867,13 @@ bool FastImportRepository::branchExists(const QString& branch) const
834
867
835
868
const QByteArray FastImportRepository::branchNote (const QString& branch) const
836
869
{
837
- return branches .value (branch). note ;
870
+ return branchNotes .value (branch);
838
871
}
839
872
840
873
void FastImportRepository::setBranchNote (const QString& branch, const QByteArray& noteText)
841
874
{
842
875
if (branches.contains (branch))
843
- branches [branch]. note = noteText;
876
+ branchNotes [branch] = noteText;
844
877
}
845
878
846
879
bool FastImportRepository::hasPrefix () const
@@ -944,20 +977,37 @@ QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int m
944
977
return &repository->fastImport ;
945
978
}
946
979
947
- void FastImportRepository::Transaction::commitNote (const QByteArray ¬eText, bool append, const QByteArray &commit)
980
+ bool FastImportRepository::Transaction::commitNote (const QByteArray ¬eText, bool append, const QByteArray &commit)
948
981
{
949
982
QByteArray branchRef = branch;
950
983
if (!branchRef.startsWith (" refs/" ))
984
+ {
951
985
branchRef.prepend (" refs/heads/" );
986
+ }
952
987
const QByteArray &commitRef = commit.isNull () ? branchRef : commit;
953
988
QByteArray message = " Adding Git note for current " + commitRef + " \n " ;
954
989
QByteArray text = noteText;
990
+ if (noteText[noteText.size () - 1 ] != ' \n ' )
991
+ {
992
+ text += ' \n ' ;
993
+ }
955
994
995
+ QByteArray branchNote = repository->branchNote (branch);
996
+ if (!branchNote.isEmpty () && (branchNote[branchNote.size () - 1 ] != ' \n ' ))
997
+ {
998
+ branchNote += ' \n ' ;
999
+ }
956
1000
if (append && commit.isNull () &&
957
1001
repository->branchExists (branch) &&
958
- !repository-> branchNote (branch) .isEmpty ())
1002
+ !branchNote.isEmpty ())
959
1003
{
960
- text = repository->branchNote (branch) + text;
1004
+ int i = branchNote.indexOf (text);
1005
+ if ((i == 0 ) || ((i != -1 ) && (branchNote[i - 1 ] == ' \n ' )))
1006
+ {
1007
+ // note is already present at the start or somewhere within following a newline
1008
+ return false ;
1009
+ }
1010
+ text = branchNote + text;
961
1011
message = " Appending Git note for current " + commitRef + " \n " ;
962
1012
}
963
1013
@@ -973,9 +1023,12 @@ void FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, b
973
1023
repository->startFastImport ();
974
1024
repository->fastImport .write (s);
975
1025
976
- if (commit.isNull ()) {
1026
+ if (commit.isNull ())
1027
+ {
977
1028
repository->setBranchNote (QString::fromUtf8 (branch), text);
978
1029
}
1030
+
1031
+ return true ;
979
1032
}
980
1033
981
1034
int FastImportRepository::Transaction::commit ()
0 commit comments