(file) Return to main.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus_unsupported / utils / cvsbackout

File: [Pegasus] / pegasus_unsupported / utils / cvsbackout / main.cpp (download)
Revision: 1.1, Fri Jul 7 17:32:51 2006 UTC (17 years, 11 months ago) by mike
Branch: MAIN
CVS Tags: HEAD
BUG#: 9999
TITLE: New utility

DESCRIPTION: New utility for backing out CVS changes.

/*
**==============================================================================
**
** Copyright (c) 2003, 2004, 2005, 2006, Michael Brasher
** 
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
** to deal in the Software without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Software, and to permit persons to whom the
** Software is furnished to do so, subject to the following conditions:
** 
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
** 
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
**==============================================================================
*/

#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char** argv)
{
    // Usage:

    if (argc != 2)
    {
	fprintf(stderr, "Usage: %s bug-number\n", argv[0]);
	exit(1);
    }

    // Check bug-number:

    size_t bug_number = atoi(argv[1]);

    if (bug_number == 0)
    {
	fprintf(stderr, "%s: invalid bug-number argument\n", argv[0]);
	exit(1);
    }

    // Run CVS log and save results.

    FILE* is = popen("cvs log", "r");

    if (!is)
    {
	fprintf(stderr, "%s: failed to exec cvs\n", argv[0]);
	exit(1);
    }

    char buffer[1024];
    vector<string> lines;

    while (fgets(buffer, sizeof(buffer), is) != 0)
    {
	// Remove trailing '\n' and '\r' characters.

	char* p = buffer + strlen(buffer);

	while (p != buffer && p[-1] == '\n' || p[-1] == '\r')
	    *--p = '\0';

	// Save working file, bug number, and revision lines only.

	lines.push_back(buffer);
    }

    fclose(is);

    // Build file-revision pairs:

    string file;
    bool found_bug = true;

    for (size_t i = 0; i < lines.size(); i++)
    {
	string line = lines[i];

	if (line.substr(0, 14) == "Working file: ")
	{
	    file = line.substr(14);
	    found_bug = false;
	    continue;
	}

	if (line.substr(0, 6) == "BUG#: " && line.substr(6) == argv[1])
	{
	    found_bug = true;
	    continue;
	}

	if (found_bug && line.substr(0, 9) == "revision ")
	{
	    string rev = line.substr(9).c_str();

	    char cmd[1024];
	    sprintf(cmd, "cvs update -r %s %s", rev.c_str(), file.c_str());
	    printf("%s\n", cmd);
	    system(cmd);
	    found_bug = false;
	}
    }

    return 0;
}

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2