54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * IPRT Testcase / Tool - Source Code Massager, Subversion Access.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Copyright (C) 2010-2012 Oracle Corporation
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * available from http://www.virtualbox.org. This file is free software;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * you can redistribute it and/or modify it under the terms of the GNU
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * General Public License (GPL) as published by the Free Software
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync/*******************************************************************************
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync* Header Files *
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync*******************************************************************************/
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/*******************************************************************************
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync* Global Variables *
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync*******************************************************************************/
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Callback that is call for each path to search.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncstatic DECLCALLBACK(int) scmSvnFindSvnBinaryCallback(char const *pchPath, size_t cchPath, void *pvUser1, void *pvUser2)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Reads from a pipe.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns @a rc or other status code.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param rc The current status of the operation. Error status
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * are preserved and returned.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param phPipeR Pointer to the pipe handle.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pcbAllocated Pointer to the buffer size variable.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param poffCur Pointer to the buffer offset variable.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param ppszBuffer Pointer to the buffer pointer variable.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsyncstatic int rtProcProcessOutput(int rc, PRTPIPE phPipeR, size_t *pcbAllocated, size_t *poffCur, char **ppszBuffer,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc2 = RTPipeRead(*phPipeR, szTmp, sizeof(szTmp), &cbRead);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* Resize the buffer. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync size_t cbNew = *pcbAllocated ? *pcbAllocated * 2 : sizeof(szTmp) + 1;
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* Append the new data, terminating it. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* Check for null terminators in the string. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* If we read a full buffer, try read some more. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** @name RTPROCEXEC_FLAGS_XXX - flags for RTProcExec and RTProcExecToString.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** Redirect /dev/null to standard input. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** Redirect standard output to /dev/null. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** Redirect standard error to /dev/null. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** Redirect all standard output to /dev/null as well as directing /dev/null
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * to standard input. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync#define RTPROCEXEC_FLAGS_STD_NULL ( RTPROCEXEC_FLAGS_STDIN_NULL \
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync/** Mask containing the valid flags. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync#define RTPROCEXEC_FLAGS_VALID_MASK UINT32_C(0x00000007)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Runs a process, collecting the standard output and/or standard error.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns IPRT status code
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @retval VERR_NO_TRANSLATION if the output of the program isn't valid UTF-8
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * or contains a nul character.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @retval VERR_TOO_MUCH_DATA if the process produced too much data.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pszExec Executable image to use to create the child process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param papszArgs Pointer to an array of arguments to the child. The
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * array terminated by an entry containing NULL.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param hEnv Handle to the environment block for the child.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param fFlags A combination of RTPROCEXEC_FLAGS_XXX. The @a
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * ppszStdOut and @a ppszStdErr parameters takes precedence
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * over redirection flags.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pStatus Where to return the status on success.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param ppszStdOut Where to return the text written to standard output. If
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * NULL then standard output will not be collected and go
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * to the standard output handle of the process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Free with RTStrFree, regardless of return status.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param ppszStdErr Where to return the text written to standard error. If
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * NULL then standard output will not be collected and go
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * to the standard error handle of the process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Free with RTStrFree, regardless of return status.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsyncint RTProcExecToString(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync PRTPROCSTATUS pStatus, char **ppszStdOut, char **ppszStdErr)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Clear output arguments (no returning failure here, simply crash!).
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Check input arguments.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync AssertReturn(!(fFlags & ~RTPROCEXEC_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Do we need a standard input bitbucket?
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if ((fFlags & RTPROCEXEC_FLAGS_STDIN_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&hChildStdIn.u.hFile, RTFILE_O_READ);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Create the output pipes / bitbuckets.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTPipeCreate(&hPipeStdOutR, &hChildStdOut.u.hPipe, 0 /*fFlags*/);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync else if ((fFlags & RTPROCEXEC_FLAGS_STDOUT_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&hChildStdOut.u.hFile, RTFILE_O_WRITE);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTPipeCreate(&hPipeStdErrR, &hChildStdErr.u.hPipe, 0 /*fFlags*/);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync else if ((fFlags & RTPROCEXEC_FLAGS_STDERR_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&hChildStdErr.u.hFile, RTFILE_O_WRITE);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTPollSetAddPipe(hPollSet, hPipeStdOutR, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, 1);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTPollSetAddPipe(hPollSet, hPipeStdErrR, RTPOLL_EVT_READ | RTPOLL_EVT_ERROR, 2);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Create the process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync 0 /*fFlags*/,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Process output and wait for the process to finish.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = rtProcProcessOutput(rc, &hPipeStdOutR, &cbStdOut, &offStdOut, ppszStdOut, hPollSet, 1);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = rtProcProcessOutput(rc, &hPipeStdErrR, &cbStdErr, &offStdErr, ppszStdErr, hPollSet, 2);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (hPipeStdOutR == NIL_RTPIPE && hPipeStdErrR == NIL_RTPIPE)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc2 = RTProcWait(hProc, RTPROCWAIT_FLAGS_NOBLOCK, pStatus);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if ( (ppszStdOut && *ppszStdOut && !RTStrIsValidEncoding(*ppszStdOut))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync || (ppszStdErr && *ppszStdErr && !RTStrIsValidEncoding(*ppszStdErr)) )
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * No more output, just wait for it to finish.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc2 = RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, pStatus);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Runs a process, waiting for it to complete.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns IPRT status code
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pszExec Executable image to use to create the child process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param papszArgs Pointer to an array of arguments to the child. The
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * array terminated by an entry containing NULL.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param hEnv Handle to the environment block for the child.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param fFlags A combination of RTPROCEXEC_FLAGS_XXX.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pStatus Where to return the status on success.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsyncint RTProcExec(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Clear output argument (no returning failure here, simply crash!).
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Check input arguments.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync AssertReturn(!(fFlags & ~RTPROCEXEC_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Set up /dev/null redirections.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if ((fFlags & RTPROCEXEC_FLAGS_STDIN_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&ah[0].u.hFile, RTFILE_O_READ);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if ((fFlags & RTPROCEXEC_FLAGS_STDOUT_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&ah[1].u.hFile, RTFILE_O_WRITE);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if ((fFlags & RTPROCEXEC_FLAGS_STDERR_NULL) && RT_SUCCESS(rc))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTFileOpenBitBucket(&ah[2].u.hFile, RTFILE_O_WRITE);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Create the process.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync 0 /*fFlags*/,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, pStatus);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Executes SVN and gets the output.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Standard error is suppressed.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns VINF_SUCCESS if the command executed successfully.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pState The rewrite state to work on. Can be NULL.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param papszArgs The SVN argument.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param fNormalFailureOk Whether normal failure is ok.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param ppszStdOut Where to return the output on success.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsyncstatic int scmSvnRunAndGetOutput(PSCMRWSTATE pState, const char **papszArgs, bool fNormalFailureOk, char **ppszStdOut)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = RTGetOptArgvToString(&pszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync ScmVerbose(pState, 2, "executing: %s\n", pszCmdLine);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTProcExecToString(g_szSvnPath, papszArgs, RTENV_DEFAULT,
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTPROCEXEC_FLAGS_STD_NULL, &Status, ppszStdOut, NULL);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (fNormalFailureOk || Status.enmReason != RTPROCEXITREASON_NORMAL)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync Status.enmReason == RTPROCEXITREASON_NORMAL ? "exit code"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : Status.enmReason == RTPROCEXITREASON_SIGNAL ? "signal"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : Status.enmReason == RTPROCEXITREASON_ABEND ? "abnormal end"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : "abducted by alien",
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTMsgError("%s: executing: %s => %Rrc\n", pState->pszFilename, pszCmdLine, rc);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTMsgError("executing: %s => %Rrc\n", pszCmdLine, rc);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Executes SVN.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Standard error and standard output is suppressed.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns VINF_SUCCESS if the command executed successfully.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pState The rewrite state to work on.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param papszArgs The SVN argument.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param fNormalFailureOk Whether normal failure is ok.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsyncstatic int scmSvnRun(PSCMRWSTATE pState, const char **papszArgs, bool fNormalFailureOk)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = RTGetOptArgvToString(&pszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync ScmVerbose(pState, 2, "executing: %s\n", pszCmdLine);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* Lazy bird uses RTProcExecToString. */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = RTProcExec(g_szSvnPath, papszArgs, RTENV_DEFAULT, RTPROCEXEC_FLAGS_STD_NULL, &Status);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (fNormalFailureOk || Status.enmReason != RTPROCEXITREASON_NORMAL)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync Status.enmReason == RTPROCEXITREASON_NORMAL ? "exit code"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : Status.enmReason == RTPROCEXITREASON_SIGNAL ? "signal"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : Status.enmReason == RTPROCEXITREASON_ABEND ? "abnormal end"
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync : "abducted by alien",
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTMsgError("%s: %s -> %Rrc\n", pState->pszFilename, pszCmdLine, rc);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Finds the svn binary, updating g_szSvnPath and g_enmSvnVersion.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync /* Already been called? */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Locate it.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync /** @todo code page fun... */
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = RTPathTraverseList(pszEnvVar, ';', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath));
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = RTPathTraverseList(pszEnvVar, ':', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath));
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Check the version.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync const char *apszArgs[] = { g_szSvnPath, "--version", "--quiet", NULL };
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = scmSvnRunAndGetOutput(pState, apszArgs, false, &pszVersion);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync else if (RTStrVersionCompare(pszVersion, "1.6") >= 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Construct a dot svn filename for the file being rewritten.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state (for the name).
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszDir The directory, including ".svn/".
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszSuff The filename suffix.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszDst The output buffer. RTPATH_MAX in size.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncstatic int scmSvnConstructName(PSCMRWSTATE pState, const char *pszDir, const char *pszSuff, char *pszDst)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync strcpy(pszDst, pState->pszFilename); /* ASSUMES sizeof(szBuf) <= sizeof(szPath) */
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync rc = RTPathAppend(pszDst, RTPATH_MAX, RTPathFilename(pState->pszFilename));
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Interprets the specified string as decimal numbers.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns true if parsed successfully, false if not.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pch The string (not terminated).
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param cch The string length.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pu Where to return the value.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncstatic bool scmSvnReadNumber(const char *pch, size_t cch, size_t *pu)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync while (cch-- > 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync return false;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync return true;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync#endif /* SCM_WITHOUT_LIBSVN */
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Checks if the file we're operating on is part of a SVN working copy.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns true if it is, false if it isn't or we cannot tell.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state to work on.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Hack: check if the .svn/text-base/<file>.svn-base file exists.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = scmSvnConstructName(pState, ".svn/text-base/", ".svn-base", szPath);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync const char *apszArgs[] = { g_szSvnPath, "propget", "svn:no-such-property", pState->pszFilename, NULL };
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = scmSvnRunAndGetOutput(pState, apszArgs, true, &pszValue);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync return true;
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync return false;
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Checks if the specified directory is part of a SVN working copy.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @returns true if it is, false if it isn't or we cannot tell.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * @param pszDir The directory in question.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Hack: check if the .svn/ dir exists.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = RTPathJoin(szPath, sizeof(szPath), pszDir, ".svn");
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync const char *apszArgs[] = { g_szSvnPath, "propget", "svn:no-such-property", pszDir, NULL };
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync int rc = scmSvnRunAndGetOutput(NULL, apszArgs, true, &pszValue);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync return true;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync return false;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Queries the value of an SVN property.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * This will automatically adjust for scheduled changes.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @retval VERR_INVALID_STATE if not a SVN WC file.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @retval VERR_NOT_FOUND if the property wasn't found.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state to work on.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszName The property name.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param ppszValue Where to return the property value. Free this
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * using RTStrFree. Optional.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncint ScmSvnQueryProperty(PSCMRWSTATE pState, const char *pszName, char **ppszValue)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Look it up in the scheduled changes.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync while (i-- > 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Hack: Read the .svn/props/<file>.svn-work file exists.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = scmSvnConstructName(pState, ".svn/props/", ".svn-work", szPath);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = scmSvnConstructName(pState, ".svn/prop-base/", ".svn-base", szPath);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * The current format is K len\n<name>\nV len\n<value>\n" ... END.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Parse the 'K num' / 'END' line.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchKey)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Match the key and skip to the value line. Don't bother with
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * names containing EOL markers.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (RT_FAILURE(ScmStreamSeekAbsolute(&Stream, offKey + cchKey)))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * Read and Parse the 'V num' line.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync || !scmSvnReadNumber(&pchLine[2], cchLine - 2, &cchValue)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync RTMsgError("%s:%u: Unexpected data '%.*s'\n", szPath, ScmStreamTellLine(&Stream), cchLine, pchLine);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * If we have a match, allocate a return buffer and read the
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * value into it. Otherwise skip this value and continue
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync * searching.
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (RT_FAILURE(ScmStreamSeekRelative(&Stream, cchValue)))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync if (RT_FAILURE(ScmStreamSeekByLine(&Stream, ScmStreamTellLine(&Stream) + 1)))
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync const char *apszArgs[] = { g_szSvnPath, "propget", "--strict", pszName, pState->pszFilename, NULL };
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync rc = scmSvnRunAndGetOutput(pState, apszArgs, false, &pszValue);
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Schedules the setting of a property.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @retval VERR_INVALID_STATE if not a SVN WC file.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state to work on.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszName The name of the property to set.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszValue The value. NULL means deleting it.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncint ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Update any existing entry first.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync while (i-- > 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Insert a new entry.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync if ((i % 32) == 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP));
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync pState->paSvnPropChanges[i].pszName = RTStrDup(pszName);
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync && (pState->paSvnPropChanges[i].pszValue || !pszValue) )
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Schedules a property deletion.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state to work on.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pszName The name of the property to delete.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsyncint ScmSvnDelProperty(PSCMRWSTATE pState, const char *pszName)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Applies any SVN property changes to the work copy of the file.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state which SVN property changes
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * should be applied.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync while (i-- > 0)
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync const char *pszName = pState->paSvnPropChanges[i].pszName;
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync const char *pszValue = pState->paSvnPropChanges[i].pszValue;
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync ScmVerbose(pState, 0, "svn propset '%s' '%s' %s\n", pszName, pszValue, pState->pszFilename);
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync ScmVerbose(pState, 0, "svn propdel '%s' %s\n", pszName, pState->pszFilename);
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Applies any SVN property changes to the work copy of the file.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @returns IPRT status code.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * @param pState The rewrite state which SVN property changes
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * should be applied.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync * Iterate thru the changes and apply them by starting the svn client.
54dc8e6c81a07ae54c66e27f210609f2ff529760vboxsync for (size_t i = 0; i < pState->cSvnPropChanges; i++)
3b91cdad96393c90c3098e2805621136b20ef1e6vboxsync apszArgv[1] = pState->paSvnPropChanges[i].pszValue ? "propset" : "propdel";