@@ -342,6 +342,9 @@ int Repository::createBranch(const QString &branch, int revnum,
342342
343343 qDebug () << " Creating branch:" << branch << " from" << branchFrom << " (" << branchRevNum << branchFromDesc << " )" ;
344344
345+ // Preserve note
346+ branches[branch].note = branches.value (branchFrom).note ;
347+
345348 return resetBranch (branch, revnum, mark, branchFromRef, branchFromDesc);
346349}
347350
@@ -469,7 +472,7 @@ void Repository::finalizeTags()
469472 if (!message.endsWith (' \n ' ))
470473 message += ' \n ' ;
471474 if (CommandLineParser::instance ()->contains (" add-metadata" ))
472- message += " \n svn path= " + tag.svnprefix + " ; revision= " + QByteArray::number ( tag.revnum ) + " \n " ;
475+ message += " \n " + formatMetadataMessage ( tag.svnprefix , tag.revnum , tagName. toUtf8 ()) ;
473476
474477 {
475478 QByteArray branchRef = tag.supportingRef .toUtf8 ();
@@ -489,6 +492,19 @@ void Repository::finalizeTags()
489492 if (!fastImport.waitForBytesWritten (-1 ))
490493 qFatal (" Failed to write to process: %s" , qPrintable (fastImport.errorString ()));
491494
495+ // Append note to the tip commit of the supporting ref. There is no
496+ // easy way to attach a note to the tag itself with fast-import.
497+ if (CommandLineParser::instance ()->contains (" add-metadata-notes" )) {
498+ Repository::Transaction *txn = newTransaction (tag.supportingRef , tag.svnprefix , tag.revnum );
499+ txn->setAuthor (tag.author );
500+ txn->setDateTime (tag.dt );
501+ txn->commitNote (formatMetadataMessage (tag.svnprefix , tag.revnum , tagName.toUtf8 ()), true );
502+ delete txn;
503+
504+ if (!fastImport.waitForBytesWritten (-1 ))
505+ qFatal (" Failed to write to process: %s" , qPrintable (fastImport.errorString ()));
506+ }
507+
492508 printf (" %s" , qPrintable (tagName));
493509 fflush (stdout);
494510 }
@@ -529,6 +545,31 @@ void Repository::startFastImport()
529545 }
530546}
531547
548+ QByteArray Repository::formatMetadataMessage (const QByteArray &svnprefix, int revnum, const QByteArray &tag)
549+ {
550+ QByteArray msg = " svn path=" + svnprefix + " ; revision=" + QByteArray::number (revnum);
551+ if (!tag.isEmpty ())
552+ msg += " ; tag=" + tag;
553+ msg += " \n " ;
554+ return msg;
555+ }
556+
557+ bool Repository::branchExists (const QString& branch) const \
558+ {
559+ return branches.contains (branch);
560+ }
561+
562+ const QByteArray Repository::branchNote (const QString& branch) const
563+ {
564+ return branches.value (branch).note ;
565+ }
566+
567+ void Repository::setBranchNote (const QString& branch, const QByteArray& noteText)
568+ {
569+ if (branches.contains (branch))
570+ branches[branch].note = noteText;
571+ }
572+
532573Repository::Transaction::~Transaction ()
533574{
534575 repository->forgetTransaction (this );
@@ -614,6 +655,37 @@ QIODevice *Repository::Transaction::addFile(const QString &path, int mode, qint6
614655 return &repository->fastImport ;
615656}
616657
658+ void Repository::Transaction::commitNote (const QByteArray ¬eText, bool append, const QByteArray &commit)
659+ {
660+ QByteArray branchRef = branch;
661+ if (!branchRef.startsWith (" refs/" ))
662+ branchRef.prepend (" refs/heads/" );
663+ const QByteArray &commitRef = commit.isNull () ? branchRef : commit;
664+ QByteArray message = " Adding Git note for current " + commitRef + " \n " ;
665+ QByteArray text = noteText;
666+
667+ if (append && commit.isNull () &&
668+ repository->branchExists (branch) &&
669+ !repository->branchNote (branch).isEmpty ())
670+ {
671+ text = repository->branchNote (branch) + text;
672+ message = " Appending Git note for current " + commitRef + " \n " ;
673+ }
674+
675+ QTextStream s (&repository->fastImport );
676+ s << " commit refs/notes/commits" << endl
677+ << " committer " << QString::fromUtf8 (author) << ' ' << datetime << " -0000" << endl
678+ << " data " << message.length () << endl
679+ << message << endl
680+ << " N inline " << commitRef << endl
681+ << " data " << text.length () << endl
682+ << text << endl;
683+
684+ if (commit.isNull ()) {
685+ repository->setBranchNote (QString::fromUtf8 (branch), text);
686+ }
687+ }
688+
617689void Repository::Transaction::commit ()
618690{
619691 repository->startFastImport ();
@@ -631,7 +703,7 @@ void Repository::Transaction::commit()
631703 if (!message.endsWith (' \n ' ))
632704 message += ' \n ' ;
633705 if (CommandLineParser::instance ()->contains (" add-metadata" ))
634- message += " \n svn path= " + svnprefix + " ; revision= " + QByteArray::number ( revnum) + " \n " ;
706+ message += " \n " + Repository::formatMetadataMessage (svnprefix, revnum);
635707
636708 int parentmark = 0 ;
637709 Branch &br = repository->branches [branch];
@@ -649,7 +721,6 @@ void Repository::Transaction::commit()
649721 QByteArray branchRef = branch;
650722 if (!branchRef.startsWith (" refs/" ))
651723 branchRef.prepend (" refs/heads/" );
652-
653724 QTextStream s (&repository->fastImport );
654725 s.setCodec (" UTF-8" );
655726 s << " commit " << branchRef << endl;
@@ -713,6 +784,10 @@ void Repository::Transaction::commit()
713784 deletedFiles.count () + modifiedFiles.count (' \n ' ), svnprefix.data (),
714785 qPrintable (repository->name ), branch.data ());
715786
787+ // Commit metadata note if requested
788+ if (CommandLineParser::instance ()->contains (" add-metadata-notes" ))
789+ commitNote (Repository::formatMetadataMessage (svnprefix, revnum), false );
790+
716791 while (repository->fastImport .bytesToWrite ())
717792 if (!repository->fastImport .waitForBytesWritten (-1 ))
718793 qFatal (" Failed to write to process: %s for repository %s" , qPrintable (repository->fastImport .errorString ()), qPrintable (repository->name ));
0 commit comments