@@ -408,6 +408,8 @@ class SvnRevision
408
408
int recurse (const char *path, const svn_fs_path_change2_t *change,
409
409
const char *path_from, const MatchRuleList &matchRules, svn_revnum_t rev_from,
410
410
apr_hash_t *changes, apr_pool_t *pool);
411
+ int addGitIgnore (apr_pool_t *pool, const char *key, QString path,
412
+ svn_fs_root_t *fs_root, Repository::Transaction *txn);
411
413
private:
412
414
void splitPathName (const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
413
415
QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
@@ -594,7 +596,18 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change2_t *chang
594
596
// is this a directory?
595
597
svn_boolean_t is_dir;
596
598
SVN_ERR (svn_fs_is_dir (&is_dir, fs_root, key, revpool));
597
- if (is_dir) {
599
+ // Adding newly created directories
600
+ if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL && CommandLineParser::instance ()->contains (" empty-dirs" )) {
601
+ QString keyQString = key;
602
+ // Skipping SVN-directory-layout
603
+ if (keyQString.endsWith (" /trunk" ) || keyQString.endsWith (" /branches" ) || keyQString.endsWith (" /tags" )) {
604
+ // qDebug() << "Skipping SVN-directory-layout:" << keyQString;
605
+ return EXIT_SUCCESS;
606
+ }
607
+ needCommit = true ;
608
+ // qDebug() << "Adding directory:" << key;
609
+ }
610
+ else if (is_dir) {
598
611
if (change->change_kind == svn_fs_path_change_modify ||
599
612
change->change_kind == svn_fs_path_change_add) {
600
613
if (path_from == NULL ) {
@@ -845,6 +858,12 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
845
858
} else {
846
859
if (ruledebug)
847
860
qDebug () << " add/change dir (" << key << " ->" << branch << path << " )" ;
861
+ // Add GitIgnore for empty directories
862
+ if (CommandLineParser::instance ()->contains (" empty-dirs" )) {
863
+ if (addGitIgnore (pool, key, path, fs_root, txn) == EXIT_SUCCESS) {
864
+ return EXIT_SUCCESS;
865
+ }
866
+ }
848
867
txn->deleteFile (path);
849
868
recursiveDumpDir (txn, fs_root, key, path, pool);
850
869
}
@@ -928,3 +947,23 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change2_t *change,
928
947
929
948
return EXIT_SUCCESS;
930
949
}
950
+
951
+ int SvnRevision::addGitIgnore (apr_pool_t *pool, const char *key, QString path,
952
+ svn_fs_root_t *fs_root, Repository::Transaction *txn)
953
+ {
954
+ // Check for number of subfiles
955
+ apr_hash_t *entries;
956
+ SVN_ERR (svn_fs_dir_entries (&entries, fs_root, key, pool));
957
+ // Return if any subfiles
958
+ if (apr_hash_count (entries)!=0 ) {
959
+ return EXIT_FAILURE;
960
+ }
961
+
962
+ // Add empty gitignore-File
963
+ QString gitIgnorePath = path + " .gitignore" ;
964
+ qDebug () << " Adding GitIgnore-File" << gitIgnorePath;
965
+ QIODevice *io = txn->addFile (gitIgnorePath, 33188 , 0 );
966
+ io->putChar (' \n ' );
967
+
968
+ return EXIT_SUCCESS;
969
+ }
0 commit comments