Changeset View
Changeset View
Standalone View
Standalone View
komparemodellist.cpp
Context not available. | |||||
268 | if ( !blendOriginalIntoModelList( m_info->localSource ) ) | 268 | if ( !blendOriginalIntoModelList( m_info->localSource ) ) | ||
---|---|---|---|---|---|
269 | { | 269 | { | ||
270 | qCDebug(LIBKOMPAREDIFF2) << "Oops cant blend original file into modellist : " << m_info->localSource; | 270 | qCDebug(LIBKOMPAREDIFF2) << "Oops cant blend original file into modellist : " << m_info->localSource; | ||
271 | emit( i18n( "<qt>There were problems applying the diff <b>%1</b> to the file <b>%2</b>.</qt>", m_info->destination.url(), m_info->source.url() ) ); | 271 | emit error( i18n( "<qt>There were problems applying the diff <b>%1</b> to the file <b>%2</b>.</qt>", m_info->source.url(), m_info->destination.url() ) ); | ||
272 | return false; | 272 | return false; | ||
273 | } | 273 | } | ||
274 | 274 | | |||
Context not available. | |||||
295 | { | 295 | { | ||
296 | // Trouble blending the original into the model | 296 | // Trouble blending the original into the model | ||
297 | qCDebug(LIBKOMPAREDIFF2) << "Oops cant blend original dir into modellist : " << m_info->localSource; | 297 | qCDebug(LIBKOMPAREDIFF2) << "Oops cant blend original dir into modellist : " << m_info->localSource; | ||
298 | emit error( i18n( "<qt>There were problems applying the diff <b>%1</b> to the folder <b>%2</b>.</qt>", m_info->destination.url(), m_info->source.url() ) ); | 298 | emit error( i18n( "<qt>There were problems applying the diff <b>%1</b> to the folder <b>%2</b>.</qt>", m_info->source.url(), m_info->destination.url() ) ); | ||
299 | return false; | 299 | return false; | ||
300 | } | 300 | } | ||
301 | 301 | | |||
Context not available. | |||||
987 | return 0; | 987 | return 0; | ||
988 | } | 988 | } | ||
989 | 989 | | |||
990 | QString adjustDepthInPath(const QString localURL, const QString sourcePath, const QString destinationPath) | ||||
991 | { | ||||
992 | QString basePath = localURL; | ||||
993 | if( !basePath.endsWith("/") ) | ||||
994 | { | ||||
995 | basePath += "/"; | ||||
996 | } | ||||
997 | | ||||
998 | QStringList sourcePathParts = sourcePath.split("/", QString::SkipEmptyParts); | ||||
999 | QStringList destinationPathParts = destinationPath.split("/", QString::SkipEmptyParts); | ||||
1000 | | ||||
1001 | // Scan source and destination paths' parts going backward and keeping only the common parts | ||||
1002 | int sourceIdx = sourcePathParts.size() - 1; | ||||
1003 | int destinationIdx = destinationPathParts.size() - 1; | ||||
1004 | QString commonPath = ""; | ||||
1005 | | ||||
1006 | while( sourceIdx >= 0 && destinationIdx >= 0 && sourcePathParts.at( sourceIdx ) == destinationPathParts.at( destinationIdx ) ) | ||||
1007 | { | ||||
1008 | if(!commonPath.isEmpty()) | ||||
1009 | commonPath = "/" + commonPath; | ||||
1010 | | ||||
1011 | commonPath = sourcePathParts.at( sourceIdx ) + commonPath; | ||||
1012 | sourceIdx--; | ||||
1013 | destinationIdx--; | ||||
1014 | }; | ||||
1015 | | ||||
1016 | return basePath + commonPath; | ||||
1017 | } | ||||
1018 | | ||||
990 | bool KompareModelList::blendOriginalIntoModelList( const QString& localURL ) | 1019 | bool KompareModelList::blendOriginalIntoModelList( const QString& localURL ) | ||
991 | { | 1020 | { | ||
992 | qCDebug(LIBKOMPAREDIFF2) << "Hurrah we are blending..."; | 1021 | qCDebug(LIBKOMPAREDIFF2) << "Hurrah we are blending..."; | ||
993 | QFileInfo fi( localURL ); | 1022 | QFileInfo fi( localURL ); | ||
994 | 1023 | | |||
995 | bool result = false; | 1024 | bool result = true; | ||
996 | DiffModel* model; | 1025 | DiffModel* model; | ||
997 | 1026 | | |||
998 | QString fileContents; | 1027 | QString fileContents; | ||
Context not available. | |||||
1009 | qCDebug(LIBKOMPAREDIFF2) << "Model : " << model; | 1038 | qCDebug(LIBKOMPAREDIFF2) << "Model : " << model; | ||
1010 | QString filename = model->source(); | 1039 | QString filename = model->source(); | ||
1011 | if ( !filename.startsWith( localURL ) ) | 1040 | if ( !filename.startsWith( localURL ) ) | ||
1012 | filename = QDir(localURL).filePath(filename); | 1041 | { | ||
1042 | filename = adjustDepthInPath(localURL, model->source(), model->destination()); | ||||
1043 | } | ||||
1013 | QFileInfo fi2( filename ); | 1044 | QFileInfo fi2( filename ); | ||
1014 | if ( fi2.exists() ) | 1045 | if ( fi2.exists() ) | ||
1015 | { | 1046 | { | ||
1016 | qCDebug(LIBKOMPAREDIFF2) << "Reading from: " << filename; | 1047 | qCDebug(LIBKOMPAREDIFF2) << "Reading from: " << filename; | ||
1017 | fileContents = readFile( filename ); | 1048 | fileContents = readFile( filename ); | ||
1018 | result = blendFile( model, fileContents ); | 1049 | result = result && blendFile( model, fileContents ); | ||
1019 | } | 1050 | } | ||
1020 | else | 1051 | else | ||
1021 | { | 1052 | { | ||
1022 | qCDebug(LIBKOMPAREDIFF2) << "File " << filename << " does not exist !"; | 1053 | qCDebug(LIBKOMPAREDIFF2) << "File " << filename << " does not exist !"; | ||
1023 | qCDebug(LIBKOMPAREDIFF2) << "Assume empty file !"; | 1054 | qCDebug(LIBKOMPAREDIFF2) << "Assume empty file !"; | ||
1024 | fileContents.truncate( 0 ); | 1055 | fileContents.truncate( 0 ); | ||
1025 | result = blendFile( model, fileContents ); | 1056 | result = result && blendFile( model, fileContents ); | ||
1026 | } | 1057 | } | ||
1027 | } | 1058 | } | ||
1028 | qCDebug(LIBKOMPAREDIFF2) << "End of Blend Dir"; | 1059 | qCDebug(LIBKOMPAREDIFF2) << "End of Blend Dir"; | ||
Context not available. | |||||
1033 | qCDebug(LIBKOMPAREDIFF2) << "Reading from: " << localURL; | 1064 | qCDebug(LIBKOMPAREDIFF2) << "Reading from: " << localURL; | ||
1034 | fileContents = readFile( localURL ); | 1065 | fileContents = readFile( localURL ); | ||
1035 | 1066 | | |||
1036 | result = blendFile( (*m_models)[ 0 ], fileContents ); | 1067 | result = result && blendFile( (*m_models)[ 0 ], fileContents ); | ||
1037 | qCDebug(LIBKOMPAREDIFF2) << "End of Blend File"; | 1068 | qCDebug(LIBKOMPAREDIFF2) << "End of Blend File"; | ||
1038 | } | 1069 | } | ||
1039 | 1070 | | |||
Context not available. | |||||
1042 | 1073 | | |||
1043 | bool KompareModelList::blendFile( DiffModel* model, const QString& fileContents ) | 1074 | bool KompareModelList::blendFile( DiffModel* model, const QString& fileContents ) | ||
1044 | { | 1075 | { | ||
1076 | bool hasConflicts = false; | ||||
1045 | if ( !model ) | 1077 | if ( !model ) | ||
1046 | { | 1078 | { | ||
1047 | qCDebug(LIBKOMPAREDIFF2) << "**** model is null :("; | 1079 | qCDebug(LIBKOMPAREDIFF2) << "**** model is null :("; | ||
Context not available. | |||||
1053 | int srcLineNo = 1, destLineNo = 1; | 1085 | int srcLineNo = 1, destLineNo = 1; | ||
1054 | 1086 | | |||
1055 | QStringList list = split( fileContents ); | 1087 | QStringList list = split( fileContents ); | ||
1056 | QLinkedList<QString> lines; | 1088 | QStringList lines; | ||
1057 | foreach (const QString &str, list) { | 1089 | foreach (const QString &str, list) { | ||
1058 | lines.append(str); | 1090 | lines.append(str); | ||
1059 | } | 1091 | } | ||
1060 | 1092 | | |||
1061 | QLinkedList<QString>::ConstIterator linesIt = lines.begin(); | 1093 | int lineIndex = 0; | ||
1062 | QLinkedList<QString>::ConstIterator lEnd = lines.end(); | | |||
1063 | 1094 | | |||
1064 | DiffHunkList* hunks = model->hunks(); | 1095 | DiffHunkList* hunks = model->hunks(); | ||
1065 | qCDebug(LIBKOMPAREDIFF2) << "Hunks in hunklist: " << hunks->count(); | 1096 | qCDebug(LIBKOMPAREDIFF2) << "Hunks in hunklist: " << hunks->count(); | ||
Context not available. | |||||
1077 | { | 1108 | { | ||
1078 | // Do we need to insert a new hunk before this one ? | 1109 | // Do we need to insert a new hunk before this one ? | ||
1079 | DiffHunk* hunk = *hunkIt; | 1110 | DiffHunk* hunk = *hunkIt; | ||
1111 | | ||||
1112 | // In case we are blending diff with files, check for conflicts | ||||
1113 | if( m_info->mode == Kompare::BlendingDir || m_info->mode == Kompare::BlendingFile ) | ||||
1114 | { | ||||
1115 | for (int i = 0; i < hunk->differences().count(); ++i) { | ||||
1116 | Difference *diff = hunk->differences().at(i); | ||||
1117 | for (int j = 0; j < diff->destinationLineCount(); ++j) { | ||||
1118 | if (lines.size() > diff->destinationLineNumber() + j - 1 && | ||||
1119 | lines.at(diff->destinationLineNumber() + j - 1) != diff->destinationLineAt(j)->string()) { | ||||
1120 | diff->setConflict(true); | ||||
1121 | hasConflicts = true; | ||||
1122 | } | ||||
1123 | } | ||||
1124 | } | ||||
1125 | } | ||||
1126 | | ||||
1080 | if ( srcLineNo < hunk->sourceLineNumber() ) | 1127 | if ( srcLineNo < hunk->sourceLineNumber() ) | ||
1081 | { | 1128 | { | ||
1082 | newHunk = new DiffHunk( srcLineNo, destLineNo, "", DiffHunk::AddedByBlend ); | 1129 | newHunk = new DiffHunk( srcLineNo, destLineNo, "", DiffHunk::AddedByBlend ); | ||
Context not available. | |||||
1088 | 1135 | | |||
1089 | newHunk->add( newDiff ); | 1136 | newHunk->add( newDiff ); | ||
1090 | 1137 | | |||
1091 | while ( srcLineNo < hunk->sourceLineNumber() && linesIt != lEnd ) | 1138 | while ( destLineNo < hunk->destinationLineNumber() && lineIndex < lines.size() ) | ||
1092 | { | 1139 | { | ||
1093 | newDiff->addSourceLine( *linesIt ); | 1140 | newDiff->addSourceLine( lines.at(lineIndex) ); | ||
1094 | newDiff->addDestinationLine( *linesIt ); | 1141 | newDiff->addDestinationLine( lines.at(lineIndex) ); | ||
1095 | srcLineNo++; | 1142 | srcLineNo++; | ||
1096 | destLineNo++; | 1143 | destLineNo++; | ||
1097 | ++linesIt; | 1144 | ++lineIndex; | ||
1098 | } | 1145 | } | ||
1099 | } | 1146 | } | ||
1100 | 1147 | | |||
1101 | // Now we add the linecount difference for the hunk that follows | 1148 | // Now we add the linecount difference for the hunk that follows | ||
1102 | int size = hunk->sourceLineCount(); | 1149 | int size = hunk->destinationLineCount(); | ||
1103 | 1150 | | |||
1104 | for ( int i = 0; i < size; ++i ) | 1151 | for ( int i = 0; i < size; ++i ) | ||
1105 | { | 1152 | { | ||
1106 | ++linesIt; | 1153 | ++lineIndex; | ||
1107 | } | 1154 | } | ||
1108 | 1155 | | |||
1109 | srcLineNo += size; | 1156 | srcLineNo += hunk->sourceLineCount(); | ||
1110 | destLineNo += hunk->destinationLineCount(); | 1157 | destLineNo += size; | ||
1111 | } | 1158 | } | ||
1112 | 1159 | | |||
1113 | if ( linesIt != lEnd ) | 1160 | if ( lineIndex < lines.size() ) | ||
1114 | { | 1161 | { | ||
1115 | newHunk = new DiffHunk( srcLineNo, destLineNo, "", DiffHunk::AddedByBlend ); | 1162 | newHunk = new DiffHunk( srcLineNo, destLineNo, "", DiffHunk::AddedByBlend ); | ||
1116 | 1163 | | |||
Context not available. | |||||
1120 | 1167 | | |||
1121 | newHunk->add( newDiff ); | 1168 | newHunk->add( newDiff ); | ||
1122 | 1169 | | |||
1123 | while ( linesIt != lEnd ) | 1170 | while ( lineIndex < lines.size() ) | ||
1124 | { | 1171 | { | ||
1125 | newDiff->addSourceLine( *linesIt ); | 1172 | newDiff->addSourceLine( lines.at(lineIndex) ); | ||
1126 | newDiff->addDestinationLine( *linesIt ); | 1173 | newDiff->addDestinationLine( lines.at(lineIndex) ); | ||
1127 | ++linesIt; | 1174 | ++lineIndex; | ||
1128 | } | 1175 | } | ||
1129 | } | 1176 | } | ||
1130 | #if 0 | 1177 | #if 0 | ||
Context not available. | |||||
1274 | 1321 | | |||
1275 | m_selectedDifference = m_selectedModel->firstDifference(); | 1322 | m_selectedDifference = m_selectedModel->firstDifference(); | ||
1276 | 1323 | | |||
1277 | return true; | 1324 | return !hasConflicts; | ||
1278 | } | 1325 | } | ||
1279 | 1326 | | |||
1280 | void KompareModelList::show() | 1327 | void KompareModelList::show() | ||
Context not available. |