Skip to content

Commit 2536659

Browse files
author
Torgny Nyblom
committed
Merge commit 'refs/merge-requests/14' of gitorious.org:svn2git/svn2git into merge-requests/14
2 parents 4c241d5 + 22f5339 commit 2536659

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static const CommandLineOption options[] = {
124124
{"--revisions-file FILENAME", "provide a file with revision number that should be processed"},
125125
{"--rules FILENAME[,FILENAME]", "the rules file(s) that determines what goes where"},
126126
{"--add-metadata", "if passed, each git commit will have svn commit info"},
127+
{"--add-metadata-notes", "if passed, each git commit will have notes with svn commit info"},
127128
{"--resume-from revision", "start importing at svn revision number"},
128129
{"--max-rev revision", "stop importing at svn revision number"},
129130
{"--dry-run", "don't actually write anything"},

src/repository.cpp

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 += "\nsvn 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+
532573
Repository::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 &noteText, 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+
617689
void 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 += "\nsvn 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));

src/repository.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class Repository
126126

127127
void deleteFile(const QString &path);
128128
QIODevice *addFile(const QString &path, int mode, qint64 length);
129+
130+
void commitNote(const QByteArray &noteText, bool append,
131+
const QByteArray &commit = QByteArray());
129132
};
130133
Repository(const Rules::Repository &rule);
131134
int setupIncremental(int &cutoff);
@@ -144,12 +147,20 @@ class Repository
144147
void finalizeTags();
145148
void commit();
146149

150+
static QByteArray formatMetadataMessage(const QByteArray &svnprefix, int revnum,
151+
const QByteArray &tag = QByteArray());
152+
153+
bool branchExists(const QString& branch) const;
154+
const QByteArray branchNote(const QString& branch) const;
155+
void setBranchNote(const QString& branch, const QByteArray& noteText);
156+
147157
private:
148158
struct Branch
149159
{
150160
int created;
151161
QVector<int> commits;
152162
QVector<int> marks;
163+
QByteArray note;
153164
};
154165
struct AnnotatedTag
155166
{

0 commit comments

Comments
 (0)