@@ -64,11 +64,12 @@ class FastImportRepository : public Repository
6464 void deleteFile (const QString &path);
6565 QIODevice *addFile (const QString &path, int mode, qint64 length);
6666
67- void commitNote (const QByteArray ¬eText, bool append,
67+ bool commitNote (const QByteArray ¬eText, bool append,
6868 const QByteArray &commit = QByteArray());
6969 };
7070 FastImportRepository (const Rules::Repository &rule);
7171 int setupIncremental (int &cutoff);
72+ void restoreBranchNotes ();
7273 void restoreLog ();
7374 ~FastImportRepository ();
7475
@@ -82,6 +83,7 @@ class FastImportRepository : public Repository
8283 const QByteArray &author, uint dt,
8384 const QByteArray &log);
8485 void finalizeTags ();
86+ void saveBranchNotes ();
8587 void commit ();
8688
8789 bool branchExists (const QString& branch) const ;
@@ -98,7 +100,6 @@ class FastImportRepository : public Repository
98100 int created;
99101 QVector<int > commits;
100102 QVector<int > marks;
101- QByteArray note;
102103 };
103104 struct AnnotatedTag
104105 {
@@ -111,6 +112,7 @@ class FastImportRepository : public Repository
111112 };
112113
113114 QHash<QString, Branch> branches;
115+ QHash<QString, QByteArray> branchNotes;
114116 QHash<QString, AnnotatedTag> annotatedTags;
115117 QString name;
116118 QString prefix;
@@ -175,14 +177,15 @@ class ForwardingRepository : public Repository
175177 QIODevice *addFile (const QString &path, int mode, qint64 length)
176178 { return txn->addFile (prefix + path, mode, length); }
177179
178- void commitNote (const QByteArray ¬eText, bool append,
180+ bool commitNote (const QByteArray ¬eText, bool append,
179181 const QByteArray &commit)
180182 { return txn->commitNote (noteText, append, commit); }
181183 };
182184
183185 ForwardingRepository (const QString &n, Repository *r, const QString &p) : name(n), repo(r), prefix(p) {}
184186
185187 int setupIncremental (int &) { return 1 ; }
188+ void restoreBranchNotes () {}
186189 void restoreLog () {}
187190
188191 void reloadBranches () { return repo->reloadBranches (); }
@@ -204,6 +207,7 @@ class ForwardingRepository : public Repository
204207 const QByteArray &log)
205208 { repo->createAnnotatedTag (name, svnprefix, revnum, author, dt, log); }
206209 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 */ }
207211 void commit () { repo->commit (); }
208212
209213 bool branchExists (const QString& branch) const
@@ -267,6 +271,13 @@ static QString marksFileName(QString name)
267271 return name;
268272}
269273
274+ static QString branchNotesFileName (QString name)
275+ {
276+ name.replace (' /' , ' _' );
277+ name.prepend (" branchNotes-" );
278+ return name;
279+ }
280+
270281FastImportRepository::FastImportRepository (const Rules::Repository &rule)
271282 : name(rule.name), prefix(rule.forwardTo), fastImport(name), commitCount(0 ), outstandingTransactions(0 ),
272283 last_commit_mark(0 ), next_file_mark(maxMark - 1 ), processHasStarted(false )
@@ -451,6 +462,17 @@ int FastImportRepository::setupIncremental(int &cutoff)
451462 return cutoff;
452463}
453464
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+
454476void FastImportRepository::restoreLog ()
455477{
456478 QString file = logFileName (name);
@@ -578,7 +600,7 @@ int FastImportRepository::createBranch(const QString &branch, int revnum,
578600 qDebug () << " Creating branch:" << branch << " from" << branchFrom << " (" << branchRevNum << branchFromDesc << " )" ;
579601
580602 // Preserve note
581- branches [branch]. note = branches .value (branchFrom). note ;
603+ branchNotes [branch] = branchNotes .value (branchFrom);
582604
583605 return resetBranch (branch, revnum, mark, branchFromRef, branchFromDesc);
584606}
@@ -748,10 +770,10 @@ void FastImportRepository::finalizeTags()
748770 Repository::Transaction *txn = newTransaction (tag.supportingRef , tag.svnprefix , tag.revnum );
749771 txn->setAuthor (tag.author );
750772 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 );
752774 delete txn;
753775
754- if (!fastImport.waitForBytesWritten (-1 ))
776+ if (written && !fastImport.waitForBytesWritten (-1 ))
755777 qFatal (" Failed to write to process: %s" , qPrintable (fastImport.errorString ()));
756778 }
757779
@@ -765,6 +787,17 @@ void FastImportRepository::finalizeTags()
765787 printf (" \n " );
766788}
767789
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+ }
768801
769802QByteArray
770803FastImportRepository::msgFilter (QByteArray msg)
@@ -834,13 +867,13 @@ bool FastImportRepository::branchExists(const QString& branch) const
834867
835868const QByteArray FastImportRepository::branchNote (const QString& branch) const
836869{
837- return branches .value (branch). note ;
870+ return branchNotes .value (branch);
838871}
839872
840873void FastImportRepository::setBranchNote (const QString& branch, const QByteArray& noteText)
841874{
842875 if (branches.contains (branch))
843- branches [branch]. note = noteText;
876+ branchNotes [branch] = noteText;
844877}
845878
846879bool FastImportRepository::hasPrefix () const
@@ -944,20 +977,37 @@ QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int m
944977 return &repository->fastImport ;
945978}
946979
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)
948981{
949982 QByteArray branchRef = branch;
950983 if (!branchRef.startsWith (" refs/" ))
984+ {
951985 branchRef.prepend (" refs/heads/" );
986+ }
952987 const QByteArray &commitRef = commit.isNull () ? branchRef : commit;
953988 QByteArray message = " Adding Git note for current " + commitRef + " \n " ;
954989 QByteArray text = noteText;
990+ if (noteText[noteText.size () - 1 ] != ' \n ' )
991+ {
992+ text += ' \n ' ;
993+ }
955994
995+ QByteArray branchNote = repository->branchNote (branch);
996+ if (!branchNote.isEmpty () && (branchNote[branchNote.size () - 1 ] != ' \n ' ))
997+ {
998+ branchNote += ' \n ' ;
999+ }
9561000 if (append && commit.isNull () &&
9571001 repository->branchExists (branch) &&
958- !repository-> branchNote (branch) .isEmpty ())
1002+ !branchNote.isEmpty ())
9591003 {
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;
9611011 message = " Appending Git note for current " + commitRef + " \n " ;
9621012 }
9631013
@@ -973,9 +1023,12 @@ void FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, b
9731023 repository->startFastImport ();
9741024 repository->fastImport .write (s);
9751025
976- if (commit.isNull ()) {
1026+ if (commit.isNull ())
1027+ {
9771028 repository->setBranchNote (QString::fromUtf8 (branch), text);
9781029 }
1030+
1031+ return true ;
9791032}
9801033
9811034int FastImportRepository::Transaction::commit ()
0 commit comments