Blame SOURCES/cvs-1.11.23-Back-port-KeywordExpand-configuration-keyword.patch

36e843
From fe7182d15c93f46212781106b4b63503fcec713f Mon Sep 17 00:00:00 2001
36e843
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
36e843
Date: Tue, 15 Mar 2011 14:44:17 +0100
36e843
Subject: [PATCH] Back-port KeywordExpand configuration keyword
36e843
36e843
This is based on code from developemnt 1.12 branch.
36e843
---
36e843
 doc/cvs.texinfo |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
36e843
 src/mkmodules.c |    5 +++
36e843
 src/parseinfo.c |    4 ++
36e843
 src/rcs.c       |   51 ++++++++++++++++++++++++++++--
36e843
 src/rcs.h       |    1 +
36e843
 5 files changed, 146 insertions(+), 8 deletions(-)
36e843
36e843
diff --git a/doc/cvs.texinfo b/doc/cvs.texinfo
36e843
index ad3a414..943af37 100644
36e843
--- a/doc/cvs.texinfo
36e843
+++ b/doc/cvs.texinfo
36e843
@@ -6847,11 +6847,12 @@ with strings of the form
36e843
 a new revision of the file.
36e843
 
36e843
 @menu
36e843
-* Keyword list::                Keywords
36e843
-* Using keywords::              Using keywords
36e843
-* Avoiding substitution::       Avoiding substitution
36e843
-* Substitution modes::          Substitution modes
36e843
-* Log keyword::                 Problems with the $@splitrcskeyword{Log}$ keyword.
36e843
+* Keyword list::                   Keywords
36e843
+* Using keywords::                 Using keywords
36e843
+* Avoiding substitution::          Avoiding substitution
36e843
+* Substitution modes::             Substitution modes
36e843
+* Configuring keyword expansion::  Configuring keyword expansion
36e843
+* Log keyword::                    Problems with the $@splitrcskeyword{Log}$ keyword.
36e843
 @end menu
36e843
 
36e843
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36e843
@@ -7032,6 +7033,12 @@ contains @samp{$@@asis@{@}Author$} whenever the text
36e843
 and @code{troff} you can embed the null-character
36e843
 @code{\&} inside the keyword for a similar effect.
36e843
 
36e843
+It is also possible to specify an explicit list of
36e843
+keywords to include or exclude using the
36e843
+@code{KeywordExpand} option in the
36e843
+@file{CVSROOT/config} file--see @ref{Configuring keyword expansion}
36e843
+for more details.
36e843
+
36e843
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36e843
 @node Substitution modes
36e843
 @section Substitution modes
36e843
@@ -7124,6 +7131,74 @@ handle an export containing binary files correctly.
36e843
 @end table
36e843
 
36e843
 @c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36e843
+@node Configuring keyword expansion
36e843
+@section Configuring Keyword Expansion
36e843
+@cindex Configuring keyword expansion
36e843
+
36e843
+The @code{KeywordExpand} option in the
36e843
+@file{CVSROOT/config} file is intended to allow for the
36e843
+either the explicit exclusion of a keyword or list of
36e843
+keywords, or for the explicit inclusion of a keyword or
36e843
+a list of keywords.
36e843
+
36e843
+The @code{KeywordExpand} option is followed by
36e843
+@code{=} and the next character may either be @code{i}
36e843
+to start an inclusion list or @code{e} to start an
36e843
+exclusion list. If the following lines were added to
36e843
+the @file{CVSROOT/config} file:
36e843
+
36e843
+@example
36e843
+        # Restrict keyword expansion to "Log" only
36e843
+        KeywordExpand=iLog
36e843
+@end example
36e843
+
36e843
+then only the $@splitrcskeyword{Log}$ keyword would be expanded.
36e843
+A list may be used. The this example:
36e843
+
36e843
+@example
36e843
+        # Restrict keyword expansion to the Name and Date keywords.
36e843
+        KeywordExpand=iName,Date
36e843
+@end example
36e843
+
36e843
+would allow $@splitrcskeyword{Name}$, and $@splitrcskeyword{Date}$
36e843
+to be expanded.
36e843
+
36e843
+It is also possible to configure an exclusion list
36e843
+using the following:
36e843
+
36e843
+@example
36e843
+        # Do not expand the keyword Date
36e843
+        KeywordExpand=eDate
36e843
+@end example
36e843
+
36e843
+This allows @sc{cvs} to ignore the 
36e843
+$@splitrcskeyword{CVSHeader}$ keyword and retain all of the
36e843
+others. This could be confusing
36e843
+to users that expect RCS keywords to be expanded, so
36e843
+care should be taken to properly set user expectations
36e843
+for a repository that is configured in that manner.
36e843
+
36e843
+If there is a desire to not have any RCS keywords
36e843
+expanded and not use the @code{-ko} flags everywhere,
36e843
+an administrator may disable all keyword expansion
36e843
+using the @file{CVSROOT/config} line:
36e843
+
36e843
+@example
36e843
+    # Do not expand any RCS keywords
36e843
+    KeywordExpand=i
36e843
+@end example
36e843
+
36e843
+this could be confusing to users that expect RCS
36e843
+keywords like $@splitrcskeyword{Id}$ to be expanded properly,
36e843
+so care should be taken to properly set user
36e843
+expectations for a repository so configured.
36e843
+
36e843
+It should be noted that a patch to provide the
36e843
+@code{KeywordExpand} feature has been around a long time.
36e843
+However, that patch implemented this feature using
36e843
+@code{tagexpand=} keyword and this keyword is NOT recognized.
36e843
+
36e843
+@c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36e843
 @node Log keyword
36e843
 @section Problems with the $@splitrcskeyword{Log}$ keyword.
36e843
 
36e843
@@ -13789,6 +13864,14 @@ each command.  It also provides a place for the
36e843
 @file{CVS/Template} file (@pxref{Working directory
36e843
 storage}).
36e843
 
36e843
+@cindex KeywordExpand, in @file{CVSROOT/config}
36e843
+@item KeywordExpand=@var{value}
36e843
+Specify @samp{i} followed by a list of keywords to be expanded
36e843
+(for example, @samp{KeywordExpand=iName,Date}),
36e843
+or @samp{e} followed by a list of keywords not to be expanded
36e843
+(for example, @samp{KeywordExpand=eName}).
36e843
+For more on keyword expansion, see @ref{Configuring keyword expansion}.
36e843
+
36e843
 @cindex LockDir, in CVSROOT/config
36e843
 @item LockDir=@var{directory}
36e843
 Put @sc{cvs} lock files in @var{directory} rather than
36e843
diff --git a/src/mkmodules.c b/src/mkmodules.c
36e843
index 4bb9d74..3be9509 100644
36e843
--- a/src/mkmodules.c
36e843
+++ b/src/mkmodules.c
36e843
@@ -300,6 +300,11 @@ static const char *const config_contents[] = {
36e843
     "# primary CVS repository.\n",
36e843
     "#IgnoreUnknownConfigKeys=no\n",
36e843
     "\n",
36e843
+    "# Set `KeywordExpand' to `i' followed by a list of keywords to expand or\n",
36e843
+    "# `e' followed by a list of keywords to not expand.\n"
36e843
+    "#KeywordExpand=iName,Date\n",
36e843
+    "#KeywordExpand=eName\n",
36e843
+    "\n",
36e843
     "# Put CVS lock files in this directory rather than directly in the repository.\n",
36e843
     "#LockDir=/var/lock/cvs\n",
36e843
     "\n",
36e843
diff --git a/src/parseinfo.c b/src/parseinfo.c
36e843
index 86fc6d6..477740a 100644
36e843
--- a/src/parseinfo.c
36e843
+++ b/src/parseinfo.c
36e843
@@ -360,6 +360,10 @@ parse_config (cvsroot)
36e843
 		goto error_return;
36e843
 	    }
36e843
 	}
36e843
+	else if (strcmp (line, "KeywordExpand") == 0)
36e843
+	{
36e843
+	    RCS_setincexc (p);
36e843
+	}
36e843
 	else if (strcmp (line, "PreservePermissions") == 0)
36e843
 	{
36e843
 	    if (strcmp (p, "no") == 0)
36e843
diff --git a/src/rcs.c b/src/rcs.c
36e843
index 20c3162..ba255ce 100644
36e843
--- a/src/rcs.c
36e843
+++ b/src/rcs.c
36e843
@@ -15,6 +15,7 @@
36e843
  */
36e843
 
36e843
 #include <assert.h>
36e843
+#include <stdbool.h>
36e843
 #include "cvs.h"
36e843
 #include "edit.h"
36e843
 #include "hardlink.h"
36e843
@@ -3509,9 +3510,10 @@ struct rcs_keyword
36e843
 {
36e843
     const char *string;
36e843
     size_t len;
36e843
+    bool expandit;
36e843
 };
36e843
-#define KEYWORD_INIT(s) (s), sizeof (s) - 1
36e843
-static const struct rcs_keyword keywords[] =
36e843
+#define KEYWORD_INIT(s) (s), sizeof (s) - 1, true
36e843
+static struct rcs_keyword keywords[] =
36e843
 {
36e843
     { KEYWORD_INIT ("Author") },
36e843
     { KEYWORD_INIT ("Date") },
36e843
@@ -3717,7 +3719,8 @@ expand_keywords (rcs, ver, name, log, loglen, expand, buf, len, retbuf, retlen)
36e843
 	slen = s - srch;
36e843
 	for (keyword = keywords; keyword->string != NULL; keyword++)
36e843
 	{
36e843
-	    if (keyword->len == slen
36e843
+	    if (keyword->expandit
36e843
+		&& keyword->len == slen
36e843
 		&& strncmp (keyword->string, srch, slen) == 0)
36e843
 	    {
36e843
 		break;
36e843
@@ -8958,3 +8961,45 @@ make_file_label (path, rev, rcs)
36e843
     }
36e843
     return label;
36e843
 }
36e843
+
36e843
+
36e843
+
36e843
+void
36e843
+RCS_setincexc (const char *arg)
36e843
+{
36e843
+    char *key;
36e843
+    char *copy, *next;
36e843
+    bool include = false;
36e843
+    struct rcs_keyword *keyword;
36e843
+
36e843
+    copy = xstrdup(arg);
36e843
+    next = copy;
36e843
+    switch (*next++) {
36e843
+	case 'e':
36e843
+	    include = false;
36e843
+	    break;
36e843
+	case 'i':
36e843
+	    include = true;
36e843
+	    break;
36e843
+	default:
36e843
+	    free(copy);
36e843
+	    return;
36e843
+    }
36e843
+
36e843
+    if (include)
36e843
+	for (keyword = keywords; keyword->string != NULL; keyword++)
36e843
+	{
36e843
+	    keyword->expandit = false;
36e843
+	}
36e843
+
36e843
+    key = strtok(next, ",");
36e843
+    while (key) {
36e843
+	for (keyword = keywords; keyword->string != NULL; keyword++) {
36e843
+	    if (strcmp (keyword->string, key) == 0)
36e843
+		keyword->expandit = include;
36e843
+	}
36e843
+	key = strtok(NULL, ",");
36e843
+    }
36e843
+    free(copy);
36e843
+    return;
36e843
+}
36e843
diff --git a/src/rcs.h b/src/rcs.h
36e843
index 3a66640..2126029 100644
36e843
--- a/src/rcs.h
36e843
+++ b/src/rcs.h
36e843
@@ -250,6 +250,7 @@ int rcs_change_text PROTO ((const char *, char *, size_t, const char *,
36e843
 void RCS_deltas PROTO ((RCSNode *, FILE *, struct rcsbuffer *, const char *,
36e843
 			enum rcs_delta_op, char **, size_t *,
36e843
 			char **, size_t *));
36e843
+void RCS_setincexc (const char *arg);
36e843
 char *make_file_label PROTO ((const char *, const char *, RCSNode *));
36e843
 
36e843
 extern int preserve_perms;
36e843
-- 
36e843
1.7.4
36e843