如何在 CVS 中获取文件特定修订版的先前修订版

发布于 2024-11-09 12:01:08 字数 51 浏览 0 评论 0原文

是否有任何 CVS 命令可以在给定文件名及其修订版本的情况下为我提供文件的先前修订版本?

Is there any CVS command that can give me previous revision of a file, given the filename and its revision?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

披肩女神 2024-11-16 12:01:08

CVS 控制文件版本的方式是仅当该文件中有提交时才增加修订版本。树或标记等的更改不会影响单个文件的修订。

尽管没有明确的方法可以根据名称和版本来获取文件的先前版本...但是有一个围绕它的点击和试用方法。盲目地去之前的修改。例如,Rev 1.5 的上一个版本将是 Rev 1.4

另一种解决此问题的方法是编写 shell 脚本。使用 cvs log 获取特定文件名的更改日志并 grep 所需的修订号。

The way CVS controls the version of a file is that the revision is increased only when there is a commit in that file. The changes in the tree or tagging etc will not affect the revision of a single file.

Although there is no definite way of getting the previous revision of a file, given the name and it's revision... But there is a hit and trial method around it. Blindly go to the previous revision. For eg, the prev revision of Rev 1.5 would be Rev 1.4

Another way to sort this out is, to write a shell script. Use cvs log to get the change log of a particular filename and grep the desired revision number.

﹉夏雨初晴づ 2024-11-16 12:01:08

没有直接的方法可以通过 CVS 命令执行此操作。但由于我在 java 中使用(CVS 日志)的输出,因此以下代码片段对我有用

if (currentRevision == null || currentRevision.trim().length() == 0) {
    return null;
}

String[] revComponents = currentRevision.trim().split("\\.");

if (revComponents == null || revComponents.length == 0) {
    log.warn("Failed to parse revision number: " + currentRevision
            + " for identification of previous revision");
    return null;
}

if (revComponents.length % 2 == 1) {
    log.warn("Odd number of components in revision: " + currentRevision);
    log.warn("Possibly a tag revision.");
    return null;
}

int lastComp;
try {
    lastComp = Integer.parseInt(revComponents[revComponents.length - 1]);
} catch (NumberFormatException nmfe) {
    log.warn("Failed to parse the last component of revision from " + currentRevision);
    log.warn("Identified presence of alphanumric values in the last component. Cannot predict previous revision for this");
    return null;
}

if (revComponents.length == 2 && lastComp == 1) {
    log.debug("Revision: " + currentRevision + " is the first revision for the current file. Cannot go further back");
    return null;
}

StringBuilder result = new StringBuilder();
if (lastComp == 1) {
    for (int i = 0; i < revComponents.length - 2; i++) {
        if (result.length() > 0)
            result.append('.');
        result.append(revComponents[i]);
    }
} else if (lastComp > 1) {
    for (int i = 0; i < revComponents.length - 1; i++) {
        result.append(revComponents[i]);
        result.append('.');
    }
    result.append((lastComp - 1));
} else {
    log.warn("Found invalid value for last revision number component in " + currentRevision);
        return null;
    }

    return result.toString();
}

上面的代码还处理分支修订,例如,如果当前修订(如图所示)是分支上的第一个修订,它将返回为该文件创建的分支的修订版本。

希望这有帮助。

There is no direct way to do this from CVS commands. But since I am using the output (of CVS log) IN java, following code snippet worked for me

if (currentRevision == null || currentRevision.trim().length() == 0) {
    return null;
}

String[] revComponents = currentRevision.trim().split("\\.");

if (revComponents == null || revComponents.length == 0) {
    log.warn("Failed to parse revision number: " + currentRevision
            + " for identification of previous revision");
    return null;
}

if (revComponents.length % 2 == 1) {
    log.warn("Odd number of components in revision: " + currentRevision);
    log.warn("Possibly a tag revision.");
    return null;
}

int lastComp;
try {
    lastComp = Integer.parseInt(revComponents[revComponents.length - 1]);
} catch (NumberFormatException nmfe) {
    log.warn("Failed to parse the last component of revision from " + currentRevision);
    log.warn("Identified presence of alphanumric values in the last component. Cannot predict previous revision for this");
    return null;
}

if (revComponents.length == 2 && lastComp == 1) {
    log.debug("Revision: " + currentRevision + " is the first revision for the current file. Cannot go further back");
    return null;
}

StringBuilder result = new StringBuilder();
if (lastComp == 1) {
    for (int i = 0; i < revComponents.length - 2; i++) {
        if (result.length() > 0)
            result.append('.');
        result.append(revComponents[i]);
    }
} else if (lastComp > 1) {
    for (int i = 0; i < revComponents.length - 1; i++) {
        result.append(revComponents[i]);
        result.append('.');
    }
    result.append((lastComp - 1));
} else {
    log.warn("Found invalid value for last revision number component in " + currentRevision);
        return null;
    }

    return result.toString();
}

Above code also handles branch revisions, for example, if the current revision (in picture) is the first one on branch that it will return the revision from which branch for that file was created.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文