Skip to content

Commit e51772b

Browse files
Vampiretnyblom
authored andcommitted
Abort on conflicting ref names
If you have a ref name refs/tags/foo you cannot create a ref refs/tags/foo/bar and also the other way around, as for the former a file and the the latter a directory would be created that both would be named 'foo' as long as the refs are not packed. So check for this and abort early so that the rules can be adapted to produce proper names.
1 parent 396cf9e commit e51772b

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/repository.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FastImportRepository : public Repository
5353
inline Transaction() {}
5454
public:
5555
~Transaction();
56-
void commit();
56+
int commit();
5757

5858
void setAuthor(const QByteArray &author);
5959
void setDateTime(uint dt);
@@ -162,7 +162,7 @@ class ForwardingRepository : public Repository
162162
public:
163163
Transaction(Repository::Transaction *t, const QString &p) : txn(t), prefix(p) {}
164164
~Transaction() { delete txn; }
165-
void commit() { txn->commit(); }
165+
int commit() { return txn->commit(); }
166166

167167
void setAuthor(const QByteArray &author) { txn->setAuthor(author); }
168168
void setDateTime(uint dt) { txn->setDateTime(dt); }
@@ -978,12 +978,21 @@ void FastImportRepository::Transaction::commitNote(const QByteArray &noteText, b
978978
}
979979
}
980980

981-
void FastImportRepository::Transaction::commit()
981+
int FastImportRepository::Transaction::commit()
982982
{
983+
foreach (QString branchName, repository->branches.keys())
984+
{
985+
if (branchName.toUtf8().startsWith(branch + "/") || branch.startsWith((branchName + "/").toUtf8()))
986+
{
987+
qCritical() << "Branch" << branch << "conflicts with already existing branch" << branchName;
988+
return EXIT_FAILURE;
989+
}
990+
}
991+
983992
repository->startFastImport();
984993

985994
// We might be tempted to use the SVN revision number as the fast-import commit mark.
986-
// However, a single SVN revision can modify multple branches, and thus lead to multiple
995+
// However, a single SVN revision can modify multiple branches, and thus lead to multiple
987996
// commits in the same repo. So, we need to maintain a separate commit mark counter.
988997
mark_t mark = ++repository->last_commit_mark;
989998

@@ -1082,4 +1091,6 @@ void FastImportRepository::Transaction::commit()
10821091
while (repository->fastImport.bytesToWrite())
10831092
if (!repository->fastImport.waitForBytesWritten(-1))
10841093
qFatal("Failed to write to process: %s for repository %s", qPrintable(repository->fastImport.errorString()), qPrintable(repository->name));
1094+
1095+
return EXIT_SUCCESS;
10851096
}

src/repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Repository
101101
Transaction() {}
102102
public:
103103
virtual ~Transaction() {}
104-
virtual void commit() = 0;
104+
virtual int commit() = 0;
105105

106106
virtual void setAuthor(const QByteArray &author) = 0;
107107
virtual void setDateTime(uint dt) = 0;

src/svn.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ int SvnRevision::commit()
602602
txn->setDateTime(epoch);
603603
txn->setLog(log);
604604

605-
txn->commit();
605+
if (txn->commit() != EXIT_SUCCESS)
606+
return EXIT_FAILURE;
606607
delete txn;
607608
}
608609

0 commit comments

Comments
 (0)