scmsubversion.cpp revision 54dc8e6c81a07ae54c66e27f210609f2ff529760
/* $Id$ */
/** @file
* IPRT Testcase / Tool - Source Code Massager, Subversion Access.
*/
/*
* Copyright (C) 2010-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#define SCM_WITHOUT_LIBSVN
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
#include "scm.h"
#ifdef SCM_WITHOUT_LIBSVN
/**
* Callback that is call for each path to search.
*/
static DECLCALLBACK(int) scmSvnFindSvnBinaryCallback(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2)
{
{
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#else
#endif
if ( RT_SUCCESS(rc)
&& RTFileExists(pszDst))
return VINF_SUCCESS;
}
return VERR_TRY_AGAIN;
}
/**
* Finds the svn binary.
*
* @param pszPath Where to store it. Worst case, we'll return
* "svn" here.
* @param cchPath The size of the buffer pointed to by @a pszPath.
*/
{
/** @todo code page fun... */
#ifdef RT_OS_WINDOWS
#else
#endif
if (pszPath)
{
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#else
#endif
if (RT_SUCCESS(rc))
return;
}
}
/**
* Construct a dot svn filename for the file being rewritten.
*
* @returns IPRT status code.
* @param pState The rewrite state (for the name).
* @param pszDir The directory, including ".svn/".
* @param pszSuff The filename suffix.
* @param pszDst The output buffer. RTPATH_MAX in size.
*/
static int scmSvnConstructName(PSCMRWSTATE pState, const char *pszDir, const char *pszSuff, char *pszDst)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
{
return VINF_SUCCESS;
}
else
}
}
return rc;
}
/**
* Interprets the specified string as decimal numbers.
*
* @returns true if parsed successfully, false if not.
* @param pch The string (not terminated).
* @param cch The string length.
* @param pu Where to return the value.
*/
{
size_t u = 0;
while (cch-- > 0)
{
return false;
u *= 10;
u += ch - '0';
}
*pu = u;
return true;
}
#endif /* SCM_WITHOUT_LIBSVN */
/**
* Checks if the file we're operating on is part of a SVN working copy.
*
* @returns true if it is, false if it isn't or we cannot tell.
* @param pState The rewrite state to work on.
*/
{
#ifdef SCM_WITHOUT_LIBSVN
/*
*/
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
return RTFileExists(szPath);
#else
#endif
return false;
}
/**
* Queries the value of an SVN property.
*
* This will automatically adjust for scheduled changes.
*
* @returns IPRT status code.
* @retval VERR_INVALID_STATE if not a SVN WC file.
* @retval VERR_NOT_FOUND if the property wasn't found.
* @param pState The rewrite state to work on.
* @param pszName The property name.
* @param ppszValue Where to return the property value. Free this
* using RTStrFree. Optional.
*/
{
/*
* Look it up in the scheduled changes.
*/
while (i-- > 0)
{
if (!pszValue)
return VERR_NOT_FOUND;
if (ppszValue)
return VINF_SUCCESS;
}
#ifdef SCM_WITHOUT_LIBSVN
/*
*/
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* The current format is K len\n<name>\nV len\n<value>\n" ... END.
*/
rc = VERR_NOT_FOUND;
const char *pchLine;
{
/*
* Parse the 'K num' / 'END' line.
*/
if ( cchLine == 3
break;
if ( cchLine < 3
|| pchLine[0] != 'K'
|| cchKey == 0
|| cchKey > 4096)
{
RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
break;
}
/*
* Match the key and skip to the value line. Don't bother with
* names containing EOL markers.
*/
if (fMatch)
{
if (!pchLine)
break;
}
break;
break;
/*
* Read and Parse the 'V num' line.
*/
if (!pchLine)
break;
if ( cchLine < 3
|| pchLine[0] != 'V'
{
RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
break;
}
/*
* If we have a match, allocate a return buffer and read the
* value into it. Otherwise skip this value and continue
* searching.
*/
if (fMatch)
{
if (!ppszValue)
rc = VINF_SUCCESS;
else
{
char *pszValue;
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
else
}
}
break;
}
break;
break;
}
{
}
}
}
if (rc == VERR_FILE_NOT_FOUND)
rc = VERR_NOT_FOUND;
return rc;
#else
#endif
return VERR_NOT_FOUND;
}
/**
* Schedules the setting of a property.
*
* @returns IPRT status code.
* @retval VERR_INVALID_STATE if not a SVN WC file.
* @param pState The rewrite state to work on.
* @param pszName The name of the property to set.
* @param pszValue The value. NULL means deleting it.
*/
{
/*
* Update any existing entry first.
*/
while (i-- > 0)
{
if (!pszValue)
{
}
else
{
char *pszCopy;
if (RT_FAILURE(rc))
return rc;
}
return VINF_SUCCESS;
}
/*
* Insert a new entry.
*/
i = pState->cSvnPropChanges;
if ((i % 32) == 0)
{
if (!pvNew)
return VERR_NO_MEMORY;
}
else
{
return VERR_NO_MEMORY;
}
return VINF_SUCCESS;
}
/**
* Schedules a property deletion.
*
* @returns IPRT status code.
* @param pState The rewrite state to work on.
* @param pszName The name of the property to delete.
*/
{
}
/**
* Applies any SVN property changes to the work copy of the file.
*
* @returns IPRT status code.
* @param pState The rewrite state which SVN property changes
* should be applied.
*/
{
while (i-- > 0)
{
if (pszValue)
else
}
return VINF_SUCCESS;
}
/**
* Applies any SVN property changes to the work copy of the file.
*
* @returns IPRT status code.
* @param pState The rewrite state which SVN property changes
* should be applied.
*/
{
#ifdef SCM_WITHOUT_LIBSVN
/*
* This sucks. We gotta find svn(.exe).
*/
static char s_szSvnPath[RTPATH_MAX];
if (s_szSvnPath[0] == '\0')
/*
* Iterate thru the changes and apply them by starting the svn client.
*/
{
const char *apszArgv[6];
apszArgv[0] = s_szSvnPath;
int iArg = 3;
if (RT_SUCCESS(rc))
{
if ( RT_SUCCESS(rc)
{
RTMsgError("%s: %s %s %s %s %s -> %s %u\n",
: "abducted by alien",
return VERR_GENERAL_FAILURE;
}
}
if (RT_FAILURE(rc))
{
RTMsgError("%s: error executing %s %s %s %s %s: %Rrc\n",
return rc;
}
}
return VINF_SUCCESS;
#else
return VERR_NOT_IMPLEMENTED;
#endif
}