threads / patch / 1318

patchAdd git-find-new-files to spot files added to the tree, but not the repository

Subject: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

## tl;dr

5 messages between Jul 23, 2005 and Jul 25, 2005. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Ryan Anderson· Jul 23, 2005, 07:42 UTC · lore
Add git-find-new-files to find files that are in the tree, but not checked into the repository.

Most users will probably want to "make clean" before using this for real significant changes, as it does such a good job that it finds binaries that just got built.

Signed-off-by: Ryan Anderson <ryan@michonline.com>
---
 Makefile           |    2 +-
 git-find-new-files |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletions(-)
 create mode 100755 git-find-new-files
028b21ae78dba3edab5e9b1a24cdf68011e42ab7
Show changes to 2 files +49 −1

Makefile, git-find-new-files

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ SCRIPTS=git git-apply-patch-script git-m
 	git-reset-script git-add-script git-checkout-script git-clone-script \
 	gitk git-cherry git-rebase-script git-relink-script git-repack-script \
 	git-format-patch-script git-sh-setup-script git-push-script \
-	git-branch-script git-parse-remote
+	git-branch-script git-parse-remote git-find-new-files
 
 PROG=   git-update-cache git-diff-files git-init-db git-write-tree \
 	git-read-tree git-commit-tree git-cat-file git-fsck-cache \
diff --git a/git-find-new-files b/git-find-new-files
new file mode 100755
--- /dev/null
+++ b/git-find-new-files
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+#
+# A simple script to take a look at all the files git knows about and compare
+# that to the files that we actually see in teh source tree, and output a
+# listing of the difference between them.
+#
+# The original command that did this is below, but a pure-Perl version can skip
+# the temp files.
+#
+#	find . -name .git -type d -prune -o -type f -print \
+#		| grep -v -e .tree1 -e .tree2 \
+#		| sed -e "s/^\.\///" \
+#		| sort >.tree1
+#	git-ls-files | grep -v -e .tree1 -e .tree2 \
+#		| sort >.tree2
+#	diff -u .tree1 .tree2
+
+use warnings;
+use strict;
+
+# Since we're using NUL (ASCII value of 0) to terminate strings,
+# set the field separator to that:
+$/ = "\0";
+
+my (%actual,%git);
+
+open(F,"-|","find . -name .git -type d -prune -o -type f -print0")
+	or die "Failed to open pipe from find: " . $!;
+
+while(<F>) {
+	chomp;
+	s#^\./##;
+	$actual{$_}++;
+}
+close(F);
+
+open(F,"-|","git-ls-files -z")
+	or die "Failed to open pipe from git-ls-files: " . $!;
+
+while(<F>) {
+	chomp;
+	delete $actual{$_};
+}
+close(F);
+
+foreach my $f (sort keys %actual) {
+	printf("A\t%s\n",$f);
+}
-- 
Ryan Anderson
  sometimes Pug Majere
Linus Torvalds· Jul 23, 2005, 17:43 UTC · re: Ryan Anderson · lore

Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

On Sat, 23 Jul 2005, Ryan Anderson wrote:
Show 6 quoted lines
>
> Add git-find-new-files to find files that are in the tree, but not checked into the repository.
> 
> Most users will probably want to "make clean" before using this for real
> significant changes, as it does such a good job that it finds binaries that
> just got built.

You really want to run "file" on the files. We almost certainly don't want to add binary executables, object files etc etc to the tree, so why even show them?

You should also filter the list by the "ignore" file. And I'd suggest ignoring dot-files by default, for example (maybe add a "-a" flag to disable that, the same way "ls" does).

		Linus
Linus Torvalds· Jul 23, 2005, 17:48 UTC · re: Linus Torvalds · lore

Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

On Sat, 23 Jul 2005, Linus Torvalds wrote:
Show 17 quoted lines
> 
> 
> On Sat, 23 Jul 2005, Ryan Anderson wrote:
> >
> > Add git-find-new-files to find files that are in the tree, but not checked into the repository.
> > 
> > Most users will probably want to "make clean" before using this for real
> > significant changes, as it does such a good job that it finds binaries that
> > just got built.
> 
> You really want to run "file" on the files. We almost certainly don't want 
> to add binary executables, object files etc etc to the tree, so why even 
> show them?
> 
> You should also filter the list by the "ignore" file. And I'd suggest
> ignoring dot-files by default, for example (maybe add a "-a" flag to 
> disable that, the same way "ls" does).

Oh, and btw, maybe you didn't realize that "git-ls-files --others" already basically does what your script does? Without any filtering - it was meant to be run from a script, so something like

	for i in $(git-ls-files --others)
	do
		if [ ! match_ignore "$i" ]; then
			case $(file -b $i)
			ELF*)
				;;
			*)
				echo $i
				;;
			esac
		fi
	done
was what I was thinking of.
		Linus
Ryan Anderson· Jul 25, 2005, 06:00 UTC · re: Linus Torvalds · lore

Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

On Sat, Jul 23, 2005 at 10:48:39AM -0700, Linus Torvalds wrote:
> 
> Oh, and btw, maybe you didn't realize that "git-ls-files --others" already 
> basically does what your script does? Without any filtering - it was meant 
> to be run from a script, so something like
That's exactly what I was missing.
The usage on a lot of the commands is very, well, "terse".

I totally missed "others" and I'm not sure I would have caught the significance right away, anyway.

I was going to start a patch series to pull the man pages into each program - but then I just decided it'd be easier to install the man pages.

-- 
Ryan Anderson
  sometimes Pug Majere
Junio C Hamano· Jul 23, 2005, 20:44 UTC · re: Ryan Anderson · lore

Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

Ryan Anderson <ryan@michonline.com> writes:
> Add git-find-new-files to find files that are in the tree, but
> not checked into the repository.
You _ought_ to be able to just say:
 $ git-ls-files --others --exclude-from=<exclude pattern file>

and be done with it. Also please see the thread about Cogito and StGIT's use of .gitignore and .git/exclude files.

The current implementation of "git-ls-files" exclude mechanism may have rooms for improvements; the last time I checked, it only did the matching of patterns against filename without leading directories). The world will be a better place if somebody extends it, instead of working around its limitation.

I may be tempted to doing it myself, but I'm in the middle of something else, so ...

Show 7 quoted lines
> +#	find . -name .git -type d -prune -o -type f -print \
> +#		| grep -v -e .tree1 -e .tree2 \
> +#		| sed -e "s/^\.\///" \
> +#		| sort >.tree1
> +#	git-ls-files | grep -v -e .tree1 -e .tree2 \
> +#		| sort >.tree2
> +#	diff -u .tree1 .tree2

It does not matter since the above is just an example and I think you should be able to just use "ls-files --others", but just FYI, you could have written "comm -23 .tree1 .tree2" above instead of "diff -u".

← back to recent threads