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

Re: [PATCH] Replace perl code with pure shell code

From
Junio C Hamano <junkio@cox.net>
Date
Jan 29, 2007, 08:56 UTC
Message-ID
<7vtzya8b4g.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<45BDABB5.4070301@fs.ei.tum.de>
Simon 'corecode' Schubert <corecode@fs.ei.tum.de> writes:
Show 14 quoted lines
> Signed-off-by: Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
> ...
> diff --git a/git-clone.sh b/git-clone.sh
> index ced7dfb..b3c6fa4 100755
> --- a/git-clone.sh
> +++ b/git-clone.sh
> @@ -66,48 +66,6 @@ Perhaps git-update-server-info needs to be run there?"
> ...
> -open FH, "<", "$git_dir/CLONE_HEAD";
> -while (<FH>) {
> -	my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
> -	next if ($name =~ /\^\173/);
> -	if ($name eq "HEAD") {
> ...
Thanks.  I like the general direction, but not quite.

You exposed one outstanding bug, which is a hint about what is not quite right with your patch.

-- >8 -- [PATCH] update-ref: do not accept malformatted refs.

We used to use lock_any_ref_for_update() because the command needs to also update HEAD (which is not under refs/, so lock_ref_sha1() cannot be used). The function however did not check for refs with illegal characters in them.

Use check_ref_format() to catch malformed refs. For this check, we specifically do not want to say having less than two levels in the name is illegal to allow HEAD (and perhaps other special refs in the future).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 1461937..5ee960b 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -61,10 +61,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 
 	lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
 	if (!lock)
-		return 1;
+		die("%s: cannot lock the ref", refname);
 	if (write_ref_sha1(lock, sha1, msg) < 0)
-		return 1;
-
-	/* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
+		die("%s: cannot update the ref", refname);
 	return 0;
 }
diff --git a/refs.c b/refs.c
index 12e46b8..3db444c 100644
--- a/refs.c
+++ b/refs.c
@@ -710,6 +710,8 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
 
 struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1)
 {
+	if (check_ref_format(ref) == -1)
+		return NULL;
 	return lock_ref_sha1_basic(ref, old_sha1, NULL);
 }
 
Previous: Simon 'corecode' SchubertNext: Simon 'corecode' Schubert
Message 2 of 12 in “Replace perl code with pure shell code”
  1. Replace perl code with pure shell codeSimon 'corecode' Schubert, Jan 29, 2007
  2. Junio C HamanoJan 29, 2007
  3. Replace perl code with pure shell codeSimon 'corecode' Schubert, Jan 29, 2007
  4. Shawn O. PearceJan 29, 2007
  5. Randal L. SchwartzJan 29, 2007
  6. Nikolai WeibullJan 29, 2007
  7. Randal L. SchwartzJan 29, 2007
  8. Nikolai WeibullJan 29, 2007
  9. Randal L. SchwartzJan 29, 2007
  10. Junio C HamanoJan 30, 2007
  11. Jakub NarebskiJan 29, 2007
  12. Randal L. SchwartzJan 29, 2007

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.