@@ -62,7 +62,7 @@ class FastImportRepository : public Repository
62
62
inline Transaction () {}
63
63
public:
64
64
~Transaction ();
65
- void commit ();
65
+ int commit ();
66
66
67
67
void setAuthor (const QByteArray &author);
68
68
void setDateTime (uint dt);
@@ -73,12 +73,13 @@ class FastImportRepository : public Repository
73
73
void deleteFile (const QString &path);
74
74
QIODevice *addFile (const QString &path, int mode, qint64 length);
75
75
76
- void commitNote (const QByteArray ¬eText, bool append,
76
+ bool commitNote (const QByteArray ¬eText, bool append,
77
77
const QByteArray &commit = QByteArray());
78
78
};
79
79
FastImportRepository (const Rules::Repository &rule);
80
80
int setupIncremental (int &cutoff);
81
81
void restoreAnnotatedTags ();
82
+ void restoreBranchNotes ();
82
83
void restoreLog ();
83
84
~FastImportRepository ();
84
85
@@ -92,6 +93,7 @@ class FastImportRepository : public Repository
92
93
const QByteArray &author, uint dt,
93
94
const QByteArray &log);
94
95
void finalizeTags ();
96
+ void saveBranchNotes ();
95
97
void commit ();
96
98
97
99
bool branchExists (const QString& branch) const ;
@@ -108,10 +110,10 @@ class FastImportRepository : public Repository
108
110
int created;
109
111
QVector<int > commits;
110
112
QVector<int > marks;
111
- QByteArray note;
112
113
};
113
114
114
115
QHash<QString, Branch> branches;
116
+ QHash<QString, QByteArray> branchNotes;
115
117
QHash<QString, AnnotatedTag> annotatedTags;
116
118
QString name;
117
119
QString prefix;
@@ -163,7 +165,7 @@ class ForwardingRepository : public Repository
163
165
public:
164
166
Transaction (Repository::Transaction *t, const QString &p) : txn(t), prefix(p) {}
165
167
~Transaction () { delete txn; }
166
- void commit () { txn->commit (); }
168
+ int commit () { return txn->commit (); }
167
169
168
170
void setAuthor (const QByteArray &author) { txn->setAuthor (author); }
169
171
void setDateTime (uint dt) { txn->setDateTime (dt); }
@@ -176,7 +178,7 @@ class ForwardingRepository : public Repository
176
178
QIODevice *addFile (const QString &path, int mode, qint64 length)
177
179
{ return txn->addFile (prefix + path, mode, length); }
178
180
179
- void commitNote (const QByteArray ¬eText, bool append,
181
+ bool commitNote (const QByteArray ¬eText, bool append,
180
182
const QByteArray &commit)
181
183
{ return txn->commitNote (noteText, append, commit); }
182
184
};
@@ -185,6 +187,7 @@ class ForwardingRepository : public Repository
185
187
186
188
int setupIncremental (int &) { return 1 ; }
187
189
void restoreAnnotatedTags () {}
190
+ void restoreBranchNotes () {}
188
191
void restoreLog () {}
189
192
190
193
void reloadBranches () { return repo->reloadBranches (); }
@@ -206,6 +209,7 @@ class ForwardingRepository : public Repository
206
209
const QByteArray &log)
207
210
{ repo->createAnnotatedTag (name, svnprefix, revnum, author, dt, log); }
208
211
void finalizeTags () { /* loop that called this will invoke it on 'repo' too */ }
212
+ void saveBranchNotes () { /* loop that called this will invoke it on 'repo' too */ }
209
213
void commit () { repo->commit (); }
210
214
211
215
bool branchExists (const QString& branch) const
@@ -303,6 +307,13 @@ static QString annotatedTagsFileName(QString name)
303
307
return name;
304
308
}
305
309
310
+ static QString branchNotesFileName (QString name)
311
+ {
312
+ name.replace (' /' , ' _' );
313
+ name.prepend (" branchNotes-" );
314
+ return name;
315
+ }
316
+
306
317
FastImportRepository::FastImportRepository (const Rules::Repository &rule)
307
318
: name(rule.name), prefix(rule.forwardTo), fastImport(name), commitCount(0 ), outstandingTransactions(0 ),
308
319
last_commit_mark(0 ), next_file_mark(maxMark - 1 ), processHasStarted(false )
@@ -498,6 +509,17 @@ void FastImportRepository::restoreAnnotatedTags()
498
509
annotatedTagsFile.close ();
499
510
}
500
511
512
+ void FastImportRepository::restoreBranchNotes ()
513
+ {
514
+ QFile branchNotesFile (name + " /" + branchNotesFileName (name));
515
+ if (!branchNotesFile.exists ())
516
+ return ;
517
+ branchNotesFile.open (QIODevice::ReadOnly);
518
+ QDataStream branchNotesStream (&branchNotesFile);
519
+ branchNotesStream >> branchNotes;
520
+ branchNotesFile.close ();
521
+ }
522
+
501
523
void FastImportRepository::restoreLog ()
502
524
{
503
525
QString file = logFileName (name);
@@ -625,7 +647,7 @@ int FastImportRepository::createBranch(const QString &branch, int revnum,
625
647
qDebug () << " Creating branch:" << branch << " from" << branchFrom << " (" << branchRevNum << branchFromDesc << " )" ;
626
648
627
649
// Preserve note
628
- branches [branch]. note = branches .value (branchFrom). note ;
650
+ branchNotes [branch] = branchNotes .value (branchFrom);
629
651
630
652
return resetBranch (branch, revnum, mark, branchFromRef, branchFromDesc);
631
653
}
@@ -801,10 +823,10 @@ void FastImportRepository::finalizeTags()
801
823
Repository::Transaction *txn = newTransaction (tag.supportingRef , tag.svnprefix , tag.revnum );
802
824
txn->setAuthor (tag.author );
803
825
txn->setDateTime (tag.dt );
804
- txn->commitNote (formatMetadataMessage (tag.svnprefix , tag.revnum , tagName.toUtf8 ()), true );
826
+ bool written = txn->commitNote (formatMetadataMessage (tag.svnprefix , tag.revnum , tagName.toUtf8 ()), true );
805
827
delete txn;
806
828
807
- if (!fastImport.waitForBytesWritten (-1 ))
829
+ if (written && !fastImport.waitForBytesWritten (-1 ))
808
830
qFatal (" Failed to write to process: %s" , qPrintable (fastImport.errorString ()));
809
831
}
810
832
@@ -818,6 +840,17 @@ void FastImportRepository::finalizeTags()
818
840
printf (" \n " );
819
841
}
820
842
843
+ void FastImportRepository::saveBranchNotes ()
844
+ {
845
+ if (branchNotes.isEmpty ())
846
+ return ;
847
+
848
+ QFile branchNotesFile (name + " /" + branchNotesFileName (name));
849
+ branchNotesFile.open (QIODevice::WriteOnly);
850
+ QDataStream branchNotesStream (&branchNotesFile);
851
+ branchNotesStream << branchNotes;
852
+ branchNotesFile.close ();
853
+ }
821
854
822
855
QByteArray
823
856
FastImportRepository::msgFilter (QByteArray msg)
@@ -887,13 +920,13 @@ bool FastImportRepository::branchExists(const QString& branch) const
887
920
888
921
const QByteArray FastImportRepository::branchNote (const QString& branch) const
889
922
{
890
- return branches .value (branch). note ;
923
+ return branchNotes .value (branch);
891
924
}
892
925
893
926
void FastImportRepository::setBranchNote (const QString& branch, const QByteArray& noteText)
894
927
{
895
928
if (branches.contains (branch))
896
- branches [branch]. note = noteText;
929
+ branchNotes [branch] = noteText;
897
930
}
898
931
899
932
bool FastImportRepository::hasPrefix () const
@@ -997,20 +1030,37 @@ QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int m
997
1030
return &repository->fastImport ;
998
1031
}
999
1032
1000
- void FastImportRepository::Transaction::commitNote (const QByteArray ¬eText, bool append, const QByteArray &commit)
1033
+ bool FastImportRepository::Transaction::commitNote (const QByteArray ¬eText, bool append, const QByteArray &commit)
1001
1034
{
1002
1035
QByteArray branchRef = branch;
1003
1036
if (!branchRef.startsWith (" refs/" ))
1037
+ {
1004
1038
branchRef.prepend (" refs/heads/" );
1039
+ }
1005
1040
const QByteArray &commitRef = commit.isNull () ? branchRef : commit;
1006
1041
QByteArray message = " Adding Git note for current " + commitRef + " \n " ;
1007
1042
QByteArray text = noteText;
1043
+ if (noteText[noteText.size () - 1 ] != ' \n ' )
1044
+ {
1045
+ text += ' \n ' ;
1046
+ }
1008
1047
1048
+ QByteArray branchNote = repository->branchNote (branch);
1049
+ if (!branchNote.isEmpty () && (branchNote[branchNote.size () - 1 ] != ' \n ' ))
1050
+ {
1051
+ branchNote += ' \n ' ;
1052
+ }
1009
1053
if (append && commit.isNull () &&
1010
1054
repository->branchExists (branch) &&
1011
- !repository-> branchNote (branch) .isEmpty ())
1055
+ !branchNote.isEmpty ())
1012
1056
{
1013
- text = repository->branchNote (branch) + text;
1057
+ int i = branchNote.indexOf (text);
1058
+ if ((i == 0 ) || ((i != -1 ) && (branchNote[i - 1 ] == ' \n ' )))
1059
+ {
1060
+ // note is already present at the start or somewhere within following a newline
1061
+ return false ;
1062
+ }
1063
+ text = branchNote + text;
1014
1064
message = " Appending Git note for current " + commitRef + " \n " ;
1015
1065
}
1016
1066
@@ -1026,17 +1076,29 @@ void FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, b
1026
1076
repository->startFastImport ();
1027
1077
repository->fastImport .write (s);
1028
1078
1029
- if (commit.isNull ()) {
1079
+ if (commit.isNull ())
1080
+ {
1030
1081
repository->setBranchNote (QString::fromUtf8 (branch), text);
1031
1082
}
1083
+
1084
+ return true ;
1032
1085
}
1033
1086
1034
- void FastImportRepository::Transaction::commit ()
1087
+ int FastImportRepository::Transaction::commit ()
1035
1088
{
1089
+ foreach (QString branchName, repository->branches .keys ())
1090
+ {
1091
+ if (branchName.toUtf8 ().startsWith (branch + " /" ) || branch.startsWith ((branchName + " /" ).toUtf8 ()))
1092
+ {
1093
+ qCritical () << " Branch" << branch << " conflicts with already existing branch" << branchName;
1094
+ return EXIT_FAILURE;
1095
+ }
1096
+ }
1097
+
1036
1098
repository->startFastImport ();
1037
1099
1038
1100
// We might be tempted to use the SVN revision number as the fast-import commit mark.
1039
- // However, a single SVN revision can modify multple branches, and thus lead to multiple
1101
+ // However, a single SVN revision can modify multiple branches, and thus lead to multiple
1040
1102
// commits in the same repo. So, we need to maintain a separate commit mark counter.
1041
1103
mark_t mark = ++repository->last_commit_mark ;
1042
1104
@@ -1135,4 +1197,6 @@ void FastImportRepository::Transaction::commit()
1135
1197
while (repository->fastImport .bytesToWrite ())
1136
1198
if (!repository->fastImport .waitForBytesWritten (-1 ))
1137
1199
qFatal (" Failed to write to process: %s for repository %s" , qPrintable (repository->fastImport .errorString ()), qPrintable (repository->name ));
1200
+
1201
+ return EXIT_SUCCESS;
1138
1202
}
0 commit comments