Skip to content

Detect when git commands delete or move a file that had ~nn~ versions left behind #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
masinter opened this issue Nov 19, 2021 · 4 comments

Comments

@masinter
Copy link
Member

One of the interactions between Medley and Git is the handling of deleting a file from the repo.

If I have on my local disk FOO FOO.~1~ and FOO.~2~ and with some git action that updates FOO (checkout of another branch), it recovers OK : git will break the hard link between FOO and FOO.~2~ and Lisp will see FOO;3.

But things aren't so good if the checkout deletes FOO because FOO.~1~ and FOO.~2~ are still around. Lisp will see INFILEP(FOO) finding FOO:2.

At the very least, a github "hook" could warn the user when the checkout deleted a file while there are ~nn~ versions.

In fact, this doesn't really have to do with git and it could be in lisp. Just detect when file versions are in a state that conflicts with Lisp's expectations:

@masinter
Copy link
Member Author

Personally, I deal with this by periodically

find . -name "*~" -exec rm {} \;

but this needs to work for everyone

https://github.com/CompSciLauren/awesome-git-hooks/blob/master/post-checkout-hooks/delete-pyc-files.hook is an example of a git "hook" that does something similar.

Maybe just make this a feature of medley-fix-links? We might implement something like this as a warning at the git level and a service in medley?

See #303

@masinter
Copy link
Member Author

I still worry about this often, whenever I submit a PR that moves things around.
If someone checks out a new branch, it will delete the 'versionless file' and Lisp will come along and recreate it quietly.

This could be simply addressed in maiko by removing the special case of recreating, in src/dsk.c
I'm not sure what errno should be tho...

probably it should just not recognize the file at all. So if you have FOO.1 and FOO.2 but no FOO at all Lisp just won't see it.

  if (*old_file == '\0') {
    /*
     * The versionless file is not linked to any file in varray.
     * Thus, we have to link the versionless file to the file which
     * is versioned one higher than the existing highest version.
     */
    FindHighestVersion(varray, entry, max_no);
    sprintf(ver, "%u", max_no + 1);
/*
 * The old file should have the same case name as the versionless
 * file.
 */
#ifndef DOS
    ConcNameAndVersion(vless, ver, old_file);
    TIMEOUT(rval = link(vless, old_file));
    if (rval == -1) {
      *Lisp_errno = errno;
      return (0);
    }
#endif /* DOS */
    return (1);
  }

@nbriggs
Copy link
Contributor

nbriggs commented Sep 29, 2022

I don't think breaking the "versionless file is linked to highest versioned file" paradigm is a good thing.
It's not about what happens in a git repository working directory, but what happens in someone's actual workspace.

@masinter
Copy link
Member Author

just to be clear, I'm not proposing breaking the paradigm, just the ill-considered recovery, when other system operations have caused an anomalous situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants