Skip to content

Support for importing empty directories #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion src/svn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 && CommandLineParser::instance()->contains("empty-dirs")) {
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) {
Expand Down Expand Up @@ -845,6 +858,12 @@ 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")) {
if (addGitIgnore(pool, key, path, fs_root, txn) == EXIT_SUCCESS) {
return EXIT_SUCCESS;
}
}
txn->deleteFile(path);
recursiveDumpDir(txn, fs_root, key, path, pool);
}
Expand Down Expand Up @@ -928,3 +947,23 @@ 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) {
return EXIT_FAILURE;
}

// 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;
}