Skip to content

Commit 437beb4

Browse files
author
Torgny Nyblom
committed
Merged 'Import svn-ignore-values and check for other svn-properties'
1 parent 39d4e83 commit 437beb4

File tree

2 files changed

+96
-17
lines changed

2 files changed

+96
-17
lines changed

Diff for: src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ static const CommandLineOption options[] = {
142142
{"--stats", "after a run print some statistics about the rules"},
143143
{"--svn-branches", "Use the contents of SVN when creating branches, Note: SVN tags are branches as well"},
144144
{"--empty-dirs", "Add .gitignore-file for empty dirs"},
145+
{"--svn-ignore", "Import svn-ignore-properties via .gitignore"},
146+
{"--propcheck", "Check for svn-properties except svn-ignore"},
145147
{"-h, --help", "show help"},
146148
{"-v, --version", "show version"},
147149
CommandLineLastOption

Diff for: src/svn.cpp

+94-17
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ class SvnRevision
409409
const char *path_from, const MatchRuleList &matchRules, svn_revnum_t rev_from,
410410
apr_hash_t *changes, apr_pool_t *pool);
411411
int addGitIgnore(apr_pool_t *pool, const char *key, QString path,
412-
svn_fs_root_t *fs_root, Repository::Transaction *txn);
412+
svn_fs_root_t *fs_root, Repository::Transaction *txn, const char *content = NULL);
413+
int fetchIgnoreProps(QString *ignore, apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
414+
int fetchUnknownProps(apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
413415
private:
414416
void splitPathName(const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
415417
QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
@@ -597,7 +599,8 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change2_t *chang
597599
svn_boolean_t is_dir;
598600
SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool));
599601
// Adding newly created directories
600-
if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL && CommandLineParser::instance()->contains("empty-dirs")) {
602+
if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL
603+
&& CommandLineParser::instance()->contains("empty-dirs")) {
601604
QString keyQString = key;
602605
// Skipping SVN-directory-layout
603606
if (keyQString.endsWith("/trunk") || keyQString.endsWith("/branches") || keyQString.endsWith("/tags")) {
@@ -607,6 +610,11 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change2_t *chang
607610
needCommit = true;
608611
//qDebug() << "Adding directory:" << key;
609612
}
613+
// svn:ignore-properties
614+
else if (is_dir && (change->change_kind == svn_fs_path_change_add || change->change_kind == svn_fs_path_change_modify)
615+
&& path_from == NULL && CommandLineParser::instance()->contains("svn-ignore")) {
616+
needCommit = true;
617+
}
610618
else if (is_dir) {
611619
if (change->change_kind == svn_fs_path_change_modify ||
612620
change->change_kind == svn_fs_path_change_add) {
@@ -858,13 +866,42 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
858866
} else {
859867
if(ruledebug)
860868
qDebug() << "add/change dir (" << key << "->" << branch << path << ")";
861-
// Add GitIgnore for empty directories
862-
if (CommandLineParser::instance()->contains("empty-dirs")) {
869+
870+
// Check unknown svn-properties
871+
if (((path_from == NULL && change->prop_mod==1) || (path_from != NULL && change->change_kind == svn_fs_path_change_add))
872+
&& CommandLineParser::instance()->contains("propcheck")) {
873+
if (fetchUnknownProps(pool, key, fs_root) != EXIT_SUCCESS) {
874+
qWarning() << "Error checking svn-properties (" << key << ")";
875+
}
876+
}
877+
878+
int ignoreSet = false;
879+
880+
// Add GitIgnore with svn:ignore
881+
if (((path_from == NULL && change->prop_mod==1) || (path_from != NULL && change->change_kind == svn_fs_path_change_add))
882+
&& CommandLineParser::instance()->contains("svn-ignore")) {
883+
QString svnignore;
884+
// TODO: Check if svn:ignore or other property was changed, but always set on copy/rename (path_from != NULL)
885+
if (fetchIgnoreProps(&svnignore, pool, key, fs_root) != EXIT_SUCCESS) {
886+
qWarning() << "Error fetching svn-properties (" << key << ")";
887+
} else if (!svnignore.isNull()) {
888+
addGitIgnore(pool, key, path, fs_root, txn, svnignore.toStdString().c_str());
889+
ignoreSet = true;
890+
}
891+
}
892+
893+
// Add GitIgnore for empty directories (if GitIgnore was not set previously)
894+
if (CommandLineParser::instance()->contains("empty-dirs") && ignoreSet == false) {
863895
if (addGitIgnore(pool, key, path, fs_root, txn) == EXIT_SUCCESS) {
864896
return EXIT_SUCCESS;
897+
} else {
898+
ignoreSet = true;
865899
}
866900
}
867-
txn->deleteFile(path);
901+
902+
if (ignoreSet == false) {
903+
txn->deleteFile(path);
904+
}
868905
recursiveDumpDir(txn, fs_root, key, path, pool);
869906
}
870907

@@ -948,22 +985,62 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change2_t *change,
948985
return EXIT_SUCCESS;
949986
}
950987

951-
int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path,
952-
svn_fs_root_t *fs_root, Repository::Transaction *txn)
988+
int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path,
989+
svn_fs_root_t *fs_root, Repository::Transaction *txn, const char *content)
953990
{
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;
991+
// Check for number of subfiles if no content
992+
if (!content) {
993+
apr_hash_t *entries;
994+
SVN_ERR(svn_fs_dir_entries(&entries, fs_root, key, pool));
995+
// Return if any subfiles
996+
if (apr_hash_count(entries)!=0) {
997+
return EXIT_FAILURE;
998+
}
960999
}
9611000

962-
// Add empty gitignore-File
1001+
// Add gitignore-File
9631002
QString gitIgnorePath = path + ".gitignore";
964-
qDebug() << "Adding GitIgnore-File" << gitIgnorePath;
965-
QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0);
966-
io->putChar('\n');
1003+
if (content) {
1004+
QIODevice *io = txn->addFile(gitIgnorePath, 33188, strlen(content));
1005+
io->write(content);
1006+
io->putChar('\n');
1007+
} else {
1008+
QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0);
1009+
io->putChar('\n');
1010+
}
1011+
1012+
return EXIT_SUCCESS;
1013+
}
1014+
1015+
int SvnRevision::fetchIgnoreProps(QString *ignore, apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root)
1016+
{
1017+
// Get svn:ignore
1018+
svn_string_t *prop = NULL;
1019+
SVN_ERR(svn_fs_node_prop(&prop, fs_root, key, "svn:ignore", pool));
1020+
if (prop) {
1021+
*ignore = QString(prop->data);
1022+
} else {
1023+
*ignore = QString();
1024+
}
9671025

9681026
return EXIT_SUCCESS;
9691027
}
1028+
1029+
int SvnRevision::fetchUnknownProps(apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root)
1030+
{
1031+
// Check all properties
1032+
apr_hash_t *table;
1033+
SVN_ERR(svn_fs_node_proplist(&table, fs_root, key, pool));
1034+
apr_hash_index_t *hi;
1035+
void *propVal;
1036+
const void *propKey;
1037+
for (hi = apr_hash_first(pool, table); hi; hi = apr_hash_next(hi)) {
1038+
apr_hash_this(hi, &propKey, NULL, &propVal);
1039+
if (strcmp((char*)propKey, "svn:ignore")!=0) {
1040+
qWarning() << "WARN: Unknown svn-property" << (char*)propKey << "set to" << ((svn_string_t*)propVal)->data << "for" << key;
1041+
}
1042+
}
1043+
1044+
return EXIT_SUCCESS;
1045+
}
1046+

0 commit comments

Comments
 (0)