aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-08-16 22:30:46 -0700
committerJunio C Hamano <junkio@cox.net>2005-08-16 22:30:46 -0700
commit6680153441de6fbba07868d5f54af74d31a3ff13 (patch)
tree200df64306c16fb12a5068092d92237ba33cd7b9
parent7de94155add87f7cd8aaddbef224669e62d3302a (diff)
parent6bff6a60680ef402f614abae8189c2cb198cfa49 (diff)
downloadgit-6680153441de6fbba07868d5f54af74d31a3ff13.tar.gz
git-6680153441de6fbba07868d5f54af74d31a3ff13.tar.xz
Merge with master to get diff fixes.
-rw-r--r--Makefile2
-rw-r--r--cache.h3
-rw-r--r--diff-cache.c12
-rw-r--r--diff-files.c11
-rw-r--r--diff-tree.c17
-rw-r--r--diffcore-pathspec.c2
-rwxr-xr-xgit-diff-script4
-rwxr-xr-xgit-format-patch-script31
-rw-r--r--read-cache.c2
-rw-r--r--rev-parse.c7
-rw-r--r--setup.c118
-rw-r--r--sha1_file.c26
-rwxr-xr-xtools/git-applymbox11
-rwxr-xr-xtools/git-applypatch5
-rw-r--r--tools/mailinfo.c15
15 files changed, 221 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 162324727..c0a84298b 100644
--- a/Makefile
+++ b/Makefile
@@ -97,7 +97,7 @@ LIB_H=cache.h object.h blob.h tree.h commit.h tag.h delta.h epoch.h csum-file.h
LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \
tag.o date.o index.o diff-delta.o patch-delta.o entry.o path.o \
refs.o csum-file.o pack-check.o pkt-line.o connect.o ident.o \
- sha1_name.o
+ sha1_name.o setup.o
LIB_H += rev-cache.h
LIB_OBJS += rev-cache.o
diff --git a/cache.h b/cache.h
index f14a4ce91..6365381c1 100644
--- a/cache.h
+++ b/cache.h
@@ -140,6 +140,9 @@ extern char *get_graft_file(void);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
+extern const char **get_pathspec(const char *prefix, char **pathspec);
+extern const char *setup_git_directory(void);
+
#define alloc_nr(x) (((x)+16)*3/2)
/* Initialize and use the cache information */
diff --git a/diff-cache.c b/diff-cache.c
index 47a4e09ec..400a4cb2a 100644
--- a/diff-cache.c
+++ b/diff-cache.c
@@ -168,10 +168,11 @@ static const char diff_cache_usage[] =
"[<common diff options>] <tree-ish> [<path>...]"
COMMON_DIFF_OPTIONS_HELP;
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
{
const char *tree_name = NULL;
unsigned char sha1[20];
+ const char *prefix = setup_git_directory();
const char **pathspec = NULL;
void *tree;
unsigned long size;
@@ -179,15 +180,12 @@ int main(int argc, const char **argv)
int allow_options = 1;
int i;
- read_cache();
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!allow_options || *arg != '-') {
- if (tree_name) {
- pathspec = argv + i;
+ if (tree_name)
break;
- }
tree_name = arg;
continue;
}
@@ -265,12 +263,16 @@ int main(int argc, const char **argv)
usage(diff_cache_usage);
}
+ pathspec = get_pathspec(prefix, argv + i);
+
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_cache_usage);
if (!tree_name || get_sha1(tree_name, sha1))
usage(diff_cache_usage);
+ read_cache();
+
/* The rest is for paths restriction. */
diff_setup(diff_setup_opt);
diff --git a/diff-files.c b/diff-files.c
index 2e6416e38..89eb29b3e 100644
--- a/diff-files.c
+++ b/diff-files.c
@@ -41,12 +41,12 @@ static void show_modified(int oldmode, int mode,
diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
}
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
{
static const unsigned char null_sha1[20] = { 0, };
const char **pathspec;
- int entries = read_cache();
- int i;
+ const char *prefix = setup_git_directory();
+ int entries, i;
while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "-p") || !strcmp(argv[1], "-u"))
@@ -95,8 +95,9 @@ int main(int argc, const char **argv)
argv++; argc--;
}
- /* Do we have a pathspec? */
- pathspec = (argc > 1) ? argv + 1 : NULL;
+ /* Find the directory, and set up the pathspec */
+ pathspec = get_pathspec(prefix, argv + 1);
+ entries = read_cache();
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_files_usage);
diff --git a/diff-tree.c b/diff-tree.c
index 0dd3cdacb..fc87902a3 100644
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -395,16 +395,25 @@ static int diff_tree_stdin(char *line)
return diff_tree_commit(commit, line);
}
+static int count_paths(const char **paths)
+{
+ int i = 0;
+ while (*paths++)
+ i++;
+ return i;
+}
+
static const char diff_tree_usage[] =
"git-diff-tree [--stdin] [-m] [-s] [-v] [--pretty] [-t] "
"[<common diff options>] <tree-ish> <tree-ish>"
COMMON_DIFF_OPTIONS_HELP;
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
{
int nr_sha1;
char line[1000];
unsigned char sha1[2][20];
+ const char *prefix = setup_git_directory();
nr_sha1 = 0;
for (;;) {
@@ -523,11 +532,11 @@ int main(int argc, const char **argv)
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
usage(diff_tree_usage);
- if (argc > 0) {
+ paths = get_pathspec(prefix, argv);
+ if (paths) {
int i;
- paths = argv;
- nr_paths = argc;
+ nr_paths = count_paths(paths);
pathlens = xmalloc(nr_paths * sizeof(int));
for (i=0; i<nr_paths; i++)
pathlens[i] = strlen(paths[i]);
diff --git a/diffcore-pathspec.c b/diffcore-pathspec.c
index a48acbc96..68fe00913 100644
--- a/diffcore-pathspec.c
+++ b/diffcore-pathspec.c
@@ -29,6 +29,8 @@ static int matches_pathspec(const char *name, struct path_spec *s, int cnt)
name[len] == 0 ||
name[len] == '/')
return 1;
+ if (!len)
+ return 1;
}
return 0;
}
diff --git a/git-diff-script b/git-diff-script
index 03ed555e7..926f594be 100755
--- a/git-diff-script
+++ b/git-diff-script
@@ -1,7 +1,5 @@
#!/bin/sh
-. git-sh-setup-script || die "Not a git archive"
-
-rev=($(git-rev-parse --revs-only "$@"))
+rev=($(git-rev-parse --revs-only "$@")) || exit
flags=($(git-rev-parse --no-revs --flags "$@"))
files=($(git-rev-parse --no-revs --no-flags "$@"))
case "${#rev[*]}" in
diff --git a/git-format-patch-script b/git-format-patch-script
index 78bb08954..3c3413b76 100755
--- a/git-format-patch-script
+++ b/git-format-patch-script
@@ -6,7 +6,7 @@
. git-sh-setup-script || die "Not a git archive."
usage () {
- echo >&2 "usage: $0"' [-n] [-o dir] [--mbox] [--check] [--signoff] [-<diff options>...] upstream [ our-head ]
+ echo >&2 "usage: $0"' [-n] [-o dir] [--keep-subject] [--mbox] [--check] [--signoff] [-<diff options>...] upstream [ our-head ]
Prepare each commit with its patch since our-head forked from upstream,
one file per patch, for e-mail submission. Each output file is
@@ -44,6 +44,9 @@ do
date=t ;;
-m|--m|--mb|--mbo|--mbox)
date=t author=t mbox=t ;;
+ -k|--k|--ke|--kee|--keep|--keep-|--keep-s|--keep-su|--keep-sub|\
+ --keep-subj|--keep-subje|--keep-subjec|--keep-subject)
+ keep_subject=t ;;
-n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered)
numbered=t ;;
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
@@ -64,6 +67,11 @@ do
shift
done
+case "$keep_subject$numbered" in
+tt)
+ die '--keep-subject and --numbered are incompatible.' ;;
+esac
+
revpair=
case "$#" in
2)
@@ -142,21 +150,22 @@ do
{
mailScript='
/./d
- /^$/n
- s|^\[PATCH[^]]*\] *||'
-
- case "$mbox" in
- t)
- echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
- mailScript="$mailScript"'
- s|^|Subject: [PATCH'"$num"'] |'
- ;;
+ /^$/n'
+ case "$keep_subject" in
+ t) ;;
*)
mailScript="$mailScript"'
+ s|^\[PATCH[^]]*\] *||
s|^|[PATCH'"$num"'] |'
;;
esac
-
+ mailScript="$mailScript"'
+ s|^|Subject: |'
+ case "$mbox" in
+ t)
+ echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
+ ;;
+ esac
eval "$(sed -ne "$whosepatchScript" $commsg)"
test "$author,$au" = ",$me" || {
mailScript="$mailScript"'
diff --git a/read-cache.c b/read-cache.c
index 5820f18d9..ced597318 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -191,6 +191,8 @@ int ce_path_match(const struct cache_entry *ce, const char **pathspec)
return 1;
if (name[matchlen] == '/' || !name[matchlen])
return 1;
+ if (!matchlen)
+ return 1;
}
return 0;
}
diff --git a/rev-parse.c b/rev-parse.c
index 1c6ae76f9..39cf63540 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -134,7 +134,8 @@ int main(int argc, char **argv)
{
int i, as_is = 0;
unsigned char sha1[20];
-
+ const char *prefix = setup_git_directory();
+
for (i = 1; i < argc; i++) {
char *arg = argv[i];
char *dotdot;
@@ -189,6 +190,10 @@ int main(int argc, char **argv)
for_each_ref(show_reference);
continue;
}
+ if (!strcmp(arg, "--show-prefix")) {
+ puts(prefix);
+ continue;
+ }
show_arg(arg);
continue;
}
diff --git a/setup.c b/setup.c
new file mode 100644
index 000000000..1710b1685
--- /dev/null
+++ b/setup.c
@@ -0,0 +1,118 @@
+#include "cache.h"
+
+static char *prefix_path(const char *prefix, int len, char *path)
+{
+ char *orig = path;
+ for (;;) {
+ char c;
+ if (*path != '.')
+ break;
+ c = path[1];
+ /* "." */
+ if (!c) {
+ path++;
+ break;
+ }
+ /* "./" */
+ if (c == '/') {
+ path += 2;
+ continue;
+ }
+ if (c != '.')
+ break;
+ c = path[2];
+ if (!c)
+ path += 2;
+ else if (c == '/')
+ path += 3;
+ else
+ break;
+ /* ".." and "../" */
+ /* Remove last component of the prefix */
+ do {
+ if (!len)
+ die("'%s' is outside repository", orig);
+ len--;
+ } while (len && prefix[len-1] != '/');
+ continue;
+ }
+ if (len) {
+ int speclen = strlen(path);
+ char *n = xmalloc(speclen + len + 1);
+
+ memcpy(n, prefix, len);
+ memcpy(n + len, path, speclen+1);
+ path = n;
+ }
+ return path;
+}
+
+const char **get_pathspec(const char *prefix, char **pathspec)
+{
+ char *entry = *pathspec;
+ char **p;
+ int prefixlen;
+
+ if (!prefix && !entry)
+ return NULL;
+
+ if (!entry) {
+ static const char *spec[2];
+ spec[0] = prefix;
+ spec[1] = NULL;
+ return spec;
+ }
+
+ /* Otherwise we have to re-write the entries.. */
+ p = pathspec;
+ prefixlen = prefix ? strlen(prefix) : 0;
+ do {
+ *p = prefix_path(prefix, prefixlen, entry);
+ } while ((entry = *++p) != NULL);
+ return (const char **) pathspec;
+}
+
+const char *setup_git_directory(void)
+{
+ static char cwd[PATH_MAX+1];
+ int len, offset;
+
+ /*
+ * If GIT_DIR is set explicitly, we're not going
+ * to do any discovery
+ */
+ if (gitenv(GIT_DIR_ENVIRONMENT))
+ return NULL;
+
+ if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
+ die("Unable to read current working directory");
+
+ offset = len = strlen(cwd);
+ for (;;) {
+ /*
+ * We always want to see a .git/refs/ subdirectory
+ */
+ if (!access(".git/refs/", X_OK)) {
+ /*
+ * Then we need either a GIT_OBJECT_DIRECTORY define
+ * or a .git/objects/ directory
+ */
+ if (gitenv(DB_ENVIRONMENT) || !access(".git/objects/", X_OK))
+ break;
+ }
+ chdir("..");
+ do {
+ if (!offset)
+ die("Not a git repository");
+ } while (cwd[--offset] != '/');
+ }
+
+ if (offset == len)
+ return NULL;
+
+ /* Make "offset" point to past the '/', and add a '/' at the end */
+ offset++;
+ cwd[len++] = '/';
+ cwd[len] = 0;
+ return cwd + offset;
+}
diff --git a/sha1_file.c b/sha1_file.c
index b6ebbc5c9..776697755 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -240,14 +240,21 @@ static struct alternate_object_database **alt_odb_tail;
* SHA1, an extra slash for the first level indirection, and the
* terminating NUL.
*/
-static void link_alt_odb_entries(const char *alt, const char *ep)
+static void link_alt_odb_entries(const char *alt, const char *ep, int sep)
{
const char *cp, *last;
struct alternate_object_database *ent;
last = alt;
- do {
- for (cp = last; cp < ep && *cp != ':'; cp++)
+ while (last < ep) {
+ cp = last;
+ if (cp < ep && *cp == '#') {
+ while (cp < ep && *cp != sep)
+ cp++;
+ last = cp + 1;
+ continue;
+ }
+ for ( ; cp < ep && *cp != sep; cp++)
;
if (last != cp) {
/* 43 = 40-byte + 2 '/' + terminating NUL */
@@ -264,16 +271,16 @@ static void link_alt_odb_entries(const char *alt, const char *ep)
ent->base[pfxlen] = ent->base[pfxlen + 3] = '/';
ent->base[entlen-1] = 0;
}
- while (cp < ep && *cp == ':')
+ while (cp < ep && *cp == sep)
cp++;
last = cp;
- } while (cp < ep);
+ }
}
void prepare_alt_odb(void)
{
char path[PATH_MAX];
- char *map, *ep;
+ char *map;
int fd;
struct stat st;
char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
@@ -282,7 +289,7 @@ void prepare_alt_odb(void)
if (alt_odb_tail)
return;
alt_odb_tail = &alt_odb_list;
- link_alt_odb_entries(alt, alt + strlen(alt));
+ link_alt_odb_entries(alt, alt + strlen(alt), ':');
fd = open(path, O_RDONLY);
if (fd < 0)
@@ -296,10 +303,7 @@ void prepare_alt_odb(void)
if (map == MAP_FAILED)
return;
- /* Remove the trailing newline */
- for (ep = map + st.st_size - 1; map < ep && ep[-1] == '\n'; ep--)
- ;
- link_alt_odb_entries(map, ep);
+ link_alt_odb_entries(map, map + st.st_size, '\n');
munmap(map, st.st_size);
}
diff --git a/tools/git-applymbox b/tools/git-applymbox
index e44f5d797..889d4c174 100755
--- a/tools/git-applymbox
+++ b/tools/git-applymbox
@@ -9,7 +9,7 @@
## You give it a mbox-format collection of emails, and it will try to
## apply them to the kernel using "applypatch"
##
-## applymbox [ -q ] (-c .dotest/msg-number | mail_archive) [Signoff_file]"
+## applymbox [ -k ] [ -q ] (-c .dotest/msg-number | mail_archive) [Signoff_file]"
##
## The patch application may fail in the middle. In which case:
## (1) look at .dotest/patch and fix it up to apply
@@ -18,10 +18,11 @@
## use a Signoff_file, because applypatch wants to append the sign-off
## message to msg-clean every time it is run.
-query_apply= continue= resume=t
+keep_subject= query_apply= continue= resume=t
while case "$#" in 0) break ;; esac
do
case "$1" in
+ -k) keep_subject=-k ;;
-q) query_apply=t ;;
-c) continue="$2"; resume=f; shift ;;
-*) usage ;;
@@ -41,6 +42,9 @@ esac
case "$query_apply" in
t) touch .dotest/.query_apply
esac
+case "$keep_subject" in
+-k) : >.dotest/.keep_subject
+esac
signoff="$1"
set x .dotest/0*
@@ -52,7 +56,8 @@ do
f,$i) resume=t;;
f,*) continue;;
*)
- git-mailinfo .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
+ git-mailinfo $keep_subject \
+ .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
git-stripspace < .dotest/msg > .dotest/msg-clean
;;
esac
diff --git a/tools/git-applypatch b/tools/git-applypatch
index 5a3a44b0e..406fef34f 100755
--- a/tools/git-applypatch
+++ b/tools/git-applypatch
@@ -16,6 +16,7 @@ final=.dotest/final-commit
## If this file exists, we ask before applying
##
query_apply=.dotest/.query_apply
+keep_subject=.dotest/.keep_subject
MSGFILE=$1
PATCHFILE=$2
INFO=$3
@@ -30,8 +31,10 @@ export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
if [ -n "$signoff" -a -f "$signoff" ]; then
cat $signoff >> $MSGFILE
fi
+patch_header=
+test -f "$keep_subject" || patch_header='[PATCH] '
-(echo "[PATCH] $SUBJECT" ; if [ -s $MSGFILE ]; then echo ; cat $MSGFILE; fi ) > $final
+(echo "$patch_header$SUBJECT" ; if [ -s $MSGFILE ]; then echo ; cat $MSGFILE; fi ) > $final
f=0
[ -f $query_apply ] || f=1
diff --git a/tools/mailinfo.c b/tools/mailinfo.c
index fb2ea2b70..a36123a1f 100644
--- a/tools/mailinfo.c
+++ b/tools/mailinfo.c
@@ -9,6 +9,7 @@
static FILE *cmitmsg, *patchfile;
+static int keep_subject = 0;
static char line[1000];
static char date[1000];
static char name[1000];
@@ -101,6 +102,8 @@ static void check_line(char *line, int len)
static char * cleanup_subject(char *subject)
{
+ if (keep_subject)
+ return subject;
for (;;) {
char *p;
int len, remove;
@@ -242,8 +245,20 @@ static void usage(void)
exit(1);
}
+static const char mailinfo_usage[] =
+"git-mailinfo [-k] msg patch <mail >info";
int main(int argc, char ** argv)
{
+ while (1 < argc && argv[1][0] == '-') {
+ if (!strcmp(argv[1], "-k"))
+ keep_subject = 1;
+ else {
+ fprintf(stderr, "usage: %s\n", mailinfo_usage);
+ exit(1);
+ }
+ argc--; argv++;
+ }
+
if (argc != 3)
usage();
cmitmsg = fopen(argv[1], "w");