From ad1932e837028fac959b4d41f2cb36824451f084 Mon Sep 17 00:00:00 2001 From: alex2kgit Date: Tue, 9 Aug 2016 15:09:59 +0200 Subject: [PATCH 1/3] Support for importing empty directories in Git --- src/main.cpp | 1 + src/svn.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 709d085..2183711 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,6 +141,7 @@ static const CommandLineOption options[] = { {"--commit-interval NUMBER", "if passed the cache will be flushed to git every NUMBER of commits"}, {"--stats", "after a run print some statistics about the rules"}, {"--svn-branches", "Use the contents of SVN when creating branches, Note: SVN tags are branches as well"}, + {"--empty-dirs", "Add .gitignore-file for empty dirs"}, {"-h, --help", "show help"}, {"-v, --version", "show version"}, CommandLineLastOption diff --git a/src/svn.cpp b/src/svn.cpp index ed32bce..35cdd06 100644 --- a/src/svn.cpp +++ b/src/svn.cpp @@ -408,6 +408,8 @@ class SvnRevision int recurse(const char *path, const svn_fs_path_change2_t *change, const char *path_from, const MatchRuleList &matchRules, svn_revnum_t rev_from, apr_hash_t *changes, apr_pool_t *pool); + int addGitIgnore(apr_pool_t *pool, const char *key, QString path, + svn_fs_root_t *fs_root, Repository::Transaction *txn); private: void splitPathName(const Rules::Match &rule, const QString &pathName, QString *svnprefix_p, 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 // is this a directory? svn_boolean_t is_dir; SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool)); - if (is_dir) { + // Adding newly created directories + if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL) { + QString keyQString = key; + // Skipping SVN-directory-layout + if (keyQString.endsWith("/trunk") || keyQString.endsWith("/branches") || keyQString.endsWith("/tags")) { + //qDebug() << "Skipping SVN-directory-layout:" << keyQString; + return EXIT_SUCCESS; + } + needCommit = true; + //qDebug() << "Adding directory:" << key; + } + else if (is_dir) { if (change->change_kind == svn_fs_path_change_modify || change->change_kind == svn_fs_path_change_add) { if (path_from == NULL) { @@ -845,6 +858,10 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch } else { if(ruledebug) qDebug() << "add/change dir (" << key << "->" << branch << path << ")"; + // Add GitIgnore for empty directories + if (CommandLineParser::instance()->contains("empty-dirs")) { + return addGitIgnore(pool, key, path, fs_root, txn); + } txn->deleteFile(path); recursiveDumpDir(txn, fs_root, key, path, pool); } @@ -928,3 +945,24 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change2_t *change, return EXIT_SUCCESS; } + +int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path, + svn_fs_root_t *fs_root, Repository::Transaction *txn) +{ + // Check for number of subfiles + apr_hash_t *entries; + SVN_ERR(svn_fs_dir_entries(&entries, fs_root, key, pool)); + // Return if any subfiles + if (apr_hash_count(entries)!=0) { + txn->deleteFile(path); + return EXIT_SUCCESS; + } + + // Add empty gitignore-File + QString gitIgnorePath = path + ".gitignore"; + qDebug() << "Adding GitIgnore-File" << gitIgnorePath; + QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0); + io->putChar('\n'); + + return EXIT_SUCCESS; +} From 6b78eb1d09db9d855fef05e9051cd17837cf606d Mon Sep 17 00:00:00 2001 From: alex2kgit Date: Tue, 9 Aug 2016 17:43:37 +0200 Subject: [PATCH 2/3] Skip empty directories by default --- src/svn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svn.cpp b/src/svn.cpp index 35cdd06..3437cb4 100644 --- a/src/svn.cpp +++ b/src/svn.cpp @@ -597,7 +597,7 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change2_t *chang svn_boolean_t is_dir; SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool)); // Adding newly created directories - if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL) { + if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL && CommandLineParser::instance()->contains("empty-dirs")) { QString keyQString = key; // Skipping SVN-directory-layout if (keyQString.endsWith("/trunk") || keyQString.endsWith("/branches") || keyQString.endsWith("/tags")) { From 2c385fc9056112a423ef7f0c56589ef201d739c3 Mon Sep 17 00:00:00 2001 From: alex2kgit Date: Tue, 9 Aug 2016 17:58:21 +0200 Subject: [PATCH 3/3] Recursive dump if subfiles available --- src/svn.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/svn.cpp b/src/svn.cpp index 3437cb4..e2893c9 100644 --- a/src/svn.cpp +++ b/src/svn.cpp @@ -860,7 +860,9 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch qDebug() << "add/change dir (" << key << "->" << branch << path << ")"; // Add GitIgnore for empty directories if (CommandLineParser::instance()->contains("empty-dirs")) { - return addGitIgnore(pool, key, path, fs_root, txn); + if (addGitIgnore(pool, key, path, fs_root, txn) == EXIT_SUCCESS) { + return EXIT_SUCCESS; + } } txn->deleteFile(path); recursiveDumpDir(txn, fs_root, key, path, pool); @@ -946,7 +948,7 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change2_t *change, return EXIT_SUCCESS; } -int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path, + int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path, svn_fs_root_t *fs_root, Repository::Transaction *txn) { // Check for number of subfiles @@ -954,8 +956,7 @@ int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path, SVN_ERR(svn_fs_dir_entries(&entries, fs_root, key, pool)); // Return if any subfiles if (apr_hash_count(entries)!=0) { - txn->deleteFile(path); - return EXIT_SUCCESS; + return EXIT_FAILURE; } // Add empty gitignore-File