@@ -386,6 +386,7 @@ class SvnRevision
386
386
int fetchIgnoreProps (QString *ignore, apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
387
387
int fetchUnknownProps (apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
388
388
private:
389
+ int checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn);
389
390
void splitPathName (const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
390
391
QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
391
392
int recursiveDumpDir (Repository::Transaction *txn, svn_fs_t *fs, svn_fs_root_t *fs_root,
@@ -868,6 +869,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
868
869
if (ruledebug)
869
870
qDebug () << " add/change file (" << key << " ->" << branch << path << " )" ;
870
871
dumpBlob (txn, fs_root, key, path, pool);
872
+ checkParentNoLongerEmpty (pool, key, path, txn);
871
873
} else {
872
874
if (ruledebug)
873
875
qDebug () << " add/change dir (" << key << " ->" << branch << path << " )" ;
@@ -897,6 +899,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
897
899
txn->deleteFile (path);
898
900
checkParentNotEmpty (pool, key, path, fs_root, txn);
899
901
}
902
+ checkParentNoLongerEmpty (pool, key, path, txn);
900
903
901
904
// Add GitIgnore with svn:ignore
902
905
int ignoreSet = false ;
@@ -1168,6 +1171,67 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
1168
1171
return EXIT_SUCCESS;
1169
1172
}
1170
1173
1174
+ int SvnRevision::checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn) {
1175
+ if (!CommandLineParser::instance ()->contains (" empty-dirs" )) {
1176
+ return EXIT_FAILURE;
1177
+ }
1178
+ QString slash = " /" ;
1179
+ QString qkey = QString::fromUtf8 (key);
1180
+ while (qkey.endsWith (' /' ))
1181
+ qkey = qkey.mid (0 , qkey.length ()-1 );
1182
+ int index = qkey.lastIndexOf (slash);
1183
+ if (index == -1 ) {
1184
+ return EXIT_FAILURE;
1185
+ }
1186
+ QString parentKey = qkey.left (index );
1187
+
1188
+ AprAutoPool subpool (pool);
1189
+ svn_fs_root_t *previous_fs_root;
1190
+ if (svn_fs_revision_root (&previous_fs_root, fs, revnum - 1 , subpool) != SVN_NO_ERROR) {
1191
+ return EXIT_FAILURE;
1192
+ }
1193
+
1194
+ apr_hash_t *entries;
1195
+ // directory did not exist
1196
+ if (svn_fs_dir_entries (&entries, previous_fs_root, parentKey.toStdString ().c_str (), pool) != SVN_NO_ERROR) {
1197
+ return EXIT_FAILURE;
1198
+ }
1199
+
1200
+ // directory was not empty
1201
+ if (apr_hash_count (entries)!=0 ) {
1202
+ return EXIT_FAILURE;
1203
+ }
1204
+
1205
+ QString cleanPath = path;
1206
+ while (cleanPath.endsWith (' /' ))
1207
+ cleanPath = cleanPath.mid (0 , cleanPath.length ()-1 );
1208
+ index = cleanPath.lastIndexOf (slash);
1209
+ QString parentPath = cleanPath.left (index );
1210
+
1211
+ // we are in the root directory, we did not add a .gitignore here
1212
+ if (index == -1 ) {
1213
+ return EXIT_FAILURE;
1214
+ }
1215
+
1216
+ // if svn-ignore should have added a .gitignore file, do not consider the directory empty
1217
+ // if svn:ignore could not be determined, stay safe and do not consider the directory empty
1218
+ // even if then an empty .gitignore might be left over
1219
+ QString svnignore;
1220
+ if (CommandLineParser::instance ()->contains (" svn-ignore" )) {
1221
+ if (fetchIgnoreProps (&svnignore, pool, parentKey.toStdString ().c_str (), previous_fs_root) != EXIT_SUCCESS) {
1222
+ qWarning () << " Error fetching svn-properties (" << parentKey << " )" ;
1223
+ return EXIT_FAILURE;
1224
+ } else if (!svnignore.isNull ()) {
1225
+ return EXIT_FAILURE;
1226
+ }
1227
+ }
1228
+
1229
+ // Delete gitignore-File
1230
+ QString gitIgnorePath = parentPath + " /.gitignore" ;
1231
+ txn->deleteFile (gitIgnorePath);
1232
+ return EXIT_SUCCESS;
1233
+ }
1234
+
1171
1235
int SvnRevision::addGitIgnoreOnBranch (apr_pool_t *pool, QString key, QString path,
1172
1236
svn_fs_root_t *fs_root, Repository::Transaction *txn)
1173
1237
{
0 commit comments