[libvirt] [PATCH] maint: ignore unsaved emacs files

I did a 'git add .', then realized that it ended up trying to add the emacs lock file for a corresponding file that I had not yet saved all my edits; thankfully I noticed it in time. Since we already exclude other temporary files, this makes the most sense for preventing such a mistake from actually hitting upstream. * .gitignore: Add .#* to the exclude list. --- If you don't like this patch, then I will be updating my local .git/info/exclude file; I could understand someone wanting to reject this patch on the grounds that 'make' does not create any temporary files under this name, but only my choice of editor (and not everyone shares that choice in editor). So I'll wait for an ack instead of claiming the trivial rule. .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 804eda4..51d83a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.#* *#*# *.#*# *.a -- 1.7.11.7

On 10/25/2012 06:15 PM, Eric Blake wrote:
I did a 'git add .', then realized that it ended up trying to add the emacs lock file for a corresponding file that I had not yet saved all my edits; thankfully I noticed it in time. Since we already exclude other temporary files, this makes the most sense for preventing such a mistake from actually hitting upstream.
* .gitignore: Add .#* to the exclude list. ---
If you don't like this patch, then I will be updating my local .git/info/exclude file; I could understand someone wanting to reject this patch on the grounds that 'make' does not create any temporary files under this name, but only my choice of editor (and not everyone shares that choice in editor). So I'll wait for an ack instead of claiming the trivial rule.
.gitignore | 1 + 1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore index 804eda4..51d83a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.#* *#*# *.#*# *.a
Well, don't we also ignore *~? That's created by an editor too. ACK.

On 10/25/2012 04:38 PM, Laine Stump wrote:
On 10/25/2012 06:15 PM, Eric Blake wrote:
I did a 'git add .', then realized that it ended up trying to add the emacs lock file for a corresponding file that I had not yet saved all my edits; thankfully I noticed it in time. Since we already exclude other temporary files, this makes the most sense for preventing such a mistake from actually hitting upstream.
* .gitignore: Add .#* to the exclude list. ---
If you don't like this patch, then I will be updating my local .git/info/exclude file; I could understand someone wanting to reject this patch on the grounds that 'make' does not create any temporary files under this name, but only my choice of editor (and not everyone shares that choice in editor). So I'll wait for an ack instead of claiming the trivial rule.
Well, don't we also ignore *~? That's created by an editor too.
Yep.
ACK.
Pushed, before anyone else has a chance to argue against us :) -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 10/25/2012 06:44 PM, Eric Blake wrote:
On 10/25/2012 04:38 PM, Laine Stump wrote:
On 10/25/2012 06:15 PM, Eric Blake wrote:
I did a 'git add .', then realized that it ended up trying to add the emacs lock file for a corresponding file that I had not yet saved all my edits; thankfully I noticed it in time. Since we already exclude other temporary files, this makes the most sense for preventing such a mistake from actually hitting upstream.
* .gitignore: Add .#* to the exclude list. ---
If you don't like this patch, then I will be updating my local .git/info/exclude file; I could understand someone wanting to reject this patch on the grounds that 'make' does not create any temporary files under this name, but only my choice of editor (and not everyone shares that choice in editor). So I'll wait for an ack instead of claiming the trivial rule.
Well, don't we also ignore *~? That's created by an editor too. Yep.
ACK. Pushed, before anyone else has a chance to argue against us :)
What would be *really* nice is if git could give a *warning* if you tried to do git add . and it found any of those files - it would prevent the cases where you forget to save a file that you've modified. (For that matter, it would be nice if make did that :-)

On 10/25/2012 05:12 PM, Laine Stump wrote:
What would be *really* nice is if git could give a *warning* if you tried to do git add . and it found any of those files - it would prevent the cases where you forget to save a file that you've modified.
I suppose it IS possible to make 'git commit' complain loudly if you have unsaved files, or if you tried to add a temporary file as part of the commit, by modifying .git/hooks/pre-commit, but I'm not sure I have the best formula for doing that off-hand, and it's the sort of thing that has to be done in each copy of the tree (and thus, the sort of thing you would want to automate during bootstrap). CC'ing Jim, who has done just that in coreutils' bootstrap.conf, in bootstrap_epilogue(): # Install our git hooks, as long as "cp" accepts the --backup option, # so that we can back up any existing files. case $(cp --help) in *--backup*) backup=1;; *) backup=0;; esac if test $backup = 1; then hooks=$(cd scripts/git-hooks && git ls-files) for f in $hooks; do # If it is identical, skip it. cmp scripts/git-hooks/$f .git/hooks/$f > /dev/null \ && continue cp --backup=numbered scripts/git-hooks/$f .git/hooks chmod a-w .git/hooks/$f done fi
(For that matter, it would be nice if make did that :-)
I run make all the time with unsaved files; in that scenario, it would have to be only a warning and not an error. I'm more comfortable with it being fatal only in a git hook (which happens when you try to commit a mess) and not during development (where a mess might be normal, as part of testing a half-baked theory). But indeed, if there were a way to make maint.mk (or cfg.mk) install some GNU make constructs to add a loud warning on the presence of any editor temporary files, as evidence that we have sniffed an unsaved file so the build may fail in relation to what you have just typed into your editor, that might be a nice improvement. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 10/25/2012 05:12 PM, Laine Stump wrote:
What would be *really* nice is if git could give a *warning* if you tried to do git add . and it found any of those files - it would prevent the cases where you forget to save a file that you've modified.
If you write ChangeLog entries in advance, vc-dwim may do precisely what you want: http://www.gnu.org/s/vc-dwim/ in that it cross-checks that what you say you're going add, change, or remove via ChangeLog with what the VC diffs say you're actually doing. It also checks for editor temporaries, which usually indicate your editor knows about a modified version that you have not yet "saved".
I suppose it IS possible to make 'git commit' complain loudly if you have unsaved files, or if you tried to add a temporary file as part of the commit, by modifying .git/hooks/pre-commit, but I'm not sure I have the best formula for doing that off-hand, and it's the sort of thing that has to be done in each copy of the tree (and thus, the sort of thing you would want to automate during bootstrap).
CC'ing Jim, who has done just that in coreutils' bootstrap.conf, in bootstrap_epilogue():
# Install our git hooks, as long as "cp" accepts the --backup option, # so that we can back up any existing files. case $(cp --help) in *--backup*) backup=1;; *) backup=0;; esac if test $backup = 1; then hooks=$(cd scripts/git-hooks && git ls-files) for f in $hooks; do # If it is identical, skip it. cmp scripts/git-hooks/$f .git/hooks/$f > /dev/null \ && continue cp --backup=numbered scripts/git-hooks/$f .git/hooks chmod a-w .git/hooks/$f done fi
Yep, that's how we install coreutils' custom log-checking local commit hook script. It sounds like you want a combination of that and the piece of vc-dwim that looks for editor temporaries. It uses the names of files that it's diffing or about to commit, and searches for the each corresponding editor temporary file name (emacs and vi*). If it finds a matching temporary file name, it complains. Here's the Perl function from vc-dwim.pl: # For emacs, the temporary is a symlink named "$dir/.#$base", # with useful information in the link name part. # For Vim, the temporary is a regular file named "$dir/.$base.swp". # Vim temporaries can also be named .$base.swo, .$base.swn, .$base.swm, etc. # so test for a few of those, in the unusual event that one of those # exists, but the .swp file does not. sub exists_editor_backup ($) { my ($f) = @_; # If $f is a symlink, use its referent. -l $f and $f = readlink $f; my $d = dirname $f; $f = basename $f; my @candidate_tmp = ( "$d/.#$f", "$d/#$f#", # Emacs map { "$d/.$f.sw$_" } qw (p o n m l k), # Vim ); foreach my $c (@candidate_tmp) { -l $c or -f _ and return $c; # Vim } return undef; }
(For that matter, it would be nice if make did that :-)
I run make all the time with unsaved files; in that scenario, it would have to be only a warning and not an error. I'm more comfortable with it being fatal only in a git hook (which happens when you try to commit a mess) and not during development (where a mess might be normal, as part of testing a half-baked theory). But indeed, if there were a way to make maint.mk (or cfg.mk) install some GNU make constructs to add a loud warning on the presence of any editor temporary files, as evidence that we have sniffed an unsaved file so the build may fail in relation to what you have just typed into your editor, that might be a nice improvement.
participants (3)
-
Eric Blake
-
Jim Meyering
-
Laine Stump