git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
@ 2005-07-23  7:42 Ryan Anderson
  2005-07-23 17:43 ` Linus Torvalds
  2005-07-23 20:44 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Ryan Anderson @ 2005-07-23  7:42 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

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
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
  2005-07-23  7:42 [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository Ryan Anderson
@ 2005-07-23 17:43 ` Linus Torvalds
  2005-07-23 17:48   ` Linus Torvalds
  2005-07-23 20:44 ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2005-07-23 17:43 UTC (permalink / raw)
  To: Ryan Anderson; +Cc: git



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).

		Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
  2005-07-23 17:43 ` Linus Torvalds
@ 2005-07-23 17:48   ` Linus Torvalds
  2005-07-25  6:00     ` Ryan Anderson
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2005-07-23 17:48 UTC (permalink / raw)
  To: Ryan Anderson; +Cc: git



On Sat, 23 Jul 2005, Linus Torvalds wrote:

> 
> 
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
  2005-07-23  7:42 [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository Ryan Anderson
  2005-07-23 17:43 ` Linus Torvalds
@ 2005-07-23 20:44 ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2005-07-23 20:44 UTC (permalink / raw)
  To: Ryan Anderson; +Cc: git

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 ...

> +#	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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
  2005-07-23 17:48   ` Linus Torvalds
@ 2005-07-25  6:00     ` Ryan Anderson
  0 siblings, 0 replies; 5+ messages in thread
From: Ryan Anderson @ 2005-07-25  6:00 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-07-25  6:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-23  7:42 [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository Ryan Anderson
2005-07-23 17:43 ` Linus Torvalds
2005-07-23 17:48   ` Linus Torvalds
2005-07-25  6:00     ` Ryan Anderson
2005-07-23 20:44 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).