Merge branch 'jc/pickaxe' into next

* jc/pickaxe:
  git-pickaxe -C: blame cut-and-pasted lines.
  git-pickaxe -M: blame line movements within a file.
  git-pickaxe: blame rewritten.
  git-apply: prepare for upcoming GNU diff -u format change.
  Don't use $author_name undefined when $from contains no /\s</.
This commit is contained in:
Junio C Hamano
2006-10-20 00:32:45 -07:00
11 changed files with 1601 additions and 1 deletions

View File

@@ -0,0 +1,124 @@
git-pickaxe(1)
==============
NAME
----
git-pickaxe - Show what revision and author last modified each line of a file
SYNOPSIS
--------
[verse]
'git-pickaxe' [-c] [-l] [-t] [-f] [-n] [-p] [-L n,m] [-S <revs-file>]
[-M] [-C] [-C] [--since=<date>] [<rev>] [--] <file>
DESCRIPTION
-----------
Annotates each line in the given file with information from the revision which
last modified the line. Optionally, start annotating from the given revision.
Also it can limit the range of lines annotated.
This report doesn't tell you anything about lines which have been deleted or
replaced; you need to use a tool such as gitlink:git-diff[1] or the "pickaxe"
interface briefly mentioned in the following paragraph.
Apart from supporting file annotation, git also supports searching the
development history for when a code snippet occured in a change. This makes it
possible to track when a code snippet was added to a file, moved or copied
between files, and eventually deleted or replaced. It works by searching for
a text string in the diff. A small example:
-----------------------------------------------------------------------------
$ git log --pretty=oneline -S'blame_usage'
5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S <ancestry-file>
ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output
-----------------------------------------------------------------------------
OPTIONS
-------
-c, --compatibility::
Use the same output mode as gitlink:git-annotate[1] (Default: off).
-L n,m::
Annotate only the specified line range (lines count from 1).
-l, --long::
Show long rev (Default: off).
-t, --time::
Show raw timestamp (Default: off).
-S, --rev-file <revs-file>::
Use revs from revs-file instead of calling gitlink:git-rev-list[1].
-f, --show-name::
Show filename in the original commit. By default
filename is shown if there is any line that came from a
file with different name, due to rename detection.
-n, --show-number::
Show line number in the original commit (Default: off).
-p, --porcelain::
Show in a format designed for machine consumption.
-M::
Detect moving lines in the file as well. When a commit
moves a block of lines in a file (e.g. the original file
has A and then B, and the commit changes it to B and
then A), traditional 'blame' algorithm typically blames
the lines that were moved up (i.e. B) to the parent and
assigns blame to the lines that were moved down (i.e. A)
to the child commit. With this option, both groups of
lines are blamed on the parent.
-C::
In addition to `-M`, detect lines copied from other
files that were modified in the same commit. This is
useful when you reorganize your program and move code
around across files. When this option is given twice,
the command looks for copies from all other files in the
parent for the commit that creates the file in addition.
-h, --help::
Show help message.
THE PORCELAIN FORMAT
--------------------
In this format, each line is output after a header; the
header at the minumum has the first line which has:
- 40-byte SHA-1 of the commit the line is attributed to;
- the line number of the line in the original file;
- the line number of the line in the final file;
- on a line that starts a group of line from a different
commit than the previous one, the number of lines in this
group. On subsequent lines this field is absent.
This header line is followed by the following information
at least once for each commit:
- author name ("author"), email ("author-mail"), time
("author-time"), and timezone ("author-tz"); similarly
for committer.
- filename in the commit the line is attributed to.
- the first line of the commit log message ("summary").
The contents of the actual line is output after the above
header, prefixed by a TAB. This is to allow adding more
header elements later.
SEE ALSO
--------
gitlink:git-blame[1]
AUTHOR
------
Written by Junio C Hamano <junkio@cox.net>
GIT
---
Part of the gitlink:git[7] suite

View File

@@ -430,6 +430,9 @@ gitlink:git-annotate[1]::
gitlink:git-blame[1]::
Blame file lines on commits.
gitlink:git-pickaxe[1]::
Find out where each line in a file came from.
gitlink:git-check-ref-format[1]::
Make sure ref name is well formed.

View File

@@ -292,6 +292,7 @@ BUILTIN_OBJS = \
builtin-mv.o \
builtin-name-rev.o \
builtin-pack-objects.o \
builtin-pickaxe.o \
builtin-prune.o \
builtin-prune-packed.o \
builtin-push.o \

View File

@@ -934,6 +934,7 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
switch (*line) {
default:
return -1;
case '\n': /* newer GNU diff, an empty context line */
case ' ':
oldlines--;
newlines--;
@@ -1623,6 +1624,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
first = '-';
}
switch (first) {
case '\n':
/* Newer GNU diff, empty context line */
if (plen < 0)
/* ... followed by '\No newline'; nothing */
break;
old[oldsize++] = '\n';
new[newsize++] = '\n';
break;
case ' ':
case '-':
memcpy(old + oldsize, patch + 1, plen);

1396
builtin-pickaxe.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,7 @@ extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
extern int cmd_mv(int argc, const char **argv, const char *prefix);
extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
extern int cmd_pickaxe(int argc, const char **argv, const char *prefix);
extern int cmd_prune(int argc, const char **argv, const char *prefix);
extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
extern int cmd_push(int argc, const char **argv, const char *prefix);

View File

@@ -412,7 +412,7 @@ sub send_message
}
my ($author_name) = ($from =~ /^(.*?)\s+</);
if ($author_name =~ /\./ && $author_name !~ /^".*"$/) {
if ($author_name && $author_name =~ /\./ && $author_name !~ /^".*"$/) {
my ($name, $addr) = ($from =~ /^(.*?)(\s+<.*)/);
$from = "\"$name\"$addr";
}

1
git.c
View File

@@ -247,6 +247,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
{ "mv", cmd_mv, RUN_SETUP },
{ "name-rev", cmd_name_rev, RUN_SETUP },
{ "pack-objects", cmd_pack_objects, RUN_SETUP },
{ "pickaxe", cmd_pickaxe, RUN_SETUP },
{ "prune", cmd_prune, RUN_SETUP },
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
{ "push", cmd_push, RUN_SETUP },

View File

@@ -4,6 +4,7 @@
check_count () {
head=
case "$1" in -h) head="$2"; shift; shift ;; esac
echo "$PROG file $head" >&4
$PROG file $head >.result || return 1
cat .result | perl -e '
my %expect = (@ARGV);

55
t/t4118-apply-empty-context.sh Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/sh
#
# Copyright (c) 2006 Junio C Hamano
#
test_description='git-apply with new style GNU diff with empty context
'
. ./test-lib.sh
test_expect_success setup '
{
echo; echo;
echo A; echo B; echo C;
echo;
} >file1 &&
cat file1 >file1.orig &&
{
cat file1 &&
echo Q | tr -d "\\012"
} >file2 &&
cat file2 >file2.orig
git add file1 file2 &&
sed -e "/^B/d" <file1.orig >file1 &&
sed -e "/^B/d" <file2.orig >file2 &&
cat file1 >file1.mods &&
cat file2 >file2.mods &&
git diff |
sed -e "s/^ \$//" >diff.output
'
test_expect_success 'apply --numstat' '
git apply --numstat diff.output >actual &&
{
echo "0 1 file1" &&
echo "0 1 file2"
} >expect &&
diff -u expect actual
'
test_expect_success 'apply --apply' '
cat file1.orig >file1 &&
cat file2.orig >file2 &&
git update-index file1 file2 &&
git apply --index diff.output &&
diff -u file1.mods file1 &&
diff -u file2.mods file2
'
test_done

9
t/t8003-pickaxe.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
test_description='git-pickaxe'
. ./test-lib.sh
PROG='git pickaxe -c'
. ../annotate-tests.sh
test_done