+void Repository::createBranch(const QString &branch, int revnum,
+ const QString &branchFrom, int)
+{
+ startFastImport();
+ if (!branches.contains(branch)) {
+ qWarning() << branch << "is not a known branch in repository" << name << endl
+ << "Going to create it automatically";
+ }
+
+ QByteArray branchRef = branch.toUtf8();
+ if (!branchRef.startsWith("refs/"))
+ branchRef.prepend("refs/heads/");
+
+ Branch &br = branches[branch];
+ if (br.created && br.created != revnum) {
+ QByteArray backupBranch = branchRef + '_' + QByteArray::number(revnum);
+ qWarning() << branch << "already exists; backing up to" << backupBranch;
+
+ fastImport.write("reset " + backupBranch + "\nfrom " + branchRef + "\n\n");
+ }
+
+ // now create the branch
+ br.created = revnum;
+ QByteArray branchFromRef = branchFrom.toUtf8();
+ if (!branchFromRef.startsWith("refs/"))
+ branchFromRef.prepend("refs/heads/");
+
+ if (!branches.contains(branchFrom) || !branches.value(branchFrom).created) {
+ qCritical() << branch << "in repository" << name
+ << "is branching from branch" << branchFrom
+ << "but the latter doesn't exist. Can't continue.";
+ exit(1);
+ }
+
+ fastImport.write("reset " + branchRef + "\nfrom " + branchFromRef + "\n\n"
+ "progress Branch " + branchRef + " created from " + branchFromRef + "\n\n");
+}
+