git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 2/8] convert: Keep foreign $Id$ on checkout.

From
Henrik Grubbström (Grubba) <grubba@grubba.org>
Date
Apr 6, 2010, 12:46 UTC
Message-ID
<946653ea904dfd6d1770f350018697e75a02fb14.1270554878.git.grubba@grubba.org>
In-Reply-To
<cover.1270554878.git.grubba@grubba.org>

If there are foreign $Id$ keywords in the repository, they are most likely there for a reason. Let's keep them on checkout (which is also what the documentation indicates). Foreign $Id$ keywords are now recognized by there being multiple space separated fields in $Id:xxxxx$.

Signed-off-by: Henrik Grubbström <grubba@grubba.org>
---
The typical use case is for repositories that have been converted
from some other VCS, where it is desirable to keep the old identifiers
around until there's some other reason to alter the file.

Note that the comment about expanded Ids in the repository is obsoleted by the core.refilterOnDiff patch.

 convert.c             |   16 ++++++++++++++--
 t/t0021-conversion.sh |    2 +-
 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/convert.c b/convert.c
index 239fa0a..5a0b7fb 100644
--- a/convert.c
+++ b/convert.c
@@ -477,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
                              struct strbuf *buf, int ident)
 {
 	unsigned char sha1[20];
-	char *to_free = NULL, *dollar;
+	char *to_free = NULL, *dollar, *spc;
 	int cnt;
 
 	if (!ident)
@@ -513,7 +513,10 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
 		} else if (src[2] == ':') {
 			/*
 			 * It's possible that an expanded Id has crept its way into the
-			 * repository, we cope with that by stripping the expansion out
+			 * repository, we cope with that by stripping the expansion out.
+			 * This is probably not a good idea, since it will cause changes
+			 * on checkout, which won't go away by stash, but let's keep it
+			 * for git-style ids.
 			 */
 			dollar = memchr(src + 3, '$', len - 3);
 			if (!dollar) {
@@ -526,6 +529,15 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
 				continue;
 			}
 
+			spc = memchr(src + 4, ' ', dollar - src - 4);
+			if (spc && spc < dollar-1) {
+				/* There are spaces in unexpected places.
+				 * This is probably an id from some other
+				 * versioning system. Keep it for now.
+				 */
+				continue;
+			}
+
 			len -= dollar + 1 - src;
 			src  = dollar + 1;
 		} else {
diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index 29438c5..828e35b 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -78,7 +78,7 @@ test_expect_success expanded_in_repo '
 		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
 		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
 		echo "\$Id: NoTerminatingSymbol"
-		echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
+		echo "\$Id: Foreign Commit With Spaces \$"
 		echo "\$Id: NoTerminatingSymbolAtEOF"
 	} > expected-output &&
 
-- 
1.7.0.3.316.g33b5e
Previous: Henrik Grubbström (Grubba)Next: Henrik Grubbström (Grubba)
Message 3 of 14 in “Attribute and conversion patches”
  1. 0/8 Attribute and conversion patchesHenrik Grubbström (Grubba), Apr 6, 2010
  2. 1/8 convert: Safer handling of $Id$ contraction.Henrik Grubbström (Grubba), Apr 6, 2010
  3. 2/8 convert: Keep foreign $Id$ on checkout.Henrik Grubbström (Grubba), Apr 6, 2010
  4. 3/8 status: Added missing calls to diff_unmodified_pair() in format_callbacks.Henrik Grubbström (Grubba), Apr 6, 2010
  5. Junio C HamanoApr 10, 2010
  6. Henrik GrubbströmApr 12, 2010
  7. Junio C HamanoApr 10, 2010
  8. 4/8 diff: Filter files that have changed only due to conversion changes.Henrik Grubbström (Grubba), Apr 6, 2010
  9. Junio C HamanoApr 10, 2010
  10. Henrik GrubbströmApr 16, 2010
  11. 5/8 convert: Added core.refilteronadd feature.Henrik Grubbström (Grubba), Apr 6, 2010
  12. 6/8 attr: Fixed debug output for macro expansion.Henrik Grubbström (Grubba), Apr 6, 2010
  13. 7/8 attr: Allow multiple changes to an attribute on the same line.Henrik Grubbström (Grubba), Apr 6, 2010
  14. 8/8 attr: Expand macros immediately when encountered.Henrik Grubbström (Grubba), Apr 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.