File indexing completed on 2024-04-28 05:42:09

0001 /***************************************************************************
0002  *   Copyright (C) 2007-2009 by Rajko Albrecht  ral@alwins-world.de        *
0003  *   https://kde.org/applications/development/org.kde.kdesvn               *
0004  *                                                                         *
0005  * This program is free software; you can redistribute it and/or           *
0006  * modify it under the terms of the GNU Lesser General Public              *
0007  * License as published by the Free Software Foundation; either            *
0008  * version 2.1 of the License, or (at your option) any later version.      *
0009  *                                                                         *
0010  * This program is distributed in the hope that it will be useful,         *
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0013  * Lesser General Public License for more details.                         *
0014  *                                                                         *
0015  * You should have received a copy of the GNU Lesser General Public        *
0016  * License along with this program (in the file LGPL.txt); if not,         *
0017  * write to the Free Software Foundation, Inc., 51 Franklin St,            *
0018  * Fifth Floor, Boston, MA  02110-1301  USA                                *
0019  *                                                                         *
0020  * This software consists of voluntary contributions made by many          *
0021  * individuals.  For exact contribution history, see the revision          *
0022  * history and logs, available at https://commits.kde.org/kdesvn.          *
0023  ***************************************************************************/
0024 
0025 #include "conflictresult.h"
0026 
0027 #include "svnqt_defines.h"
0028 
0029 #include <svn_version.h>
0030 #include <svn_wc.h>
0031 
0032 namespace svn
0033 {
0034 ConflictResult::ConflictResult()
0035     : m_choice(ChooseMerged)
0036     , m_MergedFile()
0037 {
0038 }
0039 
0040 ConflictResult::ConflictResult(const svn_wc_conflict_result_t *aResult)
0041     : m_choice(ChooseMerged)
0042 {
0043     if (!aResult) {
0044         return;
0045     }
0046     switch (aResult->choice) {
0047     case svn_wc_conflict_choose_base:
0048         m_choice = ChooseBase;
0049         break;
0050     case svn_wc_conflict_choose_theirs_full:
0051         m_choice = ChooseTheirsFull;
0052         break;
0053     case svn_wc_conflict_choose_mine_full:
0054         m_choice = ChooseMineFull;
0055         break;
0056     case svn_wc_conflict_choose_theirs_conflict:
0057         m_choice = ChooseTheirsConflict;
0058         break;
0059     case svn_wc_conflict_choose_mine_conflict:
0060         m_choice = ChooseMineConflict;
0061         break;
0062     case svn_wc_conflict_choose_merged:
0063         m_choice = ChooseMerged;
0064         break;
0065     case svn_wc_conflict_choose_postpone:
0066     default:
0067         m_choice = ChoosePostpone;
0068         break;
0069     }
0070     if (aResult->merged_file) {
0071         m_MergedFile = QString::fromUtf8(aResult->merged_file);
0072     } else {
0073         m_MergedFile.clear();
0074     }
0075 }
0076 
0077 void ConflictResult::setMergedFile(const QString &aMergedfile)
0078 {
0079     m_MergedFile = aMergedfile;
0080 }
0081 
0082 void ConflictResult::setChoice(ConflictChoice aValue)
0083 {
0084     m_choice = aValue;
0085 }
0086 
0087 void ConflictResult::assignResult(svn_wc_conflict_result_t **aResult, apr_pool_t *pool) const
0088 {
0089     svn_wc_conflict_choice_t _choice;
0090     switch (choice()) {
0091     case ConflictResult::ChooseBase:
0092         _choice = svn_wc_conflict_choose_base;
0093         break;
0094     case ConflictResult::ChooseTheirsFull:
0095         _choice = svn_wc_conflict_choose_theirs_full;
0096         break;
0097     case ConflictResult::ChooseMineFull:
0098         _choice = svn_wc_conflict_choose_mine_full;
0099         break;
0100     case ConflictResult::ChooseTheirsConflict:
0101         _choice = svn_wc_conflict_choose_theirs_conflict;
0102         break;
0103     case ConflictResult::ChooseMineConflict:
0104         _choice = svn_wc_conflict_choose_mine_conflict;
0105         break;
0106     case ConflictResult::ChooseMerged:
0107         _choice = svn_wc_conflict_choose_merged;
0108         break;
0109     case ConflictResult::ChoosePostpone:
0110     default:
0111         _choice = svn_wc_conflict_choose_postpone;
0112         break;
0113     }
0114     const char *_merged_file = mergedFile().isNull() ? nullptr : apr_pstrdup(pool, mergedFile().toUtf8());
0115     if ((*aResult) == nullptr) {
0116         (*aResult) = svn_wc_create_conflict_result(_choice, _merged_file, pool);
0117     } else {
0118         (*aResult)->choice = _choice;
0119         (*aResult)->merged_file = _merged_file;
0120     }
0121 }
0122 
0123 const svn_wc_conflict_result_t *ConflictResult::result(apr_pool_t *pool) const
0124 {
0125     svn_wc_conflict_result_t *result = nullptr;
0126     assignResult(&result, pool);
0127     return result;
0128 }
0129 }