summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-ls-files.txt9
-rw-r--r--Documentation/git-ls-tree.txt9
-rw-r--r--Makefile4
-rw-r--r--blame.c1
-rw-r--r--cache.h1
-rw-r--r--cat-file.c1
-rw-r--r--config.c5
-rw-r--r--count-delta.c72
-rw-r--r--count-delta.h10
-rw-r--r--diff.c2
-rw-r--r--diffcore-break.c46
-rw-r--r--diffcore-delta.c228
-rw-r--r--diffcore-rename.c27
-rw-r--r--diffcore.h7
-rw-r--r--environment.c1
-rw-r--r--fetch-pack.c18
-rwxr-xr-xgit-clone.sh212
-rwxr-xr-xgit-fetch.sh10
-rwxr-xr-xgit-fmt-merge-msg.perl8
-rwxr-xr-xgit-merge.sh67
-rwxr-xr-xgit-parse-remote.sh8
-rw-r--r--ls-files.c19
-rw-r--r--ls-tree.c20
-rw-r--r--merge-base.c1
-rw-r--r--name-rev.c1
-rw-r--r--read-tree.c1
-rw-r--r--rev-list.c11
-rw-r--r--rev-parse.c2
-rw-r--r--send-pack.c2
-rw-r--r--sha1_name.c35
-rwxr-xr-xt/t5000-tar-tree.sh3
-rw-r--r--tar-tree.c386
-rw-r--r--tar.h25
-rw-r--r--unpack-file.c1
-rw-r--r--update-ref.c1
35 files changed, 790 insertions, 464 deletions
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index e813f84..59f6adc 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -14,9 +14,9 @@ SYNOPSIS
(-[c|d|o|i|s|u|k|m])\*
[-x <pattern>|--exclude=<pattern>]
[-X <file>|--exclude-from=<file>]
- [--exclude-per-directory=<file>]
+ [--exclude-per-directory=<file>]
[--error-unmatch]
- [--full-name] [--] [<file>]\*
+ [--full-name] [--abbrev] [--] [<file>]\*
DESCRIPTION
-----------
@@ -98,6 +98,11 @@ OPTIONS
option forces paths to be output relative to the project
top directory.
+--abbrev[=<n>]::
+ Instead of showing the full 40-byte hexadecimal object
+ lines, show only handful hexdigits prefix.
+ Non default number of digits can be specified with --abbrev=<n>.
+
--::
Do not interpret any more arguments as options.
diff --git a/Documentation/git-ls-tree.txt b/Documentation/git-ls-tree.txt
index 5bf6d8b..018c401 100644
--- a/Documentation/git-ls-tree.txt
+++ b/Documentation/git-ls-tree.txt
@@ -8,7 +8,9 @@ git-ls-tree - Lists the contents of a tree object
SYNOPSIS
--------
-'git-ls-tree' [-d] [-r] [-t] [-z] [--name-only] [--name-status] <tree-ish> [paths...]
+'git-ls-tree' [-d] [-r] [-t] [-z]
+ [--name-only] [--name-status] [--full-name] [--abbrev=[<n>]]
+ <tree-ish> [paths...]
DESCRIPTION
-----------
@@ -40,6 +42,11 @@ OPTIONS
--name-status::
List only filenames (instead of the "long" output), one per line.
+--abbrev[=<n>]::
+ Instead of showing the full 40-byte hexadecimal object
+ lines, show only handful hexdigits prefix.
+ Non default number of digits can be specified with --abbrev=<n>.
+
paths::
When paths are given, show them (note that this isn't really raw
pathnames, but rather a list of patterns to match). Otherwise
diff --git a/Makefile b/Makefile
index 0f565eb..663a803 100644
--- a/Makefile
+++ b/Makefile
@@ -191,7 +191,7 @@ LIB_FILE=libgit.a
XDIFF_LIB=xdiff/lib.a
LIB_H = \
- blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
+ blob.h cache.h commit.h csum-file.h delta.h \
diff.h object.h pack.h pkt-line.h quote.h refs.h \
run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h
@@ -201,7 +201,7 @@ DIFF_OBJS = \
diffcore-delta.o
LIB_OBJS = \
- blob.o commit.o connect.o count-delta.o csum-file.o \
+ blob.o commit.o connect.o csum-file.o \
date.o diff-delta.o entry.o exec_cmd.o ident.o index.o \
object.o pack-check.o patch-delta.o path.o pkt-line.o \
quote.o read-cache.o refs.o run-command.o \
diff --git a/blame.c b/blame.c
index 7e88833..396defc 100644
--- a/blame.c
+++ b/blame.c
@@ -752,6 +752,7 @@ int main(int argc, const char **argv)
int found_rename;
const char* prefix = setup_git_directory();
+ git_config(git_default_config);
for(i = 1; i < argc; i++) {
if(options) {
diff --git a/cache.h b/cache.h
index 1f96280..255e6b5 100644
--- a/cache.h
+++ b/cache.h
@@ -165,6 +165,7 @@ extern void rollback_index_file(struct cache_file *);
extern int trust_executable_bit;
extern int assume_unchanged;
extern int only_use_symrefs;
+extern int warn_ambiguous_refs;
extern int diff_rename_limit_default;
extern int shared_repository;
extern const char *apply_default_whitespace;
diff --git a/cat-file.c b/cat-file.c
index 1a613f3..761111e 100644
--- a/cat-file.c
+++ b/cat-file.c
@@ -100,6 +100,7 @@ int main(int argc, char **argv)
int opt;
setup_git_directory();
+ git_config(git_default_config);
if (argc != 3 || get_sha1(argv[2], sha1))
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
diff --git a/config.c b/config.c
index 7dbdce1..95ec349 100644
--- a/config.c
+++ b/config.c
@@ -232,6 +232,11 @@ int git_default_config(const char *var, const char *value)
return 0;
}
+ if (!strcmp(var, "core.warnambiguousrefs")) {
+ warn_ambiguous_refs = git_config_bool(var, value);
+ return 0;
+ }
+
if (!strcmp(var, "user.name")) {
strncpy(git_default_name, value, sizeof(git_default_name));
return 0;
diff --git a/count-delta.c b/count-delta.c
deleted file mode 100644
index 058a2aa..0000000
--- a/count-delta.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2005 Junio C Hamano
- * The delta-parsing part is almost straight copy of patch-delta.c
- * which is (C) 2005 Nicolas Pitre <nico@cam.org>.
- */
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include "delta.h"
-#include "count-delta.h"
-
-/*
- * NOTE. We do not _interpret_ delta fully. As an approximation, we
- * just count the number of bytes that are copied from the source, and
- * the number of literal data bytes that are inserted.
- *
- * Number of bytes that are _not_ copied from the source is deletion,
- * and number of inserted literal bytes are addition, so sum of them
- * is the extent of damage.
- */
-int count_delta(void *delta_buf, unsigned long delta_size,
- unsigned long *src_copied, unsigned long *literal_added)
-{
- unsigned long copied_from_source, added_literal;
- const unsigned char *data, *top;
- unsigned char cmd;
- unsigned long src_size, dst_size, out;
-
- if (delta_size < DELTA_SIZE_MIN)
- return -1;
-
- data = delta_buf;
- top = delta_buf + delta_size;
-
- src_size = get_delta_hdr_size(&data);
- dst_size = get_delta_hdr_size(&data);
-
- added_literal = copied_from_source = out = 0;
- while (data < top) {
- cmd = *data++;
- if (cmd & 0x80) {
- unsigned long cp_off = 0, cp_size = 0;
- if (cmd & 0x01) cp_off = *data++;
- if (cmd & 0x02) cp_off |= (*data++ << 8);
- if (cmd & 0x04) cp_off |= (*data++ << 16);
- if (cmd & 0x08) cp_off |= (*data++ << 24);
- if (cmd & 0x10) cp_size = *data++;
- if (cmd & 0x20) cp_size |= (*data++ << 8);
- if (cmd & 0x40) cp_size |= (*data++ << 16);
- if (cp_size == 0) cp_size = 0x10000;
-
- copied_from_source += cp_size;
- out += cp_size;
- } else {
- /* write literal into dst */
- added_literal += cmd;
- out += cmd;
- data += cmd;
- }
- }
-
- /* sanity check */
- if (data != top || out != dst_size)
- return -1;
-
- /* delete size is what was _not_ copied from source.
- * edit size is that and literal additions.
- */
- *src_copied = copied_from_source;
- *literal_added = added_literal;
- return 0;
-}
diff --git a/count-delta.h b/count-delta.h
deleted file mode 100644
index 7359629..0000000
--- a/count-delta.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright (C) 2005 Junio C Hamano
- */
-#ifndef COUNT_DELTA_H
-#define COUNT_DELTA_H
-
-int count_delta(void *, unsigned long,
- unsigned long *src_copied, unsigned long *literal_added);
-
-#endif
diff --git a/diff.c b/diff.c
index cd2ce0f..4440465 100644
--- a/diff.c
+++ b/diff.c
@@ -561,6 +561,8 @@ void diff_free_filespec_data(struct diff_filespec *s)
munmap(s->data, s->size);
s->should_free = s->should_munmap = 0;
s->data = NULL;
+ free(s->cnt_data);
+ s->cnt_data = NULL;
}
static void prep_temp_blob(struct diff_tempfile *temp,
diff --git a/diffcore-break.c b/diffcore-break.c
index 0fc2b86..ed0e14c 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -45,8 +45,8 @@ static int should_break(struct diff_filespec *src,
* The value we return is 1 if we want the pair to be broken,
* or 0 if we do not.
*/
- unsigned long delta_size, base_size, src_copied, literal_added;
- int to_break = 0;
+ unsigned long delta_size, base_size, src_copied, literal_added,
+ src_removed;
*merge_score_p = 0; /* assume no deletion --- "do not break"
* is the default.
@@ -68,37 +68,45 @@ static int should_break(struct diff_filespec *src,
if (diffcore_count_changes(src->data, src->size,
dst->data, dst->size,
+ NULL, NULL,
0,
&src_copied, &literal_added))
return 0;
+ /* sanity */
+ if (src->size < src_copied)
+ src_copied = src->size;
+ if (dst->size < literal_added + src_copied) {
+ if (src_copied < dst->size)
+ literal_added = dst->size - src_copied;
+ else
+ literal_added = 0;
+ }
+ src_removed = src->size - src_copied;
+
/* Compute merge-score, which is "how much is removed
* from the source material". The clean-up stage will
* merge the surviving pair together if the score is
* less than the minimum, after rename/copy runs.
*/
- if (src->size <= src_copied)
- ; /* all copied, nothing removed */
- else {
- delta_size = src->size - src_copied;
- *merge_score_p = delta_size * MAX_SCORE / src->size;
- }
-
+ *merge_score_p = src_removed * MAX_SCORE / src->size;
+
/* Extent of damage, which counts both inserts and
* deletes.
*/
- if (src->size + literal_added <= src_copied)
- delta_size = 0; /* avoid wrapping around */
- else
- delta_size = (src->size - src_copied) + literal_added;
-
- /* We break if the edit exceeds the minimum.
- * i.e. (break_score / MAX_SCORE < delta_size / base_size)
+ delta_size = src_removed + literal_added;
+ if (delta_size * MAX_SCORE / base_size < break_score)
+ return 0;
+
+ /* If you removed a lot without adding new material, that is
+ * not really a rewrite.
*/
- if (break_score * base_size < delta_size * MAX_SCORE)
- to_break = 1;
+ if ((src->size * break_score < src_removed * MAX_SCORE) &&
+ (literal_added * 20 < src_removed) &&
+ (literal_added * 20 < src_copied))
+ return 0;
- return to_break;
+ return 1;
}
void diffcore_break(int break_score)
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 1e6a691..7338a40 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -1,43 +1,213 @@
#include "cache.h"
#include "diff.h"
#include "diffcore.h"
-#include "delta.h"
-#include "count-delta.h"
-
-static int diffcore_count_changes_1(void *src, unsigned long src_size,
- void *dst, unsigned long dst_size,
- unsigned long delta_limit,
- unsigned long *src_copied,
- unsigned long *literal_added)
+
+/*
+ * Idea here is very simple.
+ *
+ * We have total of (sz-N+1) N-byte overlapping sequences in buf whose
+ * size is sz. If the same N-byte sequence appears in both source and
+ * destination, we say the byte that starts that sequence is shared
+ * between them (i.e. copied from source to destination).
+ *
+ * For each possible N-byte sequence, if the source buffer has more
+ * instances of it than the destination buffer, that means the
+ * difference are the number of bytes not copied from source to
+ * destination. If the counts are the same, everything was copied
+ * from source to destination. If the destination has more,
+ * everything was copied, and destination added more.
+ *
+ * We are doing an approximation so we do not really have to waste
+ * memory by actually storing the sequence. We just hash them into
+ * somewhere around 2^16 hashbuckets and count the occurrences.
+ *
+ * The length of the sequence is arbitrarily set to 8 for now.
+ */
+
+/* Wild guess at the initial hash size */
+#define INITIAL_HASH_SIZE 9
+
+/* We leave more room in smaller hash but do not let it
+ * grow to have unused hole too much.
+ */
+#define INITIAL_FREE(sz_log2) ((1<<(sz_log2))*(sz_log2-3)/(sz_log2))
+
+/* A prime rather carefully chosen between 2^16..2^17, so that
+ * HASHBASE < INITIAL_FREE(17). We want to keep the maximum hashtable
+ * size under the current 2<<17 maximum, which can hold this many
+ * different values before overflowing to hashtable of size 2<<18.
+ */
+#define HASHBASE 107927
+
+struct spanhash {
+ unsigned int hashval;
+ unsigned int cnt;
+};
+struct spanhash_top {
+ int alloc_log2;
+ int free;
+ struct spanhash data[FLEX_ARRAY];
+};
+
+static struct spanhash *spanhash_find(struct spanhash_top *top,
+ unsigned int hashval)
{
- void *delta;
- unsigned long delta_size;
-
- delta = diff_delta(src, src_size,
- dst, dst_size,
- &delta_size, delta_limit);
- if (!delta)
- /* If delta_limit is exceeded, we have too much differences */
- return -1;
-
- /* Estimate the edit size by interpreting delta. */
- if (count_delta(delta, delta_size, src_copied, literal_added)) {
- free(delta);
- return -1;
+ int sz = 1 << top->alloc_log2;
+ int bucket = hashval & (sz - 1);
+ while (1) {
+ struct spanhash *h = &(top->data[bucket++]);
+ if (!h->cnt)
+ return NULL;
+ if (h->hashval == hashval)
+ return h;
+ if (sz <= bucket)
+ bucket = 0;
}
- free(delta);
- return 0;
+}
+
+static struct spanhash_top *spanhash_rehash(struct spanhash_top *orig)
+{
+ struct spanhash_top *new;
+ int i;
+ int osz = 1 << orig->alloc_log2;
+ int sz = osz << 1;
+
+ new = xmalloc(sizeof(*orig) + sizeof(struct spanhash) * sz);
+ new->alloc_log2 = orig->alloc_log2 + 1;
+ new->free = INITIAL_FREE(new->alloc_log2);
+ memset(new->data, 0, sizeof(struct spanhash) * sz);
+ for (i = 0; i < osz; i++) {
+ struct spanhash *o = &(orig->data[i]);
+ int bucket;
+ if (!o->cnt)
+ continue;
+ bucket = o->hashval & (sz - 1);
+ while (1) {
+ struct spanhash *h = &(new->data[bucket++]);
+ if (!h->cnt) {
+ h->hashval = o->hashval;
+ h->cnt = o->cnt;
+ new->free--;
+ break;
+ }
+ if (sz <= bucket)
+ bucket = 0;
+ }
+ }
+ free(orig);
+ return new;
+}
+
+static struct spanhash_top *add_spanhash(struct spanhash_top *top,
+ unsigned int hashval, int cnt)
+{
+ int bucket, lim;
+ struct spanhash *h;
+
+ lim = (1 << top->alloc_log2);
+ bucket = hashval & (lim - 1);
+ while (1) {
+ h = &(top->data[bucket++]);
+ if (!h->cnt) {
+ h->hashval = hashval;
+ h->cnt = cnt;
+ top->free--;
+ if (top->free < 0)
+ return spanhash_rehash(top);
+ return top;
+ }
+ if (h->hashval == hashval) {
+ h->cnt += cnt;
+ return top;
+ }
+ if (lim <= bucket)
+ bucket = 0;
+ }
+}
+
+static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz)
+{
+ int i, n;
+ unsigned int accum1, accum2, hashval;
+ struct spanhash_top *hash;
+
+ i = INITIAL_HASH_SIZE;
+ hash = xmalloc(sizeof(*hash) + sizeof(struct spanhash) * (1<<i));
+ hash->alloc_log2 = i;
+ hash->free = INITIAL_FREE(i);
+ memset(hash->data, 0, sizeof(struct spanhash) * (1<<i));
+
+ n = 0;
+ accum1 = accum2 = 0;
+ while (sz) {
+ unsigned int c = *buf++;
+ unsigned int old_1 = accum1;
+ sz--;
+ accum1 = (accum1 << 7) ^ (accum2 >> 25);
+ accum2 = (accum2 << 7) ^ (old_1 >> 25);
+ accum1 += c;
+ if (++n < 64 && c != '\n')
+ continue;
+ hashval = (accum1 + accum2 * 0x61) % HASHBASE;
+ hash = add_spanhash(hash, hashval, n);
+ n = 0;
+ accum1 = accum2 = 0;
+ }
+ return hash;
}
int diffcore_count_changes(void *src, unsigned long src_size,
void *dst, unsigned long dst_size,
+ void **src_count_p,
+ void **dst_count_p,
unsigned long delta_limit,
unsigned long *src_copied,
unsigned long *literal_added)
{
- return diffcore_count_changes_1(src, src_size,
- dst, dst_size,
- delta_limit,
- src_copied,
- literal_added);
+ int i, ssz;
+ struct spanhash_top *src_count, *dst_count;
+ unsigned long sc, la;
+
+ src_count = dst_count = NULL;
+ if (src_count_p)
+ src_count = *src_count_p;
+ if (!src_count) {
+ src_count = hash_chars(src, src_size);
+ if (src_count_p)
+ *src_count_p = src_count;
+ }
+ if (dst_count_p)
+ dst_count = *dst_count_p;
+ if (!dst_count) {
+ dst_count = hash_chars(dst, dst_size);
+ if (dst_count_p)
+ *dst_count_p = dst_count;
+ }
+ sc = la = 0;
+
+ ssz = 1 << src_count->alloc_log2;
+ for (i = 0; i < ssz; i++) {
+ struct spanhash *s = &(src_count->data[i]);
+ struct spanhash *d;
+ unsigned dst_cnt, src_cnt;
+ if (!s->cnt)
+ continue;
+ src_cnt = s->cnt;
+ d = spanhash_find(dst_count, s->hashval);
+ dst_cnt = d ? d->cnt : 0;
+ if (src_cnt < dst_cnt) {
+ la += dst_cnt - src_cnt;
+ sc += src_cnt;
+ }
+ else
+ sc += dst_cnt;
+ }
+
+ if (!src_count_p)
+ free(src_count);
+ if (!dst_count_p)
+ free(dst_count);
+ *src_copied = sc;
+ *literal_added = la;
+ return 0;
}
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 55cf1c3..e992698 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -133,7 +133,7 @@ static int estimate_similarity(struct diff_filespec *src,
* match than anything else; the destination does not even
* call into this function in that case.
*/
- unsigned long delta_size, base_size, src_copied, literal_added;
+ unsigned long max_size, delta_size, base_size, src_copied, literal_added;
unsigned long delta_limit;
int score;
@@ -144,9 +144,9 @@ static int estimate_similarity(struct diff_filespec *src,
if (!S_ISREG(src->mode) || !S_ISREG(dst->mode))
return 0;
- delta_size = ((src->size < dst->size) ?
- (dst->size - src->size) : (src->size - dst->size));
+ max_size = ((src->size > dst->size) ? src->size : dst->size);
base_size = ((src->size < dst->size) ? src->size : dst->size);
+ delta_size = max_size - base_size;
/* We would not consider edits that change the file size so
* drastically. delta_size must be smaller than
@@ -166,23 +166,18 @@ static int estimate_similarity(struct diff_filespec *src,
delta_limit = base_size * (MAX_SCORE-minimum_score) / MAX_SCORE;
if (diffcore_count_changes(src->data, src->size,
dst->data, dst->size,
+ &src->cnt_data, &dst->cnt_data,
delta_limit,
&src_copied, &literal_added))
return 0;
- /* Extent of damage */
- if (src->size + literal_added < src_copied)
- delta_size = 0;
- else
- delta_size = (src->size - src_copied) + literal_added;
-
- /*
- * Now we will give some score to it. 100% edit gets 0 points
- * and 0% edit gets MAX_SCORE points.
+ /* How similar are they?
+ * what percentage of material in dst are from source?
*/
- score = MAX_SCORE - (MAX_SCORE * delta_size / base_size);
- if (score < 0) return 0;
- if (MAX_SCORE < score) return MAX_SCORE;
+ if (!dst->size)
+ score = 0; /* should not happen */
+ else
+ score = src_copied * MAX_SCORE / max_size;
return score;
}
@@ -310,6 +305,8 @@ void diffcore_rename(struct diff_options *options)
m->score = estimate_similarity(one, two,
minimum_score);
}
+ /* We do not need the text anymore */
+ diff_free_filespec_data(two);
dst_cnt++;
}
/* cost matrix sorted by most to least similar pair */
diff --git a/diffcore.h b/diffcore.h
index dba4f17..73c7842 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -17,8 +17,8 @@
*/
#define MAX_SCORE 60000.0
#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
-#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%)*/
-#define DEFAULT_MERGE_SCORE 48000 /* maximum for break-merge to happen (80%)*/
+#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
+#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen 60%) */
#define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
@@ -26,6 +26,7 @@ struct diff_filespec {
unsigned char sha1[20];
char *path;
void *data;
+ void *cnt_data;
unsigned long size;
int xfrm_flags; /* for use by the xfrm */
unsigned short mode; /* file mode */
@@ -103,6 +104,8 @@ void diff_debug_queue(const char *, struct diff_queue_struct *);
extern int diffcore_count_changes(void *src, unsigned long src_size,
void *dst, unsigned long dst_size,
+ void **src_count_p,
+ void **dst_count_p,
unsigned long delta_limit,
unsigned long *src_copied,
unsigned long *literal_added);
diff --git a/environment.c b/environment.c
index 16c08f0..6df6478 100644
--- a/environment.c
+++ b/environment.c
@@ -14,6 +14,7 @@ char git_default_name[MAX_GITNAME];
int trust_executable_bit = 1;
int assume_unchanged = 0;
int only_use_symrefs = 0;
+int warn_ambiguous_refs = 1;
int repository_format_version = 0;
char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
int shared_repository = 0;
diff --git a/fetch-pack.c b/fetch-pack.c
index 535de10..a3bcad0 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -7,8 +7,9 @@
static int keep_pack;
static int quiet;
static int verbose;
+static int fetch_all;
static const char fetch_pack_usage[] =
-"git-fetch-pack [-q] [-v] [-k] [--thin] [--exec=upload-pack] [host:]directory <refs>...";
+"git-fetch-pack [--all] [-q] [-v] [-k] [--thin] [--exec=upload-pack] [host:]directory <refs>...";
static const char *exec = "git-upload-pack";
#define COMPLETE (1U << 0)
@@ -266,8 +267,9 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
for (prev = NULL, current = *refs; current; current = next) {
next = current->next;
if ((!memcmp(current->name, "refs/", 5) &&
- check_ref_format(current->name + 5)) ||
- !path_match(current->name, nr_match, match)) {
+ check_ref_format(current->name + 5)) ||
+ (!fetch_all &&
+ !path_match(current->name, nr_match, match))) {
if (prev == NULL)
*refs = next;
else
@@ -376,7 +378,11 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
goto all_done;
}
if (find_common(fd, sha1, ref) < 0)
- fprintf(stderr, "warning: no common commits\n");
+ if (!keep_pack)
+ /* When cloning, it is not unusual to have
+ * no common commit.
+ */
+ fprintf(stderr, "warning: no common commits\n");
if (keep_pack)
status = receive_keep_pack(fd, "git-fetch-pack", quiet);
@@ -426,6 +432,10 @@ int main(int argc, char **argv)
use_thin_pack = 1;
continue;
}
+ if (!strcmp("--all", arg)) {
+ fetch_all = 1;
+ continue;
+ }
if (!strcmp("-v", arg)) {
verbose = 1;
continue;
diff --git a/git-clone.sh b/git-clone.sh
index 4ed861d..6887321 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -9,7 +9,7 @@
unset CDPATH
usage() {
- echo >&2 "Usage: $0 [--bare] [-l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
+ echo >&2 "Usage: $0 [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
exit 1
}
@@ -40,13 +40,62 @@ Perhaps git-update-server-info needs to be run there?"
do
name=`expr "$refname" : 'refs/\(.*\)'` &&
case "$name" in
- *^*) ;;
- *)
- git-http-fetch -v -a -w "$name" "$name" "$1/" || exit 1
+ *^*) continue;;
esac
+ if test -n "$use_separate_remote" &&
+ branch_name=`expr "$name" : 'heads/\(.*\)'`
+ then
+ tname="remotes/$origin/$branch_name"
+ else
+ tname=$name
+ fi
+ git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
done <"$clone_tmp/refs"
rm -fr "$clone_tmp"
+ http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD"
+}
+
+# Read git-fetch-pack -k output and store the remote branches.
+copy_refs='
+use File::Path qw(mkpath);
+use File::Basename qw(dirname);
+my $git_dir = $ARGV[0];
+my $use_separate_remote = $ARGV[1];
+my $origin = $ARGV[2];
+
+my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
+my $tag_top = "tags";
+
+sub store {
+ my ($sha1, $name, $top) = @_;
+ $name = "$git_dir/refs/$top/$name";
+ mkpath(dirname($name));
+ open O, ">", "$name";
+ print O "$sha1\n";
+ close O;
+}
+
+open FH, "<", "$git_dir/CLONE_HEAD";
+while (<FH>) {
+ my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
+ next if ($name =~ /\^\173/);
+ if ($name eq "HEAD") {
+ open O, ">", "$git_dir/REMOTE_HEAD";
+ print O "$sha1\n";
+ close O;
+ next;
+ }
+ if ($name =~ s/^refs\/heads\///) {
+ store($sha1, $name, $branch_top);
+ next;
+ }
+ if ($name =~ s/^refs\/tags\///) {
+ store($sha1, $name, $tag_top);
+ next;
+ }
}
+close FH;
+'
quiet=
use_local=no
@@ -54,8 +103,10 @@ local_shared=no
no_checkout=
upload_pack=
bare=
-origin=origin
+reference=
+origin=
origin_override=
+use_separate_remote=
while
case "$#,$1" in
0,*) break ;;
@@ -68,9 +119,21 @@ while
*,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
local_shared=yes; use_local=yes ;;
*,-q|*,--quiet) quiet=-q ;;
+ *,--use-separate-remote)
+ use_separate_remote=t ;;
1,-o) usage;;
+ 1,--reference) usage ;;
+ *,--reference)
+ shift; reference="$1" ;;
+ *,--reference=*)
+ reference=`expr "$1" : '--reference=\(.*\)'` ;;
*,-o)
- git-check-ref-format "$2" || {
+ case "$2" in
+ */*)
+ echo >&2 "'$2' is not suitable for an origin name"
+ exit 1
+ esac
+ git-check-ref-format "heads/$2" || {
echo >&2 "'$2' is not suitable for a branch name"
exit 1
}
@@ -100,9 +163,19 @@ then
echo >&2 '--bare and -o $origin options are incompatible.'
exit 1
fi
+ if test t = "$use_separate_remote"
+ then
+ echo >&2 '--bare and --use-separate-remote options are incompatible.'
+ exit 1
+ fi
no_checkout=yes
fi
+if test -z "$origin"
+then
+ origin=origin
+fi
+
# Turn the source into an absolute path if
# it is local
repo="$1"
@@ -130,6 +203,28 @@ yes)
GIT_DIR="$D/.git" ;;
esac
+if test -n "$reference"
+then
+ if test -d "$reference"
+ then
+ if test -d "$reference/.git/objects"
+ then
+ reference="$reference/.git"
+ fi
+ reference=$(cd "$reference" && pwd)
+ echo "$reference/objects" >"$GIT_DIR/objects/info/alternates"
+ (cd "$reference" && tar cf - refs) |
+ (cd "$GIT_DIR/refs" &&
+ mkdir reference-tmp &&
+ cd reference-tmp &&
+ tar xf -)
+ else
+ echo >&2 "$reference: not a local directory." && usage
+ fi
+fi
+
+rm -f "$GIT_DIR/CLONE_HEAD"
+
# We do local magic only when the user tells us to.
case "$local,$use_local" in
yes,yes)
@@ -165,24 +260,14 @@ yes,yes)
} >"$GIT_DIR/objects/info/alternates"
;;
esac
-
- # Make a duplicate of refs and HEAD pointer
- HEAD=
- if test -f "$repo/HEAD"
- then
- HEAD=HEAD
- fi
- (cd "$repo" && tar cf - refs $HEAD) |
- (cd "$GIT_DIR" && tar xf -) || exit 1
+ git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD"
;;
*)
case "$repo" in
rsync://*)
rsync $quiet -av --ignore-existing \
- --exclude info "$repo/objects/" "$GIT_DIR/objects/" &&
- rsync $quiet -av --ignore-existing \
- --exclude info "$repo/refs/" "$GIT_DIR/refs/" || exit
-
+ --exclude info "$repo/objects/" "$GIT_DIR/objects/" ||
+ exit
# Look at objects/info/alternates for rsync -- http will
# support it natively and git native ones will do it on the
# remote end. Not having that file is not a crime.
@@ -205,6 +290,7 @@ yes,yes)
done
rm -f "$GIT_DIR/TMP_ALT"
fi
+ git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD"
;;
http://*)
if test -z "@@NO_CURL@@"
@@ -217,38 +303,89 @@ yes,yes)
;;
*)
cd "$D" && case "$upload_pack" in
- '') git-clone-pack $quiet "$repo" ;;
- *) git-clone-pack $quiet "$upload_pack" "$repo" ;;
- esac || {
- echo >&2 "clone-pack from '$repo' failed."
+ '') git-fetch-pack --all -k $quiet "$repo" ;;
+ *) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
+ esac >"$GIT_DIR/CLONE_HEAD" || {
+ echo >&2 "fetch-pack from '$repo' failed."
exit 1
}
;;
esac
;;
esac
+test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
+
+if test -f "$GIT_DIR/CLONE_HEAD"
+then
+ # Figure out where the remote HEAD points at.
+ perl -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin"
+fi
cd "$D" || exit
-if test -f "$GIT_DIR/HEAD" && test -z "$bare"
+if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
then
- head_points_at=`git-symbolic-ref HEAD`
+ head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+ # Figure out which remote branch HEAD points at.
+ case "$use_separate_remote" in
+ '') remote_top=refs/heads ;;
+ *) remote_top="refs/remotes/$origin" ;;
+ esac
+
+ # What to use to track the remote primary branch
+ if test -n "$use_separate_remote"
+ then
+ origin_tracking="remotes/$origin/master"
+ else
+ origin_tracking="heads/$origin"
+ fi
+
+ # The name under $remote_top the remote HEAD seems to point at
+ head_points_at=$(
+ (
+ echo "master"
+ cd "$GIT_DIR/$remote_top" &&
+ find . -type f -print | sed -e 's/^\.\///'
+ ) | (
+ done=f
+ while read name
+ do
+ test t = $done && continue
+ branch_tip=`cat "$GIT_DIR/$remote_top/$name"`
+ if test "$head_sha1" = "$branch_tip"
+ then
+ echo "$name"
+ done=t
+ fi
+ done
+ )
+ )
+
+ # Write out remotes/$origin file.
case "$head_points_at" in
- refs/heads/*)
- head_points_at=`expr "$head_points_at" : 'refs/heads/\(.*\)'`
+ ?*)
mkdir -p "$GIT_DIR/remotes" &&
- echo >"$GIT_DIR/remotes/origin" \
+ echo >"$GIT_DIR/remotes/$origin" \
"URL: $repo
-Pull: $head_points_at:$origin" &&
- git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) &&
- (cd "$GIT_DIR" && find "refs/heads" -type f -print) |
- while read ref
+Pull: refs/heads/$head_points_at:refs/$origin_tracking" &&
+ case "$use_separate_remote" in
+ t) git-update-ref HEAD "$head_sha1" ;;
+ *) git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) ;;
+ esac &&
+ (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
+ while read dotslref
do
- head=`expr "$ref" : 'refs/heads/\(.*\)'` &&
- test "$head_points_at" = "$head" ||
- test "$origin" = "$head" ||
- echo "Pull: ${head}:${head}"
- done >>"$GIT_DIR/remotes/origin"
+ name=`expr "$dotslref" : './\(.*\)'` &&
+ test "$head_points_at" = "$name" ||
+ test "$origin" = "$name" ||
+ echo "Pull: refs/heads/${name}:$remote_top/${name}"
+ done >>"$GIT_DIR/remotes/$origin" &&
+ case "$use_separate_remote" in
+ t)
+ rm -f "refs/remotes/$origin/HEAD"
+ git-symbolic-ref "refs/remotes/$origin/HEAD" \
+ "refs/remotes/$origin/$head_points_at"
+ esac
esac
case "$no_checkout" in
@@ -256,6 +393,7 @@ Pull: $head_points_at:$origin" &&
git-read-tree -m -u -v HEAD HEAD
esac
fi
+rm -f "$GIT_DIR/CLONE_HEAD" "$GIT_DIR/REMOTE_HEAD"
trap - exit
diff --git a/git-fetch.sh b/git-fetch.sh
index 6835634..954901d 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -94,6 +94,9 @@ append_fetch_head () {
# remote-nick is the URL given on the command line (or a shorthand)
# remote-name is the $GIT_DIR relative refs/ path we computed
# for this refspec.
+
+ # the $note_ variable will be fed to git-fmt-merge-msg for further
+ # processing.
case "$remote_name_" in
HEAD)
note_= ;;
@@ -103,6 +106,9 @@ append_fetch_head () {
refs/tags/*)
note_="$(expr "$remote_name_" : 'refs/tags/\(.*\)')"
note_="tag '$note_' of " ;;
+ refs/remotes/*)
+ note_="$(expr "$remote_name_" : 'refs/remotes/\(.*\)')"
+ note_="remote branch '$note_' of " ;;
*)
note_="$remote_name of " ;;
esac
@@ -147,10 +153,10 @@ fast_forward_local () {
else
echo >&2 "* $1: storing $3"
fi
- git-update-ref "$1" "$2"
+ git-update-ref "$1" "$2"
;;
- refs/heads/*)
+ refs/heads/* | refs/remotes/*)
# $1 is the ref being updated.
# $2 is the new value for the ref.
local=$(git-rev-parse --verify "$1^0" 2>/dev/null)
diff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl
index afe80e6..5986e54 100755
--- a/git-fmt-merge-msg.perl
+++ b/git-fmt-merge-msg.perl
@@ -75,6 +75,7 @@ while (<>) {
$src{$src} = {
BRANCH => [],
TAG => [],
+ R_BRANCH => [],
GENERIC => [],
# &1 == has HEAD.
# &2 == has others.
@@ -91,6 +92,11 @@ while (<>) {
push @{$src{$src}{TAG}}, $1;
$src{$src}{HEAD_STATUS} |= 2;
}
+ elsif (/^remote branch (.*)$/) {
+ $origin = $1;
+ push @{$src{$src}{R_BRANCH}}, $1;
+ $src{$src}{HEAD_STATUS} |= 2;
+ }
elsif (/^HEAD$/) {
$origin = $src;
$src{$src}{HEAD_STATUS} |= 1;
@@ -123,6 +129,8 @@ for my $src (@src) {
}
push @this, andjoin("branch ", "branches ",
$src{$src}{BRANCH});
+ push @this, andjoin("remote branch ", "remote branches ",
+ $src{$src}{R_BRANCH});
push @this, andjoin("tag ", "tags ",
$src{$src}{TAG});
push @this, andjoin("commit ", "commits ",
diff --git a/git-merge.sh b/git-merge.sh
index cc0952a..78ab422 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -11,11 +11,15 @@ LF='
'
all_strategies='recursive octopus resolve stupid ours'
-default_strategies='recursive'
+default_twohead_strategies='recursive'
+default_octopus_strategies='octopus'
+no_trivial_merge_strategies='ours'
use_strategies=
+
+index_merge=t
if test "@@NO_PYTHON@@"; then
all_strategies='resolve octopus stupid ours'
- default_strategies='resolve'
+ default_twohead_strategies='resolve'
fi
dropsave() {
@@ -90,8 +94,6 @@ do
shift
done
-test "$#" -le 2 && usage ;# we need at least two heads.
-
merge_msg="$1"
shift
head_arg="$1"
@@ -99,6 +101,8 @@ head=$(git-rev-parse --verify "$1"^0) || usage
shift
# All the rest are remote heads
+test "$#" = 0 && usage ;# we need at least one remote head.
+
remoteheads=
for remote
do
@@ -108,6 +112,27 @@ do
done
set x $remoteheads ; shift
+case "$use_strategies" in
+'')
+ case "$#" in
+ 1)
+ use_strategies="$default_twohead_strategies" ;;
+ *)
+ use_strategies="$default_octopus_strategies" ;;
+ esac
+ ;;
+esac
+
+for s in $use_strategies
+do
+ case " $s " in
+ *" $no_trivial_merge_strategies "*)
+ index_merge=f
+ break
+ ;;
+ esac
+done
+
case "$#" in
1)
common=$(git-merge-base --all $head "$@")
@@ -118,18 +143,21 @@ case "$#" in
esac
echo "$head" >"$GIT_DIR/ORIG_HEAD"
-case "$#,$common,$no_commit" in
-*,'',*)
+case "$index_merge,$#,$common,$no_commit" in
+f,*)
+ # We've been told not to try anything clever. Skip to real merge.
+ ;;
+?,*,'',*)
# No common ancestors found. We need a real merge.
;;
-1,"$1",*)
+?,1,"$1",*)
# If head can reach all the merge then we are up to date.
- # but first the most common case of merging one remote
+ # but first the most common case of merging one remote.
echo "Already up-to-date."
dropsave
exit 0
;;
-1,"$head",*)
+?,1,"$head",*)
# Again the most common case of merging one remote.
echo "Updating from $head to $1"
git-update-index --refresh 2>/dev/null
@@ -139,11 +167,11 @@ case "$#,$common,$no_commit" in
dropsave
exit 0
;;
-1,?*"$LF"?*,*)
+?,1,?*"$LF"?*,*)
# We are not doing octopus and not fast forward. Need a
# real merge.
;;
-1,*,)
+?,1,*,)
# We are not doing octopus, not fast forward, and have only
# one common. See if it is really trivial.
git var GIT_COMMITTER_IDENT >/dev/null || exit
@@ -188,17 +216,6 @@ esac
# We are going to make a new commit.
git var GIT_COMMITTER_IDENT >/dev/null || exit
-case "$use_strategies" in
-'')
- case "$#" in
- 1)
- use_strategies="$default_strategies" ;;
- *)
- use_strategies=octopus ;;
- esac
- ;;
-esac
-
# At this point, we need a real merge. No matter what strategy
# we use, it would operate on the index, possibly affecting the
# working tree, and when resolved cleanly, have the desired tree
@@ -270,11 +287,7 @@ done
# auto resolved the merge cleanly.
if test '' != "$result_tree"
then
- parents="-p $head"
- for remote
- do
- parents="$parents -p $remote"
- done
+ parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
finish "$result_commit" "Merge $result_commit, made by $wt_strategy."
dropsave
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 5f158c6..63f2281 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -86,14 +86,14 @@ canon_refs_list_for_fetch () {
local=$(expr "$ref" : '[^:]*:\(.*\)')
case "$remote" in
'') remote=HEAD ;;
- refs/heads/* | refs/tags/*) ;;
- heads/* | tags/* ) remote="refs/$remote" ;;
+ refs/heads/* | refs/tags/* | refs/remotes/*) ;;
+ heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
*) remote="refs/heads/$remote" ;;
esac
case "$local" in
'') local= ;;
- refs/heads/* | refs/tags/*) ;;
- heads/* | tags/* ) local="refs/$local" ;;
+ refs/heads/* | refs/tags/* | refs/remotes/*) ;;
+ heads/* | tags/* | remotes/* ) local="refs/$local" ;;
*) local="refs/heads/$local" ;;
esac
diff --git a/ls-files.c b/ls-files.c
index e42119c..3a17e5d 100644
--- a/ls-files.c
+++ b/ls-files.c
@@ -11,6 +11,7 @@
#include "cache.h"
#include "quote.h"
+static int abbrev = 0;
static int show_deleted = 0;
static int show_cached = 0;
static int show_others = 0;
@@ -489,7 +490,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
printf("%s%06o %s %d\t",
tag,
ntohl(ce->ce_mode),
- sha1_to_hex(ce->sha1),
+ abbrev ? find_unique_abbrev(ce->sha1,abbrev)
+ : sha1_to_hex(ce->sha1),
ce_stage(ce));
write_name_quoted("", 0, ce->name + offset,
line_terminator, stdout);
@@ -630,7 +632,8 @@ static void verify_pathspec(void)
static const char ls_files_usage[] =
"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* "
"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] "
- "[ --exclude-per-directory=<filename> ] [--full-name] [--] [<file>]*";
+ "[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
+ "[--] [<file>]*";
int main(int argc, const char **argv)
{
@@ -737,6 +740,18 @@ int main(int argc, const char **argv)
error_unmatch = 1;
continue;
}
+ if (!strncmp(arg, "--abbrev=", 9)) {
+ abbrev = strtoul(arg+9, NULL, 10);
+ if (abbrev && abbrev < MINIMUM_ABBREV)
+ abbrev = MINIMUM_ABBREV;
+ else if (abbrev > 40)
+ abbrev = 40;
+ continue;
+ }
+ if (!strcmp(arg, "--abbrev")) {
+ abbrev = DEFAULT_ABBREV;
+ continue;
+ }
if (*arg == '-')
usage(ls_files_usage);
break;
diff --git a/ls-tree.c b/ls-tree.c
index d005643..26258c3 100644
--- a/ls-tree.c
+++ b/ls-tree.c
@@ -13,13 +13,14 @@ static int line_termination = '\n';
#define LS_TREE_ONLY 2
#define LS_SHOW_TREES 4
#define LS_NAME_ONLY 8
+static int abbrev = 0;
static int ls_options = 0;
const char **pathspec;
static int chomp_prefix = 0;
static const char *prefix;
static const char ls_tree_usage[] =
- "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] <tree-ish> [path...]";
+ "git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]";
static int show_recursive(const char *base, int baselen, const char *pathname)
{
@@ -73,7 +74,9 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen,
return 0;
if (!(ls_options & LS_NAME_ONLY))
- printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
+ printf("%06o %s %s\t", mode, type,
+ abbrev ? find_unique_abbrev(sha1,abbrev)
+ : sha1_to_hex(sha1));
write_name_quoted(base + chomp_prefix, baselen - chomp_prefix,
pathname,
line_termination, stdout);
@@ -87,6 +90,7 @@ int main(int argc, const char **argv)
struct tree *tree;
prefix = setup_git_directory();
+ git_config(git_default_config);
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
while (1 < argc && argv[1][0] == '-') {
@@ -113,6 +117,18 @@ int main(int argc, const char **argv)
chomp_prefix = 0;
break;
}
+ if (!strncmp(argv[1]+2, "abbrev=",7)) {
+ abbrev = strtoul(argv[1]+9, NULL, 10);
+ if (abbrev && abbrev < MINIMUM_ABBREV)
+ abbrev = MINIMUM_ABBREV;
+ else if (abbrev > 40)
+ abbrev = 40;
+ break;
+ }
+ if (!strcmp(argv[1]+2, "abbrev")) {
+ abbrev = DEFAULT_ABBREV;
+ break;
+ }
/* otherwise fallthru */
default:
usage(ls_tree_usage);
diff --git a/merge-base.c b/merge-base.c
index e73fca7..07f5ab4 100644
--- a/merge-base.c
+++ b/merge-base.c
@@ -237,6 +237,7 @@ int main(int argc, char **argv)
unsigned char rev1key[20], rev2key[20];
setup_git_directory();
+ git_config(git_default_config);
while (1 < argc && argv[1][0] == '-') {
char *arg = argv[1];
diff --git a/name-rev.c b/name-rev.c
index 0c3f547..bad8a53 100644
--- a/name-rev.c
+++ b/name-rev.c
@@ -127,6 +127,7 @@ int main(int argc, char **argv)
int as_is = 0, all = 0, transform_stdin = 0;
setup_git_directory();
+ git_config(git_default_config);
if (argc < 2)
usage(name_rev_usage);
diff --git a/read-tree.c b/read-tree.c
index 1c3b09b..eaff444 100644
--- a/read-tree.c
+++ b/read-tree.c
@@ -717,6 +717,7 @@ int main(int argc, char **argv)
merge_fn_t fn = NULL;
setup_git_directory();
+ git_config(git_default_config);
newfd = hold_index_file_for_update(&cache_file, get_index_file());
if (newfd < 0)
diff --git a/rev-list.c b/rev-list.c
index 812d237..441c437 100644
--- a/rev-list.c
+++ b/rev-list.c
@@ -40,13 +40,18 @@ static int bisect_list = 0;
static int verbose_header = 0;
static int abbrev = DEFAULT_ABBREV;
static int show_parents = 0;
+static int show_timestamp = 0;
static int hdr_termination = 0;
static const char *commit_prefix = "";
static enum cmit_fmt commit_format = CMIT_FMT_RAW;
static void show_commit(struct commit *commit)
{
- printf("%s%s", commit_prefix, sha1_to_hex(commit->object.sha1));
+ if (show_timestamp)
+ printf("%lu ", commit->date);
+ if (commit_prefix[0])
+ fputs(commit_prefix, stdout);
+ fputs(sha1_to_hex(commit->object.sha1), stdout);
if (show_parents) {
struct commit_list *parents = commit->parents;
while (parents) {
@@ -335,6 +340,10 @@ int main(int argc, const char **argv)
show_parents = 1;
continue;
}
+ if (!strcmp(arg, "--timestamp")) {
+ show_timestamp = 1;
+ continue;
+ }
if (!strcmp(arg, "--bisect")) {
bisect_list = 1;
continue;
diff --git a/rev-parse.c b/rev-parse.c
index f90e999..19a5ef7 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -166,6 +166,8 @@ int main(int argc, char **argv)
unsigned char sha1[20];
const char *prefix = setup_git_directory();
+ git_config(git_default_config);
+
for (i = 1; i < argc; i++) {
struct stat st;
char *arg = argv[i];
diff --git a/send-pack.c b/send-pack.c
index c8ffc8d..409f188 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -362,6 +362,8 @@ int main(int argc, char **argv)
pid_t pid;
setup_git_directory();
+ git_config(git_default_config);
+
argv++;
for (i = 1; i < argc; i++, argv++) {
char *arg = *argv;
diff --git a/sha1_name.c b/sha1_name.c
index d67de18..4f92e12 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -235,14 +235,21 @@ static int ambiguous_path(const char *path, int len)
static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
{
- static const char *prefix[] = {
- "",
- "refs",
- "refs/tags",
- "refs/heads",
+ static const char *fmt[] = {
+ "%.*s",
+ "refs/%.*s",
+ "refs/tags/%.*s",
+ "refs/heads/%.*s",
+ "refs/remotes/%.*s",
+ "refs/remotes/%.*s/HEAD",
NULL
};
const char **p;
+ const char *warning = "warning: refname '%.*s' is ambiguous.\n";
+ char *pathname;
+ int already_found = 0;
+ unsigned char *this_result;
+ unsigned char sha1_from_ref[20];
if (len == 40 && !get_sha1_hex(str, sha1))
return 0;
@@ -251,11 +258,21 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
if (ambiguous_path(str, len))
return -1;
- for (p = prefix; *p; p++) {
- char *pathname = git_path("%s/%.*s", *p, len, str);
- if (!read_ref(pathname, sha1))
- return 0;
+ for (p = fmt; *p; p++) {
+ this_result = already_found ? sha1_from_ref : sha1;
+ pathname = git_path(*p, len, str);
+ if (!read_ref(pathname, this_result)) {
+ if (warn_ambiguous_refs) {
+ if (already_found)
+ fprintf(stderr, warning, len, str);
+ already_found++;
+ }
+ else
+ return 0;
+ }
}
+ if (already_found)
+ return 0;
return -1;
}
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index adc5e93..278eb66 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -34,6 +34,9 @@ test_expect_success \
mkdir a/bin &&
cp /bin/sh a/bin &&
ln -s a a/l1 &&
+ (p=long_path_to_a_file && cd a &&
+ for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
+ echo text >file_with_long_path) &&
(cd a && find .) | sort >a.lst'
test_expect_success \
diff --git a/tar-tree.c b/tar-tree.c
index e478e13..8d9e31c 100644
--- a/tar-tree.c
+++ b/tar-tree.c
@@ -1,37 +1,23 @@
/*
- * Copyright (c) 2005 Rene Scharfe
+ * Copyright (c) 2005, 2006 Rene Scharfe
*/
#include <time.h>
#include "cache.h"
#include "diff.h"
#include "commit.h"
+#include "strbuf.h"
+#include "tar.h"
#define RECORDSIZE (512)
#define BLOCKSIZE (RECORDSIZE * 20)
-#define TYPEFLAG_AUTO '\0'
-#define TYPEFLAG_REG '0'
-#define TYPEFLAG_LNK '2'
-#define TYPEFLAG_DIR '5'
-#define TYPEFLAG_GLOBAL_HEADER 'g'
-#define TYPEFLAG_EXT_HEADER 'x'
-
-#define EXT_HEADER_PATH 1
-#define EXT_HEADER_LINKPATH 2
-
static const char tar_tree_usage[] = "git-tar-tree <key> [basedir]";
static char block[BLOCKSIZE];
static unsigned long offset;
-static const char *basedir;
static time_t archive_time;
-struct path_prefix {
- struct path_prefix *prev;
- const char *name;
-};
-
/* tries hard to write, either succeeds or dies in the attempt */
static void reliable_write(void *buf, unsigned long size)
{
@@ -119,230 +105,170 @@ static void write_blocked(void *buf, unsigned long size)
write_if_needed();
}
-static void append_string(char **p, const char *s)
-{
- unsigned int len = strlen(s);
- memcpy(*p, s, len);
- *p += len;
-}
-
-static void append_char(char **p, char c)
-{
- **p = c;
- *p += 1;
-}
-
-static void append_path_prefix(char **buffer, struct path_prefix *prefix)
+static void strbuf_append_string(struct strbuf *sb, const char *s)
{
- if (!prefix)
- return;
- append_path_prefix(buffer, prefix->prev);
- append_string(buffer, prefix->name);
- append_char(buffer, '/');
-}
-
-static unsigned int path_prefix_len(struct path_prefix *prefix)
-{
- if (!prefix)
- return 0;
- return path_prefix_len(prefix->prev) + strlen(prefix->name) + 1;
-}
-
-static void append_path(char **p, int is_dir, const char *basepath,
- struct path_prefix *prefix, const char *path)
-{
- if (basepath) {
- append_string(p, basepath);
- append_char(p, '/');
+ int slen = strlen(s);
+ int total = sb->len + slen;
+ if (total > sb->alloc) {
+ sb->buf = xrealloc(sb->buf, total);
+ sb->alloc = total;
}
- append_path_prefix(p, prefix);
- append_string(p, path);
- if (is_dir)
- append_char(p, '/');
+ memcpy(sb->buf + sb->len, s, slen);
+ sb->len = total;
}
-static unsigned int path_len(int is_dir, const char *basepath,
- struct path_prefix *prefix, const char *path)
-{
- unsigned int len = 0;
- if (basepath)
- len += strlen(basepath) + 1;
- len += path_prefix_len(prefix) + strlen(path);
- if (is_dir)
- len++;
- return len;
-}
-
-static void append_extended_header_prefix(char **p, unsigned int size,
- const char *keyword)
+/*
+ * pax extended header records have the format "%u %s=%s\n". %u contains
+ * the size of the whole string (including the %u), the first %s is the
+ * keyword, the second one is the value. This function constructs such a
+ * string and appends it to a struct strbuf.
+ */
+static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
+ const char *value, unsigned int valuelen)
{
- int len = sprintf(*p, "%u %s=", size, keyword);
- *p += len;
-}
+ char *p;
+ int len, total, tmp;
-static unsigned int extended_header_len(const char *keyword,
- unsigned int valuelen)
-{
/* "%u %s=%s\n" */
- unsigned int len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
- if (len > 9)
- len++;
- if (len > 99)
+ len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
+ for (tmp = len; tmp > 9; tmp /= 10)
len++;
- return len;
-}
-static void append_extended_header(char **p, const char *keyword,
- const char *value, unsigned int len)
-{
- unsigned int size = extended_header_len(keyword, len);
- append_extended_header_prefix(p, size, keyword);
- memcpy(*p, value, len);
- *p += len;
- append_char(p, '\n');
-}
+ total = sb->len + len;
+ if (total > sb->alloc) {
+ sb->buf = xrealloc(sb->buf, total);
+ sb->alloc = total;
+ }
-static void write_header(const unsigned char *, char, const char *, struct path_prefix *,
- const char *, unsigned int, void *, unsigned long);
+ p = sb->buf;
+ p += sprintf(p, "%u %s=", len, keyword);
+ memcpy(p, value, valuelen);
+ p += valuelen;
+ *p = '\n';
+ sb->len = total;
+}
-/* stores a pax extended header directly in the block buffer */
-static void write_extended_header(const char *headerfilename, int is_dir,
- unsigned int flags, const char *basepath,
- struct path_prefix *prefix,
- const char *path, unsigned int namelen,
- void *content, unsigned int contentsize)
+static unsigned int ustar_header_chksum(const struct ustar_header *header)
{
- char *buffer, *p;
- unsigned int pathlen, size, linkpathlen = 0;
-
- size = pathlen = extended_header_len("path", namelen);
- if (flags & EXT_HEADER_LINKPATH) {
- linkpathlen = extended_header_len("linkpath", contentsize);
- size += linkpathlen;
- }
- write_header(NULL, TYPEFLAG_EXT_HEADER, NULL, NULL, headerfilename,
- 0100600, NULL, size);
-
- buffer = p = malloc(size);
- if (!buffer)
- die("git-tar-tree: %s", strerror(errno));
- append_extended_header_prefix(&p, pathlen, "path");
- append_path(&p, is_dir, basepath, prefix, path);
- append_char(&p, '\n');
- if (flags & EXT_HEADER_LINKPATH)
- append_extended_header(&p, "linkpath", content, contentsize);
- write_blocked(buffer, size);
- free(buffer);
+ char *p = (char *)header;
+ unsigned int chksum = 0;
+ while (p < header->chksum)
+ chksum += *p++;
+ chksum += sizeof(header->chksum) * ' ';
+ p += sizeof(header->chksum);
+ while (p < (char *)header + sizeof(struct ustar_header))
+ chksum += *p++;
+ return chksum;
}
-static void write_global_extended_header(const unsigned char *sha1)
+static int get_path_prefix(const struct strbuf *path, int maxlen)
{
- char *p;
- unsigned int size;
-
- size = extended_header_len("comment", 40);
- write_header(NULL, TYPEFLAG_GLOBAL_HEADER, NULL, NULL,
- "pax_global_header", 0100600, NULL, size);
-
- p = get_record();
- append_extended_header(&p, "comment", sha1_to_hex(sha1), 40);
- write_if_needed();
+ int i = path->len;
+ if (i > maxlen)
+ i = maxlen;
+ while (i > 0 && path->buf[i] != '/')
+ i--;
+ return i;
}
-/* stores a ustar header directly in the block buffer */
-static void write_header(const unsigned char *sha1, char typeflag, const char *basepath,
- struct path_prefix *prefix, const char *path,
- unsigned int mode, void *buffer, unsigned long size)
+static void write_entry(const unsigned char *sha1, struct strbuf *path,
+ unsigned int mode, void *buffer, unsigned long size)
{
- unsigned int namelen;
- char *header = NULL;
- unsigned int checksum = 0;
- int i;
- unsigned int ext_header = 0;
-
- if (typeflag == TYPEFLAG_AUTO) {
- if (S_ISDIR(mode))
- typeflag = TYPEFLAG_DIR;
- else if (S_ISLNK(mode))
- typeflag = TYPEFLAG_LNK;
- else
- typeflag = TYPEFLAG_REG;
- }
-
- namelen = path_len(S_ISDIR(mode), basepath, prefix, path);
- if (namelen > 100)
- ext_header |= EXT_HEADER_PATH;
- if (typeflag == TYPEFLAG_LNK && size > 100)
- ext_header |= EXT_HEADER_LINKPATH;
-
- /* the extended header must be written before the normal one */
- if (ext_header) {
- char headerfilename[51];
- sprintf(headerfilename, "%s.paxheader", sha1_to_hex(sha1));
- write_extended_header(headerfilename, S_ISDIR(mode),
- ext_header, basepath, prefix, path,
- namelen, buffer, size);
- }
-
- header = get_record();
-
- if (ext_header) {
- sprintf(header, "%s.data", sha1_to_hex(sha1));
+ struct ustar_header header;
+ struct strbuf ext_header;
+
+ memset(&header, 0, sizeof(header));
+ ext_header.buf = NULL;
+ ext_header.len = ext_header.alloc = 0;
+
+ if (!sha1) {
+ *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
+ mode = 0100666;
+ strcpy(header.name, "pax_global_header");
+ } else if (!path) {
+ *header.typeflag = TYPEFLAG_EXT_HEADER;
+ mode = 0100666;
+ sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
} else {
- char *p = header;
- append_path(&p, S_ISDIR(mode), basepath, prefix, path);
+ if (S_ISDIR(mode)) {
+ *header.typeflag = TYPEFLAG_DIR;
+ mode |= 0777;
+ } else if (S_ISLNK(mode)) {
+ *header.typeflag = TYPEFLAG_LNK;
+ mode |= 0777;
+ } else if (S_ISREG(mode)) {
+ *header.typeflag = TYPEFLAG_REG;
+ mode |= (mode & 0100) ? 0777 : 0666;
+ } else {
+ error("unsupported file mode: 0%o (SHA1: %s)",
+ mode, sha1_to_hex(sha1));
+ return;
+ }
+ if (path->len > sizeof(header.name)) {
+ int plen = get_path_prefix(path, sizeof(header.prefix));
+ int rest = path->len - plen - 1;
+ if (plen > 0 && rest <= sizeof(header.name)) {
+ memcpy(header.prefix, path->buf, plen);
+ memcpy(header.name, path->buf + plen + 1, rest);
+ } else {
+ sprintf(header.name, "%s.data",
+ sha1_to_hex(sha1));
+ strbuf_append_ext_header(&ext_header, "path",
+ path->buf, path->len);
+ }
+ } else
+ memcpy(header.name, path->buf, path->len);
}
- if (typeflag == TYPEFLAG_LNK) {
- if (ext_header & EXT_HEADER_LINKPATH) {
- sprintf(&header[157], "see %s.paxheader",
+ if (S_ISLNK(mode) && buffer) {
+ if (size > sizeof(header.linkname)) {
+ sprintf(header.linkname, "see %s.paxheader",
sha1_to_hex(sha1));
- } else {
- if (buffer)
- strncpy(&header[157], buffer, size);
- }
+ strbuf_append_ext_header(&ext_header, "linkpath",
+ buffer, size);
+ } else
+ memcpy(header.linkname, buffer, size);
}
- if (S_ISDIR(mode))
- mode |= 0777;
- else if (S_ISREG(mode))
- mode |= (mode & 0100) ? 0777 : 0666;
- else if (S_ISLNK(mode))
- mode |= 0777;
- sprintf(&header[100], "%07o", mode & 07777);
+ sprintf(header.mode, "%07o", mode & 07777);
+ sprintf(header.size, "%011lo", S_ISREG(mode) ? size : 0);
+ sprintf(header.mtime, "%011lo", archive_time);
/* XXX: should we provide more meaningful info here? */
- sprintf(&header[108], "%07o", 0); /* uid */
- sprintf(&header[116], "%07o", 0); /* gid */
- strncpy(&header[265], "git", 31); /* uname */
- strncpy(&header[297], "git", 31); /* gname */
-
- if (S_ISDIR(mode) || S_ISLNK(mode))
- size = 0;
- sprintf(&header[124], "%011lo", size);
- sprintf(&header[136], "%011lo", archive_time);
+ sprintf(header.uid, "%07o", 0);
+ sprintf(header.gid, "%07o", 0);
+ strncpy(header.uname, "git", 31);
+ strncpy(header.gname, "git", 31);
+ sprintf(header.devmajor, "%07o", 0);
+ sprintf(header.devminor, "%07o", 0);
- header[156] = typeflag;
+ memcpy(header.magic, "ustar", 6);
+ memcpy(header.version, "00", 2);
- memcpy(&header[257], "ustar", 6);
- memcpy(&header[263], "00", 2);
+ sprintf(header.chksum, "%07o", ustar_header_chksum(&header));
- sprintf(&header[329], "%07o", 0); /* devmajor */
- sprintf(&header[337], "%07o", 0); /* devminor */
-
- memset(&header[148], ' ', 8);
- for (i = 0; i < RECORDSIZE; i++)
- checksum += header[i];
- sprintf(&header[148], "%07o", checksum & 0x1fffff);
+ if (ext_header.len > 0) {
+ write_entry(sha1, NULL, 0, ext_header.buf, ext_header.len);
+ free(ext_header.buf);
+ }
+ write_blocked(&header, sizeof(header));
+ if (S_ISREG(mode) && buffer && size > 0)
+ write_blocked(buffer, size);
+}
- write_if_needed();
+static void write_global_extended_header(const unsigned char *sha1)
+{
+ struct strbuf ext_header;
+ ext_header.buf = NULL;
+ ext_header.len = ext_header.alloc = 0;
+ strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
+ write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
+ free(ext_header.buf);
}
-static void traverse_tree(struct tree_desc *tree,
- struct path_prefix *prefix)
+static void traverse_tree(struct tree_desc *tree, struct strbuf *path)
{
- struct path_prefix this_prefix;
- this_prefix.prev = prefix;
+ int pathlen = path->len;
while (tree->size) {
const char *name;
@@ -358,16 +284,19 @@ static void traverse_tree(struct tree_desc *tree,
eltbuf = read_sha1_file(sha1, elttype, &eltsize);
if (!eltbuf)
die("cannot read %s", sha1_to_hex(sha1));
- write_header(sha1, TYPEFLAG_AUTO, basedir,
- prefix, name, mode, eltbuf, eltsize);
+
+ path->len = pathlen;
+ strbuf_append_string(path, name);
+ if (S_ISDIR(mode))
+ strbuf_append_string(path, "/");
+
+ write_entry(sha1, path, mode, eltbuf, eltsize);
+
if (S_ISDIR(mode)) {
struct tree_desc subtree;
subtree.buf = eltbuf;
subtree.size = eltsize;
- this_prefix.name = name;
- traverse_tree(&subtree, &this_prefix);
- } else if (!S_ISLNK(mode)) {
- write_blocked(eltbuf, eltsize);
+ traverse_tree(&subtree, path);
}
free(eltbuf);
}
@@ -375,15 +304,22 @@ static void traverse_tree(struct tree_desc *tree,
int main(int argc, char **argv)
{
- unsigned char sha1[20];
+ unsigned char sha1[20], tree_sha1[20];
struct commit *commit;
struct tree_desc tree;
+ struct strbuf current_path;
+
+ current_path.buf = xmalloc(PATH_MAX);
+ current_path.alloc = PATH_MAX;
+ current_path.len = current_path.eof = 0;
setup_git_directory();
+ git_config(git_default_config);
switch (argc) {
case 3:
- basedir = argv[2];
+ strbuf_append_string(&current_path, argv[2]);
+ strbuf_append_string(&current_path, "/");
/* FALLTHROUGH */
case 2:
if (get_sha1(argv[1], sha1) < 0)
@@ -397,17 +333,19 @@ int main(int argc, char **argv)
if (commit) {
write_global_extended_header(commit->object.sha1);
archive_time = commit->date;
- }
- tree.buf = read_object_with_reference(sha1, "tree", &tree.size, NULL);
+ } else
+ archive_time = time(NULL);
+
+ tree.buf = read_object_with_reference(sha1, "tree", &tree.size,
+ tree_sha1);
if (!tree.buf)
die("not a reference to a tag, commit or tree object: %s",
sha1_to_hex(sha1));
- if (!archive_time)
- archive_time = time(NULL);
- if (basedir)
- write_header((unsigned char *)"0", TYPEFLAG_DIR, NULL, NULL,
- basedir, 040777, NULL, 0);
- traverse_tree(&tree, NULL);
+
+ if (current_path.len > 0)
+ write_entry(tree_sha1, &current_path, 040777, NULL, 0);
+ traverse_tree(&tree, &current_path);
write_trailer();
+ free(current_path.buf);
return 0;
}
diff --git a/tar.h b/tar.h
new file mode 100644
index 0000000..3467705
--- /dev/null
+++ b/tar.h
@@ -0,0 +1,25 @@
+#define TYPEFLAG_AUTO '\0'
+#define TYPEFLAG_REG '0'
+#define TYPEFLAG_LNK '2'
+#define TYPEFLAG_DIR '5'
+#define TYPEFLAG_GLOBAL_HEADER 'g'
+#define TYPEFLAG_EXT_HEADER 'x'
+
+struct ustar_header {
+ char name[100]; /* 0 */
+ char mode[8]; /* 100 */
+ char uid[8]; /* 108 */
+ char gid[8]; /* 116 */
+ char size[12]; /* 124 */
+ char mtime[12]; /* 136 */
+ char chksum[8]; /* 148 */
+ char typeflag[1]; /* 156 */
+ char linkname[100]; /* 157 */
+ char magic[6]; /* 257 */
+ char version[2]; /* 263 */
+ char uname[32]; /* 265 */
+ char gname[32]; /* 297 */
+ char devmajor[8]; /* 329 */
+ char devminor[8]; /* 337 */
+ char prefix[155]; /* 345 */
+};
diff --git a/unpack-file.c b/unpack-file.c
index 07303f8..3accb97 100644
--- a/unpack-file.c
+++ b/unpack-file.c
@@ -30,6 +30,7 @@ int main(int argc, char **argv)
usage("git-unpack-file <sha1>");
setup_git_directory();
+ git_config(git_default_config);
puts(create_temp_file(sha1));
return 0;
diff --git a/update-ref.c b/update-ref.c
index e6fbddb..ba4bf51 100644
--- a/update-ref.c
+++ b/update-ref.c
@@ -25,6 +25,7 @@ int main(int argc, char **argv)
int fd, written;
setup_git_directory();
+ git_config(git_default_config);
if (argc < 3 || argc > 4)
usage(git_update_ref_usage);