Subject: bug#72132: Delete commented out code from fileio.c?

From: Stefan Kangas <[email-masked]>
Date: Mon, 15 Jul 2024 23:58:55 +0000

Severity: wishlist

The below code was commented out since Emacs 10.31, and there's a commit
from 2001 saying that it might still be useful. Maybe things have
changed in 23 years, and it's less useful than it used to be.

How about removing it now?

diff --git a/src/fileio.c b/src/fileio.c
index 7afe3e75737..3433f471182 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1758,166 +1758,6 @@ DEFUN ("expand-file-name", Fexpand_file_name,
Sexpand_file_name, 1, 2, 0,
   return result;
 }

-#if 0
-/* PLEASE DO NOT DELETE THIS COMMENTED-OUT VERSION!
-   This is the old version of expand-file-name, before it was thoroughly
-   rewritten for Emacs 10.31.  We leave this version here commented-out,
-   because the code is very complex and likely to have subtle bugs.  If
-   bugs _are_ found, it might be of interest to look at the old code and
-   see what did it do in the relevant situation.
-
-   Don't remove this code: it's true that it will be accessible
-   from the repository, but a few years from deletion, people will
-   forget it is there.  */
-
-/* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'.  */
-DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
-  "Convert FILENAME to absolute, and canonicalize it.\n\
-Second arg DEFAULT is directory to start with if FILENAME is relative\n\
-\(does not start with slash); if DEFAULT is nil or missing,\n\
-the current buffer's value of default-directory is used.\n\
-Filenames containing `.' or `..' as components are simplified;\n\
-initial `~/' expands to your home directory.\n\
-See also the function `substitute-in-file-name'.")
-     (name, defalt)
-     Lisp_Object name, defalt;
-{
-  unsigned char *nm;
-
-  register unsigned char *newdir, *p, *o;
-  ptrdiff_t tlen;
-  unsigned char *target;
-  struct passwd *pw;
-
-  CHECK_STRING (name);
-  nm = SDATA (name);
-
-  /* If nm is absolute, flush ...// and detect /./ and /../.
-     If no /./ or /../ we can return right away.  */
-  if (nm[0] == '/')
-    {
-      bool lose = 0;
-      p = nm;
-      while (*p)
-	{
-	  if (p[0] == '/' && p[1] == '/')
-	    nm = p + 1;
-	  if (p[0] == '/' && p[1] == '~')
-	    nm = p + 1, lose = 1;
-	  if (p[0] == '/' && p[1] == '.'
-	      && (p[2] == '/' || p[2] == 0
-		  || (p[2] == '.' && (p[3] == '/' || p[3] == 0))))
-	    lose = 1;
-	  p++;
-	}
-      if (!lose)
-	{
-	  if (nm == SDATA (name))
-	    return name;
-	  return build_string (nm);
-	}
-    }
-
-  /* Now determine directory to start with and put it in NEWDIR.  */
-
-  newdir = 0;
-
-  if (nm[0] == '~')             /* prefix ~ */
-    if (nm[1] == '/' || nm[1] == 0)/* ~/filename */
-      {
-	if (!(newdir = (unsigned char *) egetenv ("HOME")))
-	  newdir = (unsigned char *) "";
-	nm++;
-      }
-    else  /* ~user/filename */
-      {
-	/* Get past ~ to user.  */
-	unsigned char *user = nm + 1;
-	/* Find end of name.  */
-	unsigned char *ptr = (unsigned char *) strchr (user, '/');
-	ptrdiff_t len = ptr ? ptr - user : strlen (user);
-	/* Copy the user name into temp storage.  */
-	o = alloca (len + 1);
-	memcpy (o, user, len);
-	o[len] = 0;
-
-	/* Look up the user name.  */
-	block_input ();
-	pw = (struct passwd *) getpwnam (o + 1);
-	unblock_input ();
-	if (!pw)
-	  error ("\"%s\" isn't a registered user", o + 1);
-
-	newdir = (unsigned char *) pw->pw_dir;
-
-	/* Discard the user name from NM.  */
-	nm += len;
-      }
-
-  if (nm[0] != '/' && !newdir)
-    {
-      if (NILP (defalt))
-	defalt = current_buffer->directory;
-      CHECK_STRING (defalt);
-      newdir = SDATA (defalt);
-    }
-
-  /* Now concatenate the directory and name to new space in the stack
frame.  */
-
-  tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1;
-  target = alloca (tlen);
-  *target = 0;
-
-  if (newdir)
-    {
-      if (nm[0] == 0 || nm[0] == '/')
-	strcpy (target, newdir);
-      else
-      file_name_as_directory (target, newdir);
-    }
-
-  strcat (target, nm);
-
-  /* Now canonicalize by removing /. and /foo/.. if they appear.  */
-
-  p = target;
-  o = target;
-
-  while (*p)
-    {
-      if (*p != '/')
-	{
-	  *o++ = *p++;
-	}
-      else if (!strncmp (p, "//", 2)
-	       )
-	{
-	  o = target;
-	  p++;
-	}
-      else if (p[0] == '/' && p[1] == '.'
-	       && (p[2] == '/' || p[2] == 0))
-	p += 2;
-      else if (!strncmp (p, "/..", 3)
-	       /* `/../' is the "superroot" on certain file systems.  */
-	       && o != target
-	       && (p[3] == '/' || p[3] == 0))
-	{
-	  while (o != target && *--o != '/')
-	    ;
-	  if (o == target && *o == '/')
-	    ++o;
-	  p += 3;
-	}
-      else
-	{
-	  *o++ = *p++;
-	}
-    }
-
-  return make_string (target, o - target);
-}
-#endif
 
 /* Put into BUF the concatenation of DIR and FILE, with an intervening
    directory separator if needed.  Return a pointer to the null byte