Commit graph

48 commits

Author SHA1 Message Date
René Scharfe 89d07f750a diff: don't run pager if user asked for a diff style exit code
As Wincent Colaiuta found out, it's a bit unexpected for git diff to
start a pager even when the --quiet option is specified.  The problem
is that the pager hides the return code -- which is the only output
we're interested in in this case.

Push pager setup down into builtin-diff.c and don't start the pager
if --exit-code or --quiet (which implies --exit-code) was specified.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-08-13 13:06:23 -07:00
Jeff King 82cb8afa9b git-diff: turn on recursion by default
The tree recursion behavior of git-diff may appear
inconsistent to the user because it depends on the format of
the patch as well as whether one is diffing between trees or
against the index.

Since git-diff is a porcelain wrapper for low-level diff
commands, it makes sense for its behavior to be consistent
no matter what is being diffed.  This patch turns on
recursion in all cases.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-07-29 13:24:42 -07:00
Junio C Hamano 43342941dd Diff between two blobs should take mode changes into account now.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-24 00:08:49 -07:00
Martin Koegler 01618a3ab1 use mode of the tree in git-diff, if <tree>:<file> syntax is used
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-24 00:08:49 -07:00
Junio C Hamano f1af60bdba Support 'diff=pgm' attribute
This enhances the attributes mechanism so that external programs
meant for existing GIT_EXTERNAL_DIFF interface can be specifed
per path.

To configure such a custom diff driver, first define a custom
diff driver in the configuration:

	[diff "my-c-diff"]
		command = <<your command string comes here>>

Then mark the paths that you want to use this custom driver
using the attribute mechanism.

	*.c	diff=my-c-diff

The intent of this separation is that the attribute mechanism is
used for specifying the type of the contents, while the
configuration mechanism is used to define what needs to be done
to that type of the contents, which would be specific to both
platform and personal taste.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-22 22:16:14 -07:00
Alex Riesen 41bbf9d585 Allow git-diff exit with codes similar to diff(1)
This introduces a new command-line option: --exit-code. The diff
programs will return 1 for differences, return 0 for equality, and
something else for errors.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-14 16:21:19 -07:00
Johannes Schindelin fcfa33ec90 diff: make more cases implicit --no-index
When specifying an absolute path, or a relative path pointing outside
the working tree, do not fail, but roll your own diffopt parsing,
and execute a --no-index diff.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-28 16:32:31 -08:00
Junio C Hamano 048f48a2fd Merge branch 'master' into js/diff-ni
* master: (201 commits)
  Documentation: link in 1.5.0.2 material to the top documentation page.
  Documentation: document remote.<name>.tagopt
  GIT 1.5.0.2
  git-remote: support remotes with a dot in the name
  Documentation: describe "-f/-t/-m" options to "git-remote add"
  diff --cc: fix display of symlink conflicts during a merge.
  merge-recursive: fix longstanding bug in merging symlinks
  merge-index: fix longstanding bug in merging symlinks
  diff --cached: give more sensible error message when HEAD is yet to be created.
  Update tests to use test-chmtime
  Add test-chmtime: a utility to change mtime on files
  Add Release Notes to prepare for 1.5.0.2
  Allow arbitrary number of arguments to git-pack-objects
  rerere: do not deal with symlinks.
  rerere: do not skip two conflicted paths next to each other.
  Don't modify CREDITS-FILE if it hasn't changed.
  diff-patch: Avoid emitting double-slashes in textual patch.
  Reword git-am 3-way fallback failure message.
  Limit filename for format-patch
  core.legacyheaders: Use the description used in RelNotes-1.5.0
  ...
2007-02-26 01:20:42 -08:00
Junio C Hamano 6c09c45138 diff --cached: give more sensible error message when HEAD is yet to be created.
It is not like the user said 'diff --cached HEAD', so complaining about
HEAD not being a valid commit, while technically might be correct, is
not very helpful.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-25 11:09:56 -08:00
Junio C Hamano efdfd6c8d4 Evil Merge branch 'jc/status' (early part) into js/diff-ni
* 'jc/status' (early part):
  run_diff_{files,index}(): update calling convention.
  update-index: do not die too early in a read-only repository.
  git-status: do not be totally useless in a read-only repository.

This is to resolve semantic conflict (which is not textual) that
changes the calling convention of run_diff_files() early.
2007-02-24 02:20:13 -08:00
Johannes Schindelin 75b62b489a git-diff: fix combined diff
The code forgets that typecast binds tighter than addition, in
other words:

    (cast *)array + i  === ((cast *)array) + i

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 21:24:34 -08:00
Johannes Schindelin d516c2d119 Teach git-diff-files the new option --no-index
With this flag and given two paths, git-diff-files behaves as a GNU diff
lookalike (plus the git goodies like --check, colour, etc.).  This flag
is also available in git-diff.  It also works outside of a git repository.

In addition, if git-diff{,-files} is called without revision or stage
parameter, and with exactly two paths at least one of which is not tracked,
the default is --no-index.

So, you can now say

	git diff /etc/inittab /etc/fstab

and it actually works!

This also unifies the duplicated argument parsing between cmd_diff_files()
and builtin_diff_files().

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 20:59:55 -08:00
Junio C Hamano b4e1e4a787 run_diff_{files,index}(): update calling convention.
They used to open and read index themselves, but they now expect
their callers to do so.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 02:02:15 -08:00
Junio C Hamano f2dd1c9adf Revert "git-diff: Introduce --index and deprecate --cached."
This reverts commit 4c81c213a4.

Although --cached and --index are confusing wording, the use of
word --cached for git-diff is consistent with git-apply.  It means
"work with index without looking at the working tree".

We should probably come up with better wording for --cached, if
somebody wants to deprecate it.  But making --index and --cached
synonyms for diff while leaving them mean different things for
apply is no good.
2006-12-13 02:03:11 -08:00
Andreas Ericsson 4c81c213a4 git-diff: Introduce --index and deprecate --cached.
'git diff --cached' still works, but its use is discouraged
in the documentation. 'git diff --index' does the same thing
and is consistent with how 'git apply --index' works.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-01 21:57:04 -08:00
Shawn Pearce e702496e43 Convert memcpy(a,b,20) to hashcpy(a,b).
This abstracts away the size of the hash values when copying them
from memory location to memory location, much as the introduction
of hashcmp abstracted away hash value comparsion.

A few call sites were using char* rather than unsigned char* so
I added the cast rather than open hashcpy to be void*.  This is a
reasonable tradeoff as most call sites already use unsigned char*
and the existing hashcmp is also declared to be unsigned char*.

[jc: Splitted the patch to "master" part, to be followed by a
 patch for merge-recursive.c which is not in "master" yet.

 Fixed the cast in the latter hunk to combine-diff.c which was
 wrong in the original.

 Also converted ones left-over in combine-diff.c, diff-lib.c and
 upload-pack.c ]

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-23 13:53:10 -07:00
David Rientjes a89fccd281 Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
Introduces global inline:

	hashcmp(const unsigned char *sha1, const unsigned char *sha2)

Uses memcmp for comparison and returns the result based on the length of
the hash name (a future runtime decision).

Acked-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-17 14:23:53 -07:00
David Rientjes 0bef57ee44 make inline is_null_sha1 global
Replace sha1 comparisons to null_sha1 with a global inline (which previously an
unused static inline in builtin-apply.c)

[jc: with a fix from Jonas Fonseca.]

Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-15 15:06:03 -07:00
Junio C Hamano f3c5b39567 Merge branch 'th/diff-extra' 2006-08-12 19:34:41 -07:00
Junio C Hamano 306ea2df03 Fix git-diff A...B
Commit 9919f41 meant to make git-diff A...B to (usually) mean
"git-diff `git-merge-base A B` B", but it got the parameters wrong
and ended up showing "git-diff `git-merge-base A B` A" by mistake.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-10 00:50:15 -07:00
Junio C Hamano 72ee96c0f1 check return value from diff_setup_done()
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-09 12:45:27 -07:00
Ramsay Allan Jones 15e593e4d3 Fixup command names in some usage strings.
Most usage strings, such as for command xxx, start with "git-xxx".
This updates the rebels to conform to the general pattern.
(The git wrapper is an exception to this, of course ...)

Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-03 21:38:24 -07:00
Junio C Hamano 53dd8a9cb5 Show both blob names from "git diff blob1 blob2"
Earlier we deliberately showed only blob1's name because showing
both names labeled the output as a renaming patch.  Now the output
routine (namely, diff.c::resolve_rename_copy()) is taught not to
use pathname comparison to tell if a filepair is a rename, we can
safely do this change.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-03 14:41:53 -07:00
Junio C Hamano f82cd3c610 Fix "git diff blob1 blob2" showing the diff in reverse.
This was introduced by mistake when revision.c::add_pending_object()
was modified to use object-array instead of object-list.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-03 11:50:10 -07:00
Linus Torvalds a633fca0c0 Call setup_git_directory() much earlier
This changes the calling convention of built-in commands and
passes the "prefix" (i.e. pathname of $PWD relative to the
project root level) down to them.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-29 01:34:07 -07:00
Linus Torvalds db6296a566 Call setup_git_directory() early
Any git command that expects to work in a subdirectory of a project, and
that reads the git config files (which is just about all of them) needs to
make sure that it does the "setup_git_directory()" call before it tries to
read the config file.

This means, among other things, that we need to move the call out of
"init_revisions()", and into the caller.

This does the mostly trivial conversion to do that.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-28 22:03:06 -07:00
Junio C Hamano f789f82993 Merge branch 'jc/diff'
* jc/diff:
  git-diff A...B to (usually) mean "git-diff `git-merge-base A B` B"
2006-07-28 12:23:52 -07:00
Junio C Hamano ef1d9c5aa4 log and diff family: honor config even from subdirectories
There currently is an unfortunate circular dependency between
what init_revisions (the command line revision specification
parser) does and setting up the log and diff options.  The
function uses setup_git_directory() to find the root of the
project relative to the current directory and calls diff_setup()
to prepare diff generation.  However, some of the things that
diff_setup() does needs to depend on the configuration variable,
which needs to be read after setup_git_directory() is called.

This patch is a low impact workaround.  It first lets
init_revisions() to run and do its thing, then uses git_config()
and diff_setup() after it returns, so that configuration
variables that affects the diff operation can be used from
subdirectories.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-27 22:55:44 -07:00
Junio C Hamano 9919f41c91 git-diff A...B to (usually) mean "git-diff git-merge-base A B B"
This tweaks the argument parser of "git diff" to allow "git-diff
A...B" to show diffs leading to B since their merge-base, when
there is only one sensible merge base between A and B.

Currently nonsense cases are thrown at combined-diff to produce
nonsense results, which would eventually need to be fixed.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-17 01:10:03 -07:00
Linus Torvalds 1974632c66 Remove TYPE_* constant macros and use object_type enums consistently.
This updates the type-enumeration constants introduced to reduce
the memory footprint of "struct object" to match the type bits
already used in the packfile format, by removing the former
(i.e. TYPE_* constant macros) and using the latter (i.e. enum
object_type) throughout the code for consistency.

Eventually we can stop passing around the "type strings"
entirely, and this will help - no confusion about two different
integer enumeration.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-12 23:18:03 -07:00
Pavel Roskin 82e5a82fd7 Fix more typos, primarily in the code
The only visible change is that git-blame doesn't understand
"--compability" anymore, but it does accept "--compatibility" instead,
which is already documented.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-10 00:36:44 -07:00
Junio C Hamano 83ad63cfeb diff: do not use configuration magic at the core-level
The Porcelainish has become so much usable as the UI that there
is not much reason people should be using the core programs by
hand anymore.  At this point we are better off making the
behaviour of the core programs predictable by keeping them
unaffected by the configuration variables.  Otherwise they will
become very hard to use as reliable building blocks.

For example, "git-commit -a" internally uses git-diff-files to
figure out the set of paths that need to be updated in the
index, and we should never allow diff.renames that happens to be
in the configuration to interfere (or slow down the process).

The UI level configuration such as showing renamed diff and
coloring are still honored by the Porcelainish ("git log" family
and "git diff"), but not by the core anymore.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-08 03:11:01 -07:00
Timo Hirvonen 5faf64cd28 Remove awkward compatibility warts
Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-01 22:26:00 -07:00
Junio C Hamano 047fbe906b builtin-diff: turn recursive on when defaulting to --patch format.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-01 22:15:40 -07:00
Timo Hirvonen c9b5ef998a Set default diff output format after parsing command line
Initialize output_format to 0 instead of DIFF_FORMAT_RAW so that we can see
later if any command line options changed it.  Default value is set only if
output format was not specified.

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-26 14:58:40 -07:00
Timo Hirvonen a610786f4b Make --raw option available for all diff commands
Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-26 14:58:40 -07:00
Timo Hirvonen c6744349df Merge with_raw, with_stat and summary variables to output_format
DIFF_FORMAT_* are now bit-flags instead of enumerated values.

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-26 14:58:40 -07:00
Linus Torvalds 1f1e895fcc Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.

That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.

This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.

The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).

One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.

It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-19 18:45:48 -07:00
Linus Torvalds 885a86abe2 Shrink "struct object" a bit
This shrinks "struct object" by a small amount, by getting rid of the
"struct type *" pointer and replacing it with a 3-bit bitfield instead.

In addition, we merge the bitfields and the "flags" field, which
incidentally should also remove a useless 4-byte padding from the object
when in 64-bit mode.

Now, our "struct object" is still too damn large, but it's now less
obviously bloated, and of the remaining fields, only the "util" (which is
not used by most things) is clearly something that should be eventually
discarded.

This shrinks the "git-rev-list --all" memory use by about 2.5% on the
kernel archive (and, perhaps more importantly, on the larger mozilla
archive). That may not sound like much, but I suspect it's more on a
64-bit platform.

There are other remaining inefficiencies (the parent lists, for example,
probably have horrible malloc overhead), but this was pretty obvious.

Most of the patch is just changing the comparison of the "type" pointer
from one of the constant string pointers to the appropriate new TYPE_xxx
small integer constant.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-17 18:49:18 -07:00
Junio C Hamano 328b710d80 Merge branch 'master' into js/fmt-patch
* master: (119 commits)
  diff family: add --check option
  Document that "git add" only adds non-ignored files.
  Add a conversion tool to migrate remote information into the config
  fetch, pull: ask config for remote information
  Fix build procedure for builtin-init-db
  read-tree -m -u: do not overwrite or remove untracked working tree files.
  apply --cached: do not check newly added file in the working tree
  Implement a --dry-run option to git-quiltimport
  Implement git-quiltimport
  Revert "builtin-grep: workaround for non GNU grep."
  builtin-grep: workaround for non GNU grep.
  builtin-grep: workaround for non GNU grep.
  git-am: use apply --cached
  apply --cached: apply a patch without using working tree.
  apply --numstat: show new name, not old name.
  Documentation/Makefile: create tarballs for the man pages and html files
  Allow pickaxe and diff-filter options to be used by git log.
  Libify the index refresh logic
  Builtin git-init-db
  Remove unnecessary local in get_ref_sha1.
  ...
2006-05-21 01:34:54 -07:00
Junio C Hamano 065e0b126f builtin-diff: do not say files are renamed when blob and file are given
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-18 14:35:37 -07:00
Junio C Hamano e4e23f3a1c builtin-diff: fix comparison between two blobs.
The code forgot that setup_revisions() leaves parsed object
names in reverse in the list.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-15 19:05:50 -07:00
Peter Hagervall d92f1dc63f Sparse fix for builtin-diff
You gotta love sparse:

builtin-diff.c:88:4: error: Just how const do you want this type to be?

Signed-off-by: Peter Hagervall <hager@cs.umu.se>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-07 15:36:10 -07:00
Johannes Schindelin e686eb9870 fmt-patch: understand old <his> notation
When calling "git fmt-patch HEAD~5", you now get the same as if you would
have said "git fmt-patch HEAD~5..". This makes it easier for my fingers
which are so used to the old syntax.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-06 14:43:33 -07:00
Junio C Hamano 230f544e87 Merge branch 'jc/diff'
* jc/diff:
  builtin-diff: call it "git-diff", really.
  builtin-diff.c: die() formatting type fix.
  built-in diff: assorted updates.
  built-in diff.
2006-05-03 23:54:34 -07:00
Junio C Hamano 334b506a34 builtin-diff.c: die() formatting type fix.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-30 00:26:41 -07:00
Junio C Hamano 0fe7c1de16 built-in diff: assorted updates.
"git diff(n)" without --base, --ours, etc. defaults to --cc,
which usually is the same as -p unless you are in the middle of
a conflicted merge, just like the shell script version.

"git diff(n) blobA blobB path" complains and dies.

"git diff(n) tree0 tree1 tree2...treeN" does combined diff that
shows a merge of tree1..treeN to result in tree0.

Giving "-c" option to any command that defaults to "--cc" turns
off dense-combined flag.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-29 01:32:53 -07:00
Junio C Hamano 65056021f2 built-in diff.
This starts to replace the shell script version of "git diff".

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-28 23:20:52 -07:00