Merge branch 'rs/graph-simplify'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2014 19:36:11 +0000 (12:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2014 19:36:11 +0000 (12:36 -0700)
* rs/graph-simplify:
graph: simplify graph_padding_line()

63 files changed:
Documentation/RelNotes/2.2.0.txt
Documentation/git-credential-cache--daemon.txt
Documentation/git-rev-parse.txt
Documentation/pretty-formats.txt
Documentation/technical/api-allocation-growing.txt
attr.c
builtin/apply.c
builtin/branch.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/hash-object.c
builtin/index-pack.c
builtin/log.c
builtin/merge.c
builtin/mv.c
builtin/pack-objects.c
builtin/prune-packed.c
builtin/receive-pack.c
builtin/repack.c
builtin/rev-parse.c
builtin/show-branch.c
builtin/unpack-objects.c
cache.h
column.c
commit-slab.h
credential-cache--daemon.c
fast-import.c
fsck.c
fsck.h
git-compat-util.h
git-stash.sh
git.c
graph.c
help.c
khash.h
line-log.c
log-tree.c
log-tree.h
object.c
object.h
pack-bitmap-write.c
pack-bitmap.c
pack-objects.c
po/TEAMS
po/de.po
pretty.c
refs.c
refs.h
revision.c
server-info.c
sh-i18n--envsubst.c
sha1_name.c
shallow.c
string-list.c
t/t1450-fsck.sh
t/t1503-rev-parse-verify.sh
t/t3201-branch-contains.sh
t/t3210-pack-refs.sh
t/t4205-log-pretty-formats.sh
t/t5302-pack-index.sh
t/t5401-update-hooks.sh
walker.c
write_or_die.c
index a8a27a95b70073a2eefccdc0e46771dd5c5a40e8..a5e3ce8f5de41ff7eb1e17686be80bf7f9c11775 100644 (file)
@@ -40,6 +40,10 @@ UI, Workflows & Features
    forgot to remove higher stage entries, or if it wanted to unresolve
    and forgot to remove the stage#0 entry).
 
+ * The "pre-receive" and "post-receive" hooks are no longer required
+   to consume their input fully (not following this requirement used
+   to result in intermittent errors in "git push").
+
 
 Performance, Internal Implementation, etc.
 
@@ -87,6 +91,20 @@ Performance, Internal Implementation, etc.
    to two separate options is detected by parse_options() API to help
    developers.
 
+ * The code path to write out the packed-refs file has been optimized,
+   which especially matters in a repository with a large number of
+   refs.
+
+ * The check to see if a ref $F can be created by making sure no
+   existing ref has $F/ as its prefix has been optimized, which
+   especially matters in a repository with a large number of existing
+   refs.
+
+ * "git fsck" was taught to check contents of tag objects a bit more.
+
+ * "git hash-object" was taught a "--literally" option to help
+   debugging.
+
 
 Also contains various documentation updates and code clean-ups.
 
@@ -169,3 +187,6 @@ notes for details).
  * "git fsck" failed to report that it found corrupt objects via its
    exit status in some cases.
    (merge 30d1038 jk/fsck-exit-code-fix later to maint).
+
+ * Use of "--verbose" option used to break "git branch --merged".
+   (merge 12994dd jk/maint-branch-verbose-merged later to maint).
index d15db42d43b9e94628246a30e7c12df41b45b935..7051c6bdf8f542b8fb8c3c4a5a24471355111922 100644 (file)
@@ -8,7 +8,7 @@ git-credential-cache--daemon - Temporarily store user credentials in memory
 SYNOPSIS
 --------
 [verse]
-git credential-cache--daemon <socket>
+git credential-cache--daemon [--debug] <socket>
 
 DESCRIPTION
 -----------
@@ -21,6 +21,10 @@ for `git-credential-cache` clients. Clients may store and retrieve
 credentials. Each credential is held for a timeout specified by the
 client; once no credentials are held, the daemon exits.
 
+If the `--debug` option is specified, the daemon does not close its
+stderr stream, and may output extra diagnostics to it even after it has
+begun listening for clients.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 0b84769bd91b5894a246ff3d499dca1ffba339ac..fa4a8c3afcb93a5fc72e9d0a5dc798d773e0bb9e 100644 (file)
@@ -114,6 +114,7 @@ can be used.
        Only meaningful in `--verify` mode. Do not output an error
        message if the first argument is not a valid object name;
        instead exit with non-zero status silently.
+       SHA-1s for valid object names are printed to stdout on success.
 
 --sq::
        Usually the output is made one line per flag and
index 6c30723740cff5d88d3696f45e2325bc565e5f4a..eecc39dec99b3cab3da3e36440653ea46ac762b9 100644 (file)
@@ -130,6 +130,7 @@ The placeholders are:
 - '%ci': committer date, ISO 8601-like format
 - '%cI': committer date, strict ISO 8601 format
 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
+- '%D': ref names without the " (", ")" wrapping.
 - '%e': encoding
 - '%s': subject
 - '%f': sanitized subject line, suitable for a filename
@@ -184,8 +185,9 @@ The placeholders are:
 NOTE: Some placeholders may depend on other options given to the
 revision traversal engine. For example, the `%g*` reflog options will
 insert an empty string unless we are traversing reflog entries (e.g., by
-`git log -g`). The `%d` placeholder will use the "short" decoration
-format if `--decorate` was not already provided on the command line.
+`git log -g`). The `%d` and `%D` placeholders will use the "short"
+decoration format if `--decorate` was not already provided on the command
+line.
 
 If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
 is inserted immediately before the expansion if and only if the
index 542946b1ba701069837b702cbd8fe8079cecf56d..5a59b548448f3744a24ff9a58181b105f9cb1934 100644 (file)
@@ -34,3 +34,6 @@ item[nr++] = value you like;
 ------------
 
 You are responsible for updating the `nr` variable.
+
+If you need to specify the number of elements to allocate explicitly
+then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
diff --git a/attr.c b/attr.c
index 734222dc45c588736f963dea7907258e76024415..cd5469770a6f7841ae327e6ba7141dd99d9cacc1 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -97,8 +97,7 @@ static struct git_attr *git_attr_internal(const char *name, int len)
        a->attr_nr = attr_nr++;
        git_attr_hash[pos] = a;
 
-       check_all_attr = xrealloc(check_all_attr,
-                                 sizeof(*check_all_attr) * attr_nr);
+       REALLOC_ARRAY(check_all_attr, attr_nr);
        check_all_attr[a->attr_nr].attr = a;
        check_all_attr[a->attr_nr].value = ATTR__UNKNOWN;
        return a;
index f204cca5d2df50d8ecb01944927fb756ac387b5e..8714a887203acd84ad08f3e0917fc72b2c7a3138 100644 (file)
@@ -2626,7 +2626,7 @@ static void update_image(struct image *img,
                 * NOTE: this knows that we never call remove_first_line()
                 * on anything other than pre/post image.
                 */
-               img->line = xrealloc(img->line, nr * sizeof(*img->line));
+               REALLOC_ARRAY(img->line, nr);
                img->line_allocated = img->line;
        }
        if (preimage_limit != postimage->nr)
index ced422b627fc05c462f6be8b6c20ee0ba9ff2628..9e4666f0c53164113ac211eee674ba838fb7ae72 100644 (file)
@@ -280,6 +280,7 @@ struct ref_item {
        char *dest;
        unsigned int kind, width;
        struct commit *commit;
+       int ignore;
 };
 
 struct ref_list {
@@ -385,6 +386,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
        newitem->commit = commit;
        newitem->width = utf8_strwidth(refname);
        newitem->dest = resolve_symref(orig_refname, prefix);
+       newitem->ignore = 0;
        /* adjust for "remotes/" */
        if (newitem->kind == REF_REMOTE_BRANCH &&
            ref_list->kinds != REF_REMOTE_BRANCH)
@@ -484,17 +486,6 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
        free(ref);
 }
 
-static int matches_merge_filter(struct commit *commit)
-{
-       int is_merged;
-
-       if (merge_filter == NO_FILTER)
-               return 1;
-
-       is_merged = !!(commit->object.flags & UNINTERESTING);
-       return (is_merged == (merge_filter == SHOW_MERGED));
-}
-
 static void add_verbose_info(struct strbuf *out, struct ref_item *item,
                             int verbose, int abbrev)
 {
@@ -522,10 +513,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 {
        char c;
        int color;
-       struct commit *commit = item->commit;
        struct strbuf out = STRBUF_INIT, name = STRBUF_INIT;
 
-       if (!matches_merge_filter(commit))
+       if (item->ignore)
                return;
 
        switch (item->kind) {
@@ -575,7 +565,7 @@ static int calc_maxwidth(struct ref_list *refs)
 {
        int i, w = 0;
        for (i = 0; i < refs->index; i++) {
-               if (!matches_merge_filter(refs->list[i].commit))
+               if (refs->list[i].ignore)
                        continue;
                if (refs->list[i].width > w)
                        w = refs->list[i].width;
@@ -618,6 +608,7 @@ static void show_detached(struct ref_list *ref_list)
                item.kind = REF_LOCAL_BRANCH;
                item.dest = NULL;
                item.commit = head_commit;
+               item.ignore = 0;
                if (item.width > ref_list->maxwidth)
                        ref_list->maxwidth = item.width;
                print_ref_item(&item, ref_list->maxwidth, ref_list->verbose, ref_list->abbrev, 1, "");
@@ -656,6 +647,20 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
 
                if (prepare_revision_walk(&ref_list.revs))
                        die(_("revision walk setup failed"));
+
+               for (i = 0; i < ref_list.index; i++) {
+                       struct ref_item *item = &ref_list.list[i];
+                       struct commit *commit = item->commit;
+                       int is_merged = !!(commit->object.flags & UNINTERESTING);
+                       item->ignore = is_merged != (merge_filter == SHOW_MERGED);
+               }
+
+               for (i = 0; i < ref_list.index; i++) {
+                       struct ref_item *item = &ref_list.list[i];
+                       clear_commit_marks(item->commit, ALL_REV_FLAGS);
+               }
+               clear_commit_marks(filter, ALL_REV_FLAGS);
+
                if (verbose)
                        ref_list.maxwidth = calc_maxwidth(&ref_list);
        }
index 69bba067189776d8411b1926084b53659799d0da..fda0f047125f16f080288c1cda76b0e337784a54 100644 (file)
@@ -138,10 +138,8 @@ static int parse_atom(const char *atom, const char *ep)
        /* Add it in, including the deref prefix */
        at = used_atom_cnt;
        used_atom_cnt++;
-       used_atom = xrealloc(used_atom,
-                            (sizeof *used_atom) * used_atom_cnt);
-       used_atom_type = xrealloc(used_atom_type,
-                                 (sizeof(*used_atom_type) * used_atom_cnt));
+       REALLOC_ARRAY(used_atom, used_atom_cnt);
+       REALLOC_ARRAY(used_atom_type, used_atom_cnt);
        used_atom[at] = xmemdupz(atom, ep - atom);
        used_atom_type[at] = valid_atom[i].cmp_type;
        if (*atom == '*')
@@ -870,8 +868,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
        ref->flag = flag;
 
        cnt = cb->grab_cnt;
-       cb->grab_array = xrealloc(cb->grab_array,
-                                 sizeof(*cb->grab_array) * (cnt + 1));
+       REALLOC_ARRAY(cb->grab_array, cnt + 1);
        cb->grab_array[cnt++] = ref;
        cb->grab_cnt = cnt;
        return 0;
index 0928a98a71ca2b764d4fbb59976f1c4bdc421dde..e9ba576c1fe85cab505eb13fc20ae68dcfc19ff3 100644 (file)
@@ -298,7 +298,7 @@ static int fsck_obj(struct object *obj)
 
        if (fsck_walk(obj, mark_used, NULL))
                objerror(obj, "broken links");
-       if (fsck_object(obj, check_strict, fsck_error_func))
+       if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
                return -1;
 
        if (obj->type == OBJ_TREE) {
index d7fcf4c13c7e0f0855fba51c6b58d2b06c99984e..61583633182da359556fc65795a8eb740167675c 100644 (file)
 #include "parse-options.h"
 #include "exec_cmd.h"
 
-static void hash_fd(int fd, const char *type, int write_object, const char *path)
+/*
+ * This is to create corrupt objects for debugging and as such it
+ * needs to bypass the data conversion performed by, and the type
+ * limitation imposed by, index_fd() and its callees.
+ */
+static int hash_literally(unsigned char *sha1, int fd, const char *type, unsigned flags)
+{
+       struct strbuf buf = STRBUF_INIT;
+       int ret;
+
+       if (strbuf_read(&buf, fd, 4096) < 0)
+               ret = -1;
+       else if (flags & HASH_WRITE_OBJECT)
+               ret = write_sha1_file(buf.buf, buf.len, type, sha1);
+       else
+               ret = hash_sha1_file(buf.buf, buf.len, type, sha1);
+       strbuf_release(&buf);
+       return ret;
+}
+
+static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
+                   int literally)
 {
        struct stat st;
        unsigned char sha1[20];
-       unsigned flags = (HASH_FORMAT_CHECK |
-                         (write_object ? HASH_WRITE_OBJECT : 0));
 
        if (fstat(fd, &st) < 0 ||
-           index_fd(sha1, fd, &st, type_from_string(type), path, flags))
-               die(write_object
+           (literally
+            ? hash_literally(sha1, fd, type, flags)
+            : index_fd(sha1, fd, &st, type_from_string(type), path, flags)))
+               die((flags & HASH_WRITE_OBJECT)
                    ? "Unable to add %s to database"
                    : "Unable to hash %s", path);
        printf("%s\n", sha1_to_hex(sha1));
        maybe_flush_or_die(stdout, "hash to stdout");
 }
 
-static void hash_object(const char *path, const char *type, int write_object,
-                       const char *vpath)
+static void hash_object(const char *path, const char *type, const char *vpath,
+                       unsigned flags, int literally)
 {
        int fd;
        fd = open(path, O_RDONLY);
        if (fd < 0)
                die_errno("Cannot open '%s'", path);
-       hash_fd(fd, type, write_object, vpath);
+       hash_fd(fd, type, vpath, flags, literally);
 }
 
-static int no_filters;
-
-static void hash_stdin_paths(const char *type, int write_objects)
+static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
+                            int literally)
 {
        struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
 
@@ -49,47 +69,46 @@ static void hash_stdin_paths(const char *type, int write_objects)
                                die("line is badly quoted");
                        strbuf_swap(&buf, &nbuf);
                }
-               hash_object(buf.buf, type, write_objects,
-                   no_filters ? NULL : buf.buf);
+               hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags,
+                           literally);
        }
        strbuf_release(&buf);
        strbuf_release(&nbuf);
 }
 
-static const char * const hash_object_usage[] = {
-       N_("git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>..."),
-       N_("git hash-object  --stdin-paths < <list-of-paths>"),
-       NULL
-};
-
-static const char *type;
-static int write_object;
-static int hashstdin;
-static int stdin_paths;
-static const char *vpath;
-
-static const struct option hash_object_options[] = {
-       OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
-       OPT_BOOL('w', NULL, &write_object, N_("write the object into the object database")),
-       OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
-       OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
-       OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
-       OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
-       OPT_END()
-};
-
 int cmd_hash_object(int argc, const char **argv, const char *prefix)
 {
+       static const char * const hash_object_usage[] = {
+               N_("git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>..."),
+               N_("git hash-object  --stdin-paths < <list-of-paths>"),
+               NULL
+       };
+       const char *type = blob_type;
+       int hashstdin = 0;
+       int stdin_paths = 0;
+       int no_filters = 0;
+       int literally = 0;
+       unsigned flags = HASH_FORMAT_CHECK;
+       const char *vpath = NULL;
+       const struct option hash_object_options[] = {
+               OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
+               OPT_BIT('w', NULL, &flags, N_("write the object into the object database"),
+                       HASH_WRITE_OBJECT),
+               OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
+               OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
+               OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
+               OPT_BOOL( 0, "literally", &literally, N_("just hash any random garbage to create corrupt objects for debugging Git")),
+               OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
+               OPT_END()
+       };
        int i;
        int prefix_length = -1;
        const char *errstr = NULL;
 
-       type = blob_type;
-
        argc = parse_options(argc, argv, NULL, hash_object_options,
                             hash_object_usage, 0);
 
-       if (write_object) {
+       if (flags & HASH_WRITE_OBJECT) {
                prefix = setup_git_directory();
                prefix_length = prefix ? strlen(prefix) : 0;
                if (vpath && prefix)
@@ -119,19 +138,19 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
        }
 
        if (hashstdin)
-               hash_fd(0, type, write_object, vpath);
+               hash_fd(0, type, vpath, flags, literally);
 
        for (i = 0 ; i < argc; i++) {
                const char *arg = argv[i];
 
                if (0 <= prefix_length)
                        arg = prefix_filename(prefix, prefix_length, arg);
-               hash_object(arg, type, write_object,
-                           no_filters ? NULL : vpath ? vpath : arg);
+               hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg,
+                           flags, literally);
        }
 
        if (stdin_paths)
-               hash_stdin_paths(type, write_object);
+               hash_stdin_paths(type, no_filters, flags, literally);
 
        return 0;
 }
index eebf1a8fc21fd551f3917ad23ab5a45dff302f23..792c66ca5932638e11f2587f928a6b98c08e7854 100644 (file)
@@ -779,7 +779,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                        if (!obj)
                                die(_("invalid %s"), typename(type));
                        if (do_fsck_object &&
-                           fsck_object(obj, 1, fsck_error_function))
+                           fsck_object(obj, buf, size, 1,
+                                   fsck_error_function))
                                die(_("Error in object"));
                        if (fsck_walk(obj, mark_link, NULL))
                                die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
@@ -1169,9 +1170,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
                int nr_objects_initial = nr_objects;
                if (nr_unresolved <= 0)
                        die(_("confusion beyond insanity"));
-               objects = xrealloc(objects,
-                                  (nr_objects + nr_unresolved + 1)
-                                  * sizeof(*objects));
+               REALLOC_ARRAY(objects, nr_objects + nr_unresolved + 1);
                memset(objects + nr_objects + 1, 0,
                       nr_unresolved * sizeof(*objects));
                f = sha1fd(output_fd, curr_pack);
index 4ea71fee6819e4d94812e64cc20cbf1027655013..2fb34c7de96a4236327d46bf1392d54fa882c17f 100644 (file)
@@ -1440,7 +1440,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        continue;
 
                nr++;
-               list = xrealloc(list, nr * sizeof(list[0]));
+               REALLOC_ARRAY(list, nr);
                list[nr - 1] = commit;
        }
        if (nr == 0)
index ec6fa9398faf2e5c61ebce198a5006cfb6dc8192..dff043dac33ea88a8c5a05ea5ac3da71ca00c0d3 100644 (file)
@@ -556,7 +556,7 @@ static void parse_branch_merge_options(char *bmo)
        if (argc < 0)
                die(_("Bad branch.%s.mergeoptions string: %s"), branch,
                    split_cmdline_strerror(argc));
-       argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
+       REALLOC_ARRAY(argv, argc + 2);
        memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
        argc++;
        argv[0] = "branch.*.mergeoptions";
index bf784cb94361f8db5ea17906d0199284a04be99a..8883baa903e92093cabcc3dbaac7ccec3eecd64a 100644 (file)
@@ -184,10 +184,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
                                modes[i] = WORKING_DIRECTORY;
                                n = argc + last - first;
-                               source = xrealloc(source, n * sizeof(char *));
-                               destination = xrealloc(destination, n * sizeof(char *));
-                               modes = xrealloc(modes, n * sizeof(enum update_mode));
-                               submodule_gitfile = xrealloc(submodule_gitfile, n * sizeof(char *));
+                               REALLOC_ARRAY(source, n);
+                               REALLOC_ARRAY(destination, n);
+                               REALLOC_ARRAY(modes, n);
+                               REALLOC_ARRAY(submodule_gitfile, n);
 
                                dst = add_slash(dst);
                                dst_len = strlen(dst);
index b59f5d895e38bdb96d19b5fc5061669facdf22cc..d39193453a6bf868f8b62dac18201b0b4b7bccbd 100644 (file)
@@ -89,8 +89,7 @@ static void index_commit_for_bitmap(struct commit *commit)
 {
        if (indexed_commits_nr >= indexed_commits_alloc) {
                indexed_commits_alloc = (indexed_commits_alloc + 32) * 2;
-               indexed_commits = xrealloc(indexed_commits,
-                       indexed_commits_alloc * sizeof(struct commit *));
+               REALLOC_ARRAY(indexed_commits, indexed_commits_alloc);
        }
 
        indexed_commits[indexed_commits_nr++] = commit;
index 6879468c46a7baca69e5e28b0c6e38ff7099a6ff..d430731d701d7a06e1da0d8273c03453b85dcf96 100644 (file)
@@ -68,6 +68,7 @@ void prune_packed_objects(int opts)
                rmdir(pathname.buf);
        }
        stop_progress(&progress);
+       strbuf_release(&pathname);
 }
 
 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
index afb8d9926496de2bed8bcab793dd79562e575e18..daf0600ca30eb3969e0583cc1096e6f33291d4aa 100644 (file)
@@ -15,6 +15,7 @@
 #include "connected.h"
 #include "argv-array.h"
 #include "version.h"
+#include "sigchain.h"
 
 static const char receive_pack_usage[] = "git receive-pack <git-dir>";
 
@@ -287,6 +288,8 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
                return code;
        }
 
+       sigchain_push(SIGPIPE, SIG_IGN);
+
        while (1) {
                const char *buf;
                size_t n;
@@ -298,6 +301,9 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
        close(proc.in);
        if (use_sideband)
                finish_async(&muxer);
+
+       sigchain_pop(SIGPIPE);
+
        return finish_command(&proc);
 }
 
index fc088dbe6aec8b7a8fd23c924d8bc10c426b78ec..2aae05d36486bd31666853c545c37f1280ee11c9 100644 (file)
@@ -377,6 +377,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        /* End of pack replacement. */
 
        if (delete_redundant) {
+               int opts = 0;
                sort_string_list(&names);
                for_each_string_list_item(item, &existing_packs) {
                        char *sha1;
@@ -387,25 +388,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        if (!string_list_has_string(&names, sha1))
                                remove_redundant_pack(packdir, item->string);
                }
-               argv_array_push(&cmd_args, "prune-packed");
-               if (quiet)
-                       argv_array_push(&cmd_args, "--quiet");
-
-               memset(&cmd, 0, sizeof(cmd));
-               cmd.argv = cmd_args.argv;
-               cmd.git_cmd = 1;
-               run_command(&cmd);
-               argv_array_clear(&cmd_args);
+               if (!quiet && isatty(2))
+                       opts |= PRUNE_PACKED_VERBOSE;
+               prune_packed_objects(opts);
        }
 
-       if (!no_update_server_info) {
-               argv_array_push(&cmd_args, "update-server-info");
-               memset(&cmd, 0, sizeof(cmd));
-               cmd.argv = cmd_args.argv;
-               cmd.git_cmd = 1;
-               run_command(&cmd);
-               argv_array_clear(&cmd_args);
-       }
+       if (!no_update_server_info)
+               update_server_info(0);
        remove_temporary_files();
        string_list_clear(&names, 0);
        string_list_clear(&rollback, 0);
index c911b456dedd648e36a876c6175c23e1ef028a43..35d3c43ed656bf28b78501426f4502c0dff1e7b0 100644 (file)
@@ -508,7 +508,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
        int has_dashdash = 0;
        int output_prefix = 0;
        unsigned char sha1[20];
+       unsigned int flags = 0;
        const char *name = NULL;
+       struct object_context unused;
 
        if (argc > 1 && !strcmp("--parseopt", argv[1]))
                return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -596,6 +598,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        }
                        if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
                                quiet = 1;
+                               flags |= GET_SHA1_QUIETLY;
                                continue;
                        }
                        if (!strcmp(arg, "--short") ||
@@ -818,7 +821,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        name++;
                        type = REVERSED;
                }
-               if (!get_sha1(name, sha1)) {
+               if (!get_sha1_with_context(name, flags, sha1, &unused)) {
                        if (verify)
                                revs_count++;
                        else
index 298c95e3f8b03e7f89d7767407ca8cee3eecc591..199b081e9b805cceb1f2097f2d33966e5f8ff167 100644 (file)
@@ -563,7 +563,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
                        default_arg[default_num++] = "show-branch";
                } else if (default_alloc <= default_num + 1) {
                        default_alloc = default_alloc * 3 / 2 + 20;
-                       default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
+                       REALLOC_ARRAY(default_arg, default_alloc);
                }
                default_arg[default_num++] = xstrdup(value);
                default_arg[default_num] = NULL;
@@ -723,6 +723,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                char nth_desc[256];
                char *ref;
                int base = 0;
+               unsigned int flags = 0;
 
                if (ac == 0) {
                        static const char *fake_av[2];
@@ -749,7 +750,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                /* Ah, that is a date spec... */
                                unsigned long at;
                                at = approxidate(reflog_base);
-                               read_ref_at(ref, at, -1, sha1, NULL,
+                               read_ref_at(ref, flags, at, -1, sha1, NULL,
                                            NULL, NULL, &base);
                        }
                }
@@ -760,7 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                        unsigned long timestamp;
                        int tz;
 
-                       if (read_ref_at(ref, 0, base+i, sha1, &logmsg,
+                       if (read_ref_at(ref, flags, 0, base+i, sha1, &logmsg,
                                        &timestamp, &tz, NULL)) {
                                reflog = i;
                                break;
index 99cde45879401350355083f773a2ff2b78113d1a..855d94b90ba019ff19832ff49a76d6cc0077e956 100644 (file)
@@ -164,10 +164,10 @@ static unsigned nr_objects;
  * Called only from check_object() after it verified this object
  * is Ok.
  */
-static void write_cached_object(struct object *obj)
+static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
 {
        unsigned char sha1[20];
-       struct obj_buffer *obj_buf = lookup_object_buffer(obj);
+
        if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0)
                die("failed to write object %s", sha1_to_hex(obj->sha1));
        obj->flags |= FLAG_WRITTEN;
@@ -180,6 +180,8 @@ static void write_cached_object(struct object *obj)
  */
 static int check_object(struct object *obj, int type, void *data)
 {
+       struct obj_buffer *obj_buf;
+
        if (!obj)
                return 1;
 
@@ -198,11 +200,15 @@ static int check_object(struct object *obj, int type, void *data)
                return 0;
        }
 
-       if (fsck_object(obj, 1, fsck_error_function))
+       obj_buf = lookup_object_buffer(obj);
+       if (!obj_buf)
+               die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
+       if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
+                       fsck_error_function))
                die("Error in object");
        if (fsck_walk(obj, check_object, NULL))
                die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
-       write_cached_object(obj);
+       write_cached_object(obj, obj_buf);
        return 0;
 }
 
diff --git a/cache.h b/cache.h
index af590d5077d534503263dfe0ee80a69374c27053..8206039cfe9545b4f6eb6757dfd62bf468b3be52 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -482,7 +482,7 @@ extern int daemonize(void);
                                alloc = (nr); \
                        else \
                                alloc = alloc_nr(alloc); \
-                       x = xrealloc((x), alloc * sizeof(*(x))); \
+                       REALLOC_ARRAY(x, alloc); \
                } \
        } while (0)
 
@@ -1430,6 +1430,8 @@ extern const char *git_mailmap_blob;
 
 /* IO helper functions */
 extern void maybe_flush_or_die(FILE *, const char *);
+__attribute__((format (printf, 2, 3)))
+extern void fprintf_or_die(FILE *, const char *fmt, ...);
 extern int copy_fd(int ifd, int ofd);
 extern int copy_file(const char *dst, const char *src, int mode);
 extern int copy_file_with_time(const char *dst, const char *src, int mode);
index 76b615db5f2a4ff7567a7d1d9d6514f838f15321..8082a944fd6d07f69d323678380d635d9361b77c 100644 (file)
--- a/column.c
+++ b/column.c
@@ -81,8 +81,7 @@ static void compute_column_width(struct column_data *data)
  */
 static void shrink_columns(struct column_data *data)
 {
-       data->width = xrealloc(data->width,
-                              sizeof(*data->width) * data->cols);
+       REALLOC_ARRAY(data->width, data->cols);
        while (data->rows > 1) {
                int x, total_width, cols, rows;
                rows = data->rows;
@@ -91,8 +90,7 @@ static void shrink_columns(struct column_data *data)
                data->rows--;
                data->cols = DIV_ROUND_UP(data->list->nr, data->rows);
                if (data->cols != cols)
-                       data->width = xrealloc(data->width,
-                                              sizeof(*data->width) * data->cols);
+                       REALLOC_ARRAY(data->width, data->cols);
                compute_column_width(data);
 
                total_width = strlen(data->opts.indent);
index 375c9c751adbf165c757832667102b761e1358c3..f37ec3831f60cb9072d6cbf4f3d0126bc0681bf1 100644 (file)
@@ -90,8 +90,7 @@ static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s,      \
                                                                        \
        if (s->slab_count <= nth_slab) {                                \
                int i;                                                  \
-               s->slab = xrealloc(s->slab,                             \
-                                  (nth_slab + 1) * sizeof(*s->slab));  \
+               REALLOC_ARRAY(s->slab, nth_slab + 1);                   \
                stat_ ##slabname## realloc++;                           \
                for (i = s->slab_count; i <= nth_slab; i++)             \
                        s->slab[i] = NULL;                              \
index 3b370ca5e529c74e17e0f39da5c689ebc4ccfc25..c2f00498f6a171ecde3dd91a5cbdb30d88827495 100644 (file)
@@ -2,6 +2,7 @@
 #include "credential.h"
 #include "unix-socket.h"
 #include "sigchain.h"
+#include "parse-options.h"
 
 static const char *socket_path;
 
@@ -201,7 +202,7 @@ static int serve_cache_loop(int fd)
        return 1;
 }
 
-static void serve_cache(const char *socket_path)
+static void serve_cache(const char *socket_path, int debug)
 {
        int fd;
 
@@ -211,6 +212,10 @@ static void serve_cache(const char *socket_path)
 
        printf("ok\n");
        fclose(stdout);
+       if (!debug) {
+               if (!freopen("/dev/null", "w", stderr))
+                       die_errno("unable to point stderr to /dev/null");
+       }
 
        while (serve_cache_loop(fd))
                ; /* nothing */
@@ -252,16 +257,28 @@ static void check_socket_directory(const char *path)
 
 int main(int argc, const char **argv)
 {
-       socket_path = argv[1];
+       static const char *usage[] = {
+               "git-credential-cache--daemon [opts] <socket_path>",
+               NULL
+       };
+       int debug = 0;
+       const struct option options[] = {
+               OPT_BOOL(0, "debug", &debug,
+                        N_("print debugging messages to stderr")),
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, NULL, options, usage, 0);
+       socket_path = argv[0];
 
        if (!socket_path)
-               die("usage: git-credential-cache--daemon <socket_path>");
+               usage_with_options(usage, options);
        check_socket_directory(socket_path);
 
        atexit(cleanup_socket);
        sigchain_push_common(cleanup_socket_on_signal);
 
-       serve_cache(socket_path);
+       serve_cache(socket_path, debug);
 
        return 0;
 }
index 487f1f81ac170acf87bae2801f6472c0768e3e24..96b0f4236a2083044e4ae1dfa3b8180e3e586ba1 100644 (file)
@@ -878,7 +878,7 @@ static void start_packfile(void)
        pack_size = sizeof(hdr);
        object_count = 0;
 
-       all_packs = xrealloc(all_packs, sizeof(*all_packs) * (pack_id + 1));
+       REALLOC_ARRAY(all_packs, pack_id + 1);
        all_packs[pack_id] = p;
 }
 
diff --git a/fsck.c b/fsck.c
index 56156fff44a3556e2fa0b691ab103612a4678a3e..2fffa434a5763abb6d7895ee8c7582307766ee62 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -6,6 +6,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "fsck.h"
+#include "refs.h"
 
 static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
 {
@@ -237,6 +238,26 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
        return retval;
 }
 
+static int require_end_of_header(const void *data, unsigned long size,
+       struct object *obj, fsck_error error_func)
+{
+       const char *buffer = (const char *)data;
+       unsigned long i;
+
+       for (i = 0; i < size; i++) {
+               switch (buffer[i]) {
+               case '\0':
+                       return error_func(obj, FSCK_ERROR,
+                               "unterminated header: NUL at offset %d", i);
+               case '\n':
+                       if (i + 1 < size && buffer[i + 1] == '\n')
+                               return 0;
+               }
+       }
+
+       return error_func(obj, FSCK_ERROR, "unterminated header");
+}
+
 static int fsck_ident(const char **ident, struct object *obj, fsck_error error_func)
 {
        char *end;
@@ -277,13 +298,16 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f
 }
 
 static int fsck_commit_buffer(struct commit *commit, const char *buffer,
-                             fsck_error error_func)
+       unsigned long size, fsck_error error_func)
 {
        unsigned char tree_sha1[20], sha1[20];
        struct commit_graft *graft;
        unsigned parent_count, parent_line_count = 0;
        int err;
 
+       if (require_end_of_header(buffer, size, &commit->object, error_func))
+               return -1;
+
        if (!skip_prefix(buffer, "tree ", &buffer))
                return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'tree' line");
        if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
@@ -322,24 +346,111 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
        return 0;
 }
 
-static int fsck_commit(struct commit *commit, fsck_error error_func)
+static int fsck_commit(struct commit *commit, const char *data,
+       unsigned long size, fsck_error error_func)
 {
-       const char *buffer = get_commit_buffer(commit, NULL);
-       int ret = fsck_commit_buffer(commit, buffer, error_func);
-       unuse_commit_buffer(commit, buffer);
+       const char *buffer = data ?  data : get_commit_buffer(commit, &size);
+       int ret = fsck_commit_buffer(commit, buffer, size, error_func);
+       if (!data)
+               unuse_commit_buffer(commit, buffer);
        return ret;
 }
 
-static int fsck_tag(struct tag *tag, fsck_error error_func)
+static int fsck_tag_buffer(struct tag *tag, const char *data,
+       unsigned long size, fsck_error error_func)
+{
+       unsigned char sha1[20];
+       int ret = 0;
+       const char *buffer;
+       char *to_free = NULL, *eol;
+       struct strbuf sb = STRBUF_INIT;
+
+       if (data)
+               buffer = data;
+       else {
+               enum object_type type;
+
+               buffer = to_free =
+                       read_sha1_file(tag->object.sha1, &type, &size);
+               if (!buffer)
+                       return error_func(&tag->object, FSCK_ERROR,
+                               "cannot read tag object");
+
+               if (type != OBJ_TAG) {
+                       ret = error_func(&tag->object, FSCK_ERROR,
+                               "expected tag got %s",
+                           typename(type));
+                       goto done;
+               }
+       }
+
+       if (require_end_of_header(buffer, size, &tag->object, error_func))
+               goto done;
+
+       if (!skip_prefix(buffer, "object ", &buffer)) {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid format - expected 'object' line");
+               goto done;
+       }
+       if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid 'object' line format - bad sha1");
+               goto done;
+       }
+       buffer += 41;
+
+       if (!skip_prefix(buffer, "type ", &buffer)) {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid format - expected 'type' line");
+               goto done;
+       }
+       eol = strchr(buffer, '\n');
+       if (!eol) {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid format - unexpected end after 'type' line");
+               goto done;
+       }
+       if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid 'type' value");
+       if (ret)
+               goto done;
+       buffer = eol + 1;
+
+       if (!skip_prefix(buffer, "tag ", &buffer)) {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid format - expected 'tag' line");
+               goto done;
+       }
+       eol = strchr(buffer, '\n');
+       if (!eol) {
+               ret = error_func(&tag->object, FSCK_ERROR, "invalid format - unexpected end after 'type' line");
+               goto done;
+       }
+       strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
+       if (check_refname_format(sb.buf, 0))
+               error_func(&tag->object, FSCK_WARN, "invalid 'tag' name: %s", buffer);
+       buffer = eol + 1;
+
+       if (!skip_prefix(buffer, "tagger ", &buffer))
+               /* early tags do not contain 'tagger' lines; warn only */
+               error_func(&tag->object, FSCK_WARN, "invalid format - expected 'tagger' line");
+       else
+               ret = fsck_ident(&buffer, &tag->object, error_func);
+
+done:
+       strbuf_release(&sb);
+       free(to_free);
+       return ret;
+}
+
+static int fsck_tag(struct tag *tag, const char *data,
+       unsigned long size, fsck_error error_func)
 {
        struct object *tagged = tag->tagged;
 
        if (!tagged)
                return error_func(&tag->object, FSCK_ERROR, "could not load tagged object");
-       return 0;
+
+       return fsck_tag_buffer(tag, data, size, error_func);
 }
 
-int fsck_object(struct object *obj, int strict, fsck_error error_func)
+int fsck_object(struct object *obj, void *data, unsigned long size,
+       int strict, fsck_error error_func)
 {
        if (!obj)
                return error_func(obj, FSCK_ERROR, "no valid object to fsck");
@@ -349,9 +460,11 @@ int fsck_object(struct object *obj, int strict, fsck_error error_func)
        if (obj->type == OBJ_TREE)
                return fsck_tree((struct tree *) obj, strict, error_func);
        if (obj->type == OBJ_COMMIT)
-               return fsck_commit((struct commit *) obj, error_func);
+               return fsck_commit((struct commit *) obj, (const char *) data,
+                       size, error_func);
        if (obj->type == OBJ_TAG)
-               return fsck_tag((struct tag *) obj, error_func);
+               return fsck_tag((struct tag *) obj, (const char *) data,
+                       size, error_func);
 
        return error_func(obj, FSCK_ERROR, "unknown type '%d' (internal fsck error)",
                          obj->type);
diff --git a/fsck.h b/fsck.h
index 1e4f527318ea4b4d701a27e08d68f3551173f176..d1e6387a44e223b6d9438c7c35dc9efaa52f7d48 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -28,6 +28,8 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
  *    0                everything OK
  */
 int fsck_walk(struct object *obj, fsck_walk_func walk, void *data);
-int fsck_object(struct object *obj, int strict, fsck_error error_func);
+/* If NULL is passed for data, we assume the object is local and read it. */
+int fsck_object(struct object *obj, void *data, unsigned long size,
+       int strict, fsck_error error_func);
 
 #endif
index 08a9ee2970aaef6f40fbb3c73f9c38ad176cf601..0c4e663928cb8fb03c73a6d3de6a506c7d98fc9a 100644 (file)
@@ -627,6 +627,8 @@ extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
 extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
 extern char *xgetcwd(void);
 
+#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x)))
+
 static inline size_t xsize_t(off_t len)
 {
        if (len > (size_t) len)
index 0158c7338685c8ccbc31766927f905b455a444c2..d4cf818be9488f1b94fdf4766a8f73db6bfd1029 100755 (executable)
@@ -50,7 +50,7 @@ clear_stash () {
        then
                die "$(gettext "git stash clear with parameters is unimplemented")"
        fi
-       if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
+       if current=$(git rev-parse --verify --quiet $ref_stash)
        then
                git update-ref -d $ref_stash $current
        fi
@@ -292,7 +292,7 @@ save_stash () {
 }
 
 have_stash () {
-       git rev-parse --verify $ref_stash >/dev/null 2>&1
+       git rev-parse --verify --quiet $ref_stash >/dev/null
 }
 
 list_stash () {
@@ -392,12 +392,12 @@ parse_flags_and_rev()
                ;;
        esac
 
-       REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
+       REV=$(git rev-parse --symbolic --verify --quiet "$1") || {
                reference="$1"
                die "$(eval_gettext "\$reference is not a valid reference")"
        }
 
-       i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
+       i_commit=$(git rev-parse --verify --quiet "$REV^2") &&
        set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) &&
        s=$1 &&
        w_commit=$1 &&
@@ -409,7 +409,7 @@ parse_flags_and_rev()
        test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
        IS_STASH_REF=t
 
-       u_commit=$(git rev-parse --quiet --verify "$REV^3" 2>/dev/null) &&
+       u_commit=$(git rev-parse --verify --quiet "$REV^3") &&
        u_tree=$(git rev-parse "$REV^3:" 2>/dev/null)
 }
 
@@ -531,7 +531,8 @@ drop_stash () {
                die "$(eval_gettext "\${REV}: Could not drop stash entry")"
 
        # clear_stash if we just dropped the last stash entry
-       git rev-parse --verify "$ref_stash@{0}" >/dev/null 2>&1 || clear_stash
+       git rev-parse --verify --quiet "$ref_stash@{0}" >/dev/null ||
+       clear_stash
 }
 
 apply_to_branch () {
diff --git a/git.c b/git.c
index 523768da616c5884d2279acebc43cf57c98dd3e2..4076b014aba6c488e51a9bae8e5cd4b26e4e2476 100644 (file)
--- a/git.c
+++ b/git.c
@@ -282,8 +282,7 @@ static int handle_alias(int *argcp, const char ***argv)
                                  "trace: alias expansion: %s =>",
                                  alias_command);
 
-               new_argv = xrealloc(new_argv, sizeof(char *) *
-                                   (count + *argcp));
+               REALLOC_ARRAY(new_argv, count + *argcp);
                /* insert after command name */
                memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp);
 
diff --git a/graph.c b/graph.c
index 52605e4f6bc4e3b420e5fd45fefd7bf901022435..c25a09a8fdaf3e90bf7e029c78127146418ab023 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -267,16 +267,10 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
                graph->column_capacity *= 2;
        } while (graph->column_capacity < num_columns);
 
-       graph->columns = xrealloc(graph->columns,
-                                 sizeof(struct column) *
-                                 graph->column_capacity);
-       graph->new_columns = xrealloc(graph->new_columns,
-                                     sizeof(struct column) *
-                                     graph->column_capacity);
-       graph->mapping = xrealloc(graph->mapping,
-                                 sizeof(int) * 2 * graph->column_capacity);
-       graph->new_mapping = xrealloc(graph->new_mapping,
-                                     sizeof(int) * 2 * graph->column_capacity);
+       REALLOC_ARRAY(graph->columns, graph->column_capacity);
+       REALLOC_ARRAY(graph->new_columns, graph->column_capacity);
+       REALLOC_ARRAY(graph->mapping, graph->column_capacity * 2);
+       REALLOC_ARRAY(graph->new_mapping, graph->column_capacity * 2);
 }
 
 /*
diff --git a/help.c b/help.c
index 7af65e205ecdf1a01dce009cbf0ada15de68c844..2072a873e2db784ca66c0f1736b12e523a96b7db 100644 (file)
--- a/help.c
+++ b/help.c
@@ -305,7 +305,7 @@ const char *help_unknown_cmd(const char *cmd)
        add_cmd_list(&main_cmds, &aliases);
        add_cmd_list(&main_cmds, &other_cmds);
        qsort(main_cmds.names, main_cmds.cnt,
-             sizeof(main_cmds.names), cmdname_compare);
+             sizeof(*main_cmds.names), cmdname_compare);
        uniq(&main_cmds);
 
        /* This abuses cmdname->len for levenshtein distance */
diff --git a/khash.h b/khash.h
index 06c79065490f152ceed2732ba1b93c309eb4d574..376475a5eaf80585311ab518d03c229a7a49a7ed 100644 (file)
--- a/khash.h
+++ b/khash.h
@@ -121,13 +121,9 @@ static const double __ac_HASH_UPPER = 0.77;
                                if (!new_flags) return -1;                                                              \
                                memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
                                if (h->n_buckets < new_n_buckets) {     /* expand */            \
-                                       khkey_t *new_keys = (khkey_t*)xrealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
-                                       if (!new_keys) return -1;                                                       \
-                                       h->keys = new_keys;                                                                     \
+                                       REALLOC_ARRAY(h->keys, new_n_buckets); \
                                        if (kh_is_map) {                                                                        \
-                                               khval_t *new_vals = (khval_t*)xrealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
-                                               if (!new_vals) return -1;                                               \
-                                               h->vals = new_vals;                                                             \
+                                               REALLOC_ARRAY(h->vals, new_n_buckets); \
                                        }                                                                                                       \
                                } /* otherwise shrink */                                                                \
                        }                                                                                                                       \
@@ -160,8 +156,8 @@ static const double __ac_HASH_UPPER = 0.77;
                                }                                                                                                               \
                        }                                                                                                                       \
                        if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
-                               h->keys = (khkey_t*)xrealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
-                               if (kh_is_map) h->vals = (khval_t*)xrealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
+                               REALLOC_ARRAY(h->keys, new_n_buckets); \
+                               if (kh_is_map) REALLOC_ARRAY(h->vals, new_n_buckets); \
                        }                                                                                                                       \
                        free(h->flags); /* free the working space */                            \
                        h->flags = new_flags;                                                                           \
index 1008e722584c882ac86b936307ace701b9225aaf..038c58a395c6804e5f719d4d82a3d4edbd6d8901 100644 (file)
@@ -533,7 +533,7 @@ static void fill_line_ends(struct diff_filespec *spec, long *lines,
        }
 
        /* shrink the array to fit the elements */
-       ends = xrealloc(ends, cur * sizeof(*ends));
+       REALLOC_ARRAY(ends, cur);
        *lines = cur-1;
        *line_ends = ends;
 }
index bcee7c596696eb1da109b3ff375e09453045a60f..cff7ac1dbd8942f3013e6fa91d30d2ea33495854 100644 (file)
@@ -174,14 +174,16 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
 }
 
 /*
- * The caller makes sure there is no funny color before
- * calling. format_decorations makes sure the same after return.
+ * The caller makes sure there is no funny color before calling.
+ * format_decorations_extended makes sure the same after return.
  */
-void format_decorations(struct strbuf *sb,
+void format_decorations_extended(struct strbuf *sb,
                        const struct commit *commit,
-                       int use_color)
+                       int use_color,
+                       const char *prefix,
+                       const char *separator,
+                       const char *suffix)
 {
-       const char *prefix;
        const struct name_decoration *decoration;
        const char *color_commit =
                diff_get_color(use_color, DIFF_COMMIT);
@@ -191,7 +193,6 @@ void format_decorations(struct strbuf *sb,
        decoration = get_name_decoration(&commit->object);
        if (!decoration)
                return;
-       prefix = " (";
        while (decoration) {
                strbuf_addstr(sb, color_commit);
                strbuf_addstr(sb, prefix);
@@ -200,11 +201,11 @@ void format_decorations(struct strbuf *sb,
                        strbuf_addstr(sb, "tag: ");
                strbuf_addstr(sb, decoration->name);
                strbuf_addstr(sb, color_reset);
-               prefix = ", ";
+               prefix = separator;
                decoration = decoration->next;
        }
        strbuf_addstr(sb, color_commit);
-       strbuf_addch(sb, ')');
+       strbuf_addstr(sb, suffix);
        strbuf_addstr(sb, color_reset);
 }
 
index d6ecd4dc46b82147c5c7e00dcfa2e9088ab00d7c..b26160c4d64b041ed31826a61d4b898c8608c0a2 100644 (file)
@@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
 int log_tree_opt_parse(struct rev_info *, const char **, int);
 void show_log(struct rev_info *opt);
-void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color);
+void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
+                            int use_color,
+                            const char *prefix,
+                            const char *separator,
+                            const char *suffix);
+#define format_decorations(strbuf, commit, color) \
+                            format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
 void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **subject_p,
index a16b9f9e936d060ba190b6c7e82ff5f25795f490..ca9d790f4d2b0f30ff585df7a6f8edf515e40a20 100644 (file)
--- a/object.c
+++ b/object.c
@@ -33,13 +33,20 @@ const char *typename(unsigned int type)
        return object_type_strings[type];
 }
 
-int type_from_string(const char *str)
+int type_from_string_gently(const char *str, ssize_t len, int gentle)
 {
        int i;
 
+       if (len < 0)
+               len = strlen(str);
+
        for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
-               if (!strcmp(str, object_type_strings[i]))
+               if (!strncmp(str, object_type_strings[i], len))
                        return i;
+
+       if (gentle)
+               return -1;
+
        die("invalid object type \"%s\"", str);
 }
 
@@ -312,7 +319,7 @@ static void add_object_array_with_mode_context(struct object *obj, const char *n
 
        if (nr >= alloc) {
                alloc = (alloc + 32) * 2;
-               objects = xrealloc(objects, alloc * sizeof(*objects));
+               REALLOC_ARRAY(objects, alloc);
                array->alloc = alloc;
                array->objects = objects;
        }
index 5e8d8ee5485a5825c4dc0a0bba1911061723e161..e028ced74c6c50459376d778c8bb9bae1d2808c3 100644 (file)
--- a/object.h
+++ b/object.h
@@ -53,7 +53,8 @@ struct object {
 };
 
 extern const char *typename(unsigned int type);
-extern int type_from_string(const char *str);
+extern int type_from_string_gently(const char *str, ssize_t, int gentle);
+#define type_from_string(str) type_from_string_gently(str, -1, 0)
 
 /*
  * Return the current number of buckets in the object hashmap.
index 5f1791a59c5e9ecd553fb9109fa774d921f777c8..8029ae35619fbff7e9e595b20ea25c379c698016 100644 (file)
@@ -111,8 +111,7 @@ static inline void push_bitmapped_commit(struct commit *commit, struct ewah_bitm
 {
        if (writer.selected_nr >= writer.selected_alloc) {
                writer.selected_alloc = (writer.selected_alloc + 32) * 2;
-               writer.selected = xrealloc(writer.selected,
-                                          writer.selected_alloc * sizeof(struct bitmapped_commit));
+               REALLOC_ARRAY(writer.selected, writer.selected_alloc);
        }
 
        writer.selected[writer.selected_nr].commit = commit;
index 91e41015316e8d5c166cdee92c453ec23a483dab..a1f3c0d34f8958c08310aa9fc77e764885b76008 100644 (file)
@@ -400,10 +400,8 @@ static int ext_index_add_object(struct object *object, const char *name)
        if (hash_ret > 0) {
                if (eindex->count >= eindex->alloc) {
                        eindex->alloc = (eindex->alloc + 16) * 3 / 2;
-                       eindex->objects = xrealloc(eindex->objects,
-                               eindex->alloc * sizeof(struct object *));
-                       eindex->hashes = xrealloc(eindex->hashes,
-                               eindex->alloc * sizeof(uint32_t));
+                       REALLOC_ARRAY(eindex->objects, eindex->alloc);
+                       REALLOC_ARRAY(eindex->hashes, eindex->alloc);
                }
 
                bitmap_pos = eindex->count;
index 9992f3ecf249c32e5be31dc047bad46a4c4ac367..6398a8aa96f2f44c0b01cf168619f1d269bc6dbb 100644 (file)
@@ -92,8 +92,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
 
        if (pdata->nr_objects >= pdata->nr_alloc) {
                pdata->nr_alloc = (pdata->nr_alloc  + 1024) * 3 / 2;
-               pdata->objects = xrealloc(pdata->objects,
-                                         pdata->nr_alloc * sizeof(*new_entry));
+               REALLOC_ARRAY(pdata->objects, pdata->nr_alloc);
        }
 
        new_entry = pdata->objects + pdata->nr_objects++;
index 461cc14354c79da2baa0b1aa8bad0fc61812846b..a33a38e7d058823cc462e66288e6e940b5af81e5 100644 (file)
--- a/po/TEAMS
+++ b/po/TEAMS
@@ -17,6 +17,7 @@ Members:      Thomas Rast <tr@thomasrast.ch>
                Christian Stimming <stimming@tuhh.de>
                Phillip Szelat <phillip.szelat@gmail.com>
                Matthias Rüster <matthias.ruester@gmail.com>
+               Magnus Görlitz <magnus.goerlitz@googlemail.com>
 
 Language:      fr (French)
 Repository:    https://github.com/jnavila/git
index e5d2b25f448b5b9847e9bcda5285198afa40930d..c807967cfcc4da737e8f142dab262534fb240734 100644 (file)
--- a/po/de.po
+++ b/po/de.po
@@ -29,7 +29,7 @@ msgid ""
 "'git commit -a'."
 msgstr ""
 "Korrigieren Sie dies im Arbeitsverzeichnis, und benutzen Sie\n"
-"dann 'git add/rm <Datei>' um die Auflösung entsprechend zu markieren\n"
+"dann 'git add/rm <Datei>', um die Auflösung entsprechend zu markieren\n"
 "und zu committen, oder benutzen Sie 'git commit -a'."
 
 #: archive.c:10
@@ -619,7 +619,7 @@ msgstr "Fehler beim Erstellen des Pfades '%s'%s"
 #: merge-recursive.c:703
 #, c-format
 msgid "Removing %s to make room for subdirectory\n"
-msgstr "Entferne %s um Platz für Unterverzeichnis zu schaffen\n"
+msgstr "Entferne %s, um Platz für Unterverzeichnis zu schaffen\n"
 
 #: merge-recursive.c:717 merge-recursive.c:738
 msgid ": perhaps a D/F conflict?"
@@ -1037,7 +1037,7 @@ msgstr[1] "Ihr Branch ist vor '%s' um %d Commits.\n"
 
 #: remote.c:1960
 msgid "  (use \"git push\" to publish your local commits)\n"
-msgstr "  (benutzen Sie \"git push\" um lokale Commits zu publizieren)\n"
+msgstr "  (benutzen Sie \"git push\", um lokale Commits zu publizieren)\n"
 
 #: remote.c:1963
 #, c-format
@@ -1052,7 +1052,7 @@ msgstr[1] ""
 #: remote.c:1971
 msgid "  (use \"git pull\" to update your local branch)\n"
 msgstr ""
-"  (benutzen Sie \"git pull\" um Ihren lokalen Branch zu aktualisieren)\n"
+"  (benutzen Sie \"git pull\", um Ihren lokalen Branch zu aktualisieren)\n"
 
 #: remote.c:1974
 #, c-format
@@ -1072,7 +1072,7 @@ msgstr[1] ""
 #: remote.c:1984
 msgid "  (use \"git pull\" to merge the remote branch into yours)\n"
 msgstr ""
-"  (benutzen Sie \"git pull\" um Ihren Branch mit dem Remote-Branch "
+"  (benutzen Sie \"git pull\", um Ihren Branch mit dem Remote-Branch "
 "zusammenzuführen)\n"
 
 #: run-command.c:80
@@ -1136,7 +1136,7 @@ msgstr "Ihre lokalen Ã„nderungen würden von \"revert\" Ã¼berschrieben werden."
 #: sequencer.c:233
 msgid "Commit your changes or stash them to proceed."
 msgstr ""
-"Tragen Sie Ihre Ã„nderungen ein oder benutzen Sie \"stash\" um fortzufahren."
+"Tragen Sie Ihre Ã„nderungen ein oder benutzen Sie \"stash\", um fortzufahren."
 
 #: sequencer.c:250
 msgid "Failed to lock HEAD during fast_forward_to"
@@ -1488,18 +1488,18 @@ msgstr ""
 #: wt-status.c:183
 msgid "  (use \"git add <file>...\" to mark resolution)"
 msgstr ""
-"  (benutzen Sie \"git add/rm <Datei>...\" um die Auflösung zu markieren)"
+"  (benutzen Sie \"git add/rm <Datei>...\", um die Auflösung zu markieren)"
 
 #: wt-status.c:185 wt-status.c:189
 msgid "  (use \"git add/rm <file>...\" as appropriate to mark resolution)"
 msgstr ""
-"  (benutzen Sie \"git add/rm <Datei>...\" um die Auflösung entsprechend zu "
+"  (benutzen Sie \"git add/rm <Datei>...\", um die Auflösung entsprechend zu "
 "markieren)"
 
 #: wt-status.c:187
 msgid "  (use \"git rm <file>...\" to mark resolution)"
 msgstr ""
-"  (benutzen Sie \"git add/rm <Datei>...\" um die Auflösung zu markieren)"
+"  (benutzen Sie \"git add/rm <Datei>...\", um die Auflösung zu markieren)"
 
 #: wt-status.c:198
 msgid "Changes to be committed:"
@@ -1512,20 +1512,20 @@ msgstr "Änderungen, die nicht zum Commit vorgemerkt sind:"
 #: wt-status.c:220
 msgid "  (use \"git add <file>...\" to update what will be committed)"
 msgstr ""
-"  (benutzen Sie \"git add <Datei>...\" um die Ã„nderungen zum Commit "
+"  (benutzen Sie \"git add <Datei>...\", um die Ã„nderungen zum Commit "
 "vorzumerken)"
 
 #: wt-status.c:222
 msgid "  (use \"git add/rm <file>...\" to update what will be committed)"
 msgstr ""
-"  (benutzen Sie \"git add/rm <Datei>...\" um die Ã„nderungen zum Commit "
+"  (benutzen Sie \"git add/rm <Datei>...\", um die Ã„nderungen zum Commit "
 "vorzumerken)"
 
 #: wt-status.c:223
 msgid ""
 "  (use \"git checkout -- <file>...\" to discard changes in working directory)"
 msgstr ""
-"  (benutzen Sie \"git checkout -- <Datei>...\" um die Ã„nderungen im "
+"  (benutzen Sie \"git checkout -- <Datei>...\", um die Ã„nderungen im "
 "Arbeitsverzeichnis zu verwerfen)"
 
 #: wt-status.c:225
@@ -1538,7 +1538,7 @@ msgstr ""
 #, c-format
 msgid "  (use \"git %s <file>...\" to include in what will be committed)"
 msgstr ""
-"  (benutzen Sie \"git %s <Datei>...\" um die Ã„nderungen zum Commit "
+"  (benutzen Sie \"git %s <Datei>...\", um die Ã„nderungen zum Commit "
 "vorzumerken)"
 
 #: wt-status.c:252
@@ -1653,7 +1653,7 @@ msgstr "Alle Konflikte sind behoben, aber Sie sind immer noch beim Merge."
 
 #: wt-status.c:945
 msgid "  (use \"git commit\" to conclude merge)"
-msgstr "  (benutzen Sie \"git commit\" um den Merge abzuschließen)"
+msgstr "  (benutzen Sie \"git commit\", um den Merge abzuschließen)"
 
 #: wt-status.c:955
 msgid "You are in the middle of an am session."
@@ -1670,12 +1670,12 @@ msgstr ""
 
 #: wt-status.c:964
 msgid "  (use \"git am --skip\" to skip this patch)"
-msgstr "  (benutzen Sie \"git am --skip\" um diesen Patch auszulassen)"
+msgstr "  (benutzen Sie \"git am --skip\", um diesen Patch auszulassen)"
 
 #: wt-status.c:966
 msgid "  (use \"git am --abort\" to restore the original branch)"
 msgstr ""
-"  (benutzen Sie \"git am --abort\" um den ursprünglichen Branch "
+"  (benutzen Sie \"git am --abort\", um den ursprünglichen Branch "
 "wiederherzustellen)"
 
 #: wt-status.c:1026 wt-status.c:1043
@@ -1695,12 +1695,12 @@ msgstr ""
 
 #: wt-status.c:1036
 msgid "  (use \"git rebase --skip\" to skip this patch)"
-msgstr "  (benutzen Sie \"git rebase --skip\" um diesen Patch auszulassen)"
+msgstr "  (benutzen Sie \"git rebase --skip\", um diesen Patch auszulassen)"
 
 #: wt-status.c:1038
 msgid "  (use \"git rebase --abort\" to check out the original branch)"
 msgstr ""
-"  (benutzen Sie \"git rebase --abort\" um den ursprünglichen Branch "
+"  (benutzen Sie \"git rebase --abort\", um den ursprünglichen Branch "
 "auszuchecken)"
 
 #: wt-status.c:1051
@@ -1739,7 +1739,7 @@ msgstr "Sie editieren gerade einen Commit während eines Rebase."
 #: wt-status.c:1075
 msgid "  (use \"git commit --amend\" to amend the current commit)"
 msgstr ""
-"  (benutzen Sie \"git commit --amend\" um den aktuellen Commit nachzubessern)"
+"  (benutzen Sie \"git commit --amend\", um den aktuellen Commit nachzubessern)"
 
 #: wt-status.c:1077
 msgid ""
@@ -1767,7 +1767,7 @@ msgstr ""
 #: wt-status.c:1097
 msgid "  (use \"git cherry-pick --abort\" to cancel the cherry-pick operation)"
 msgstr ""
-"  (benutzen Sie \"git cherry-pick --abort\" um die Cherry-Pick-Operation "
+"  (benutzen Sie \"git cherry-pick --abort\", um die Cherry-Pick-Operation "
 "abzubrechen)"
 
 #: wt-status.c:1106
@@ -1788,7 +1788,7 @@ msgstr "  (alle Konflikte behoben: führen Sie \"git revert --continue\" aus)"
 #: wt-status.c:1116
 msgid "  (use \"git revert --abort\" to cancel the revert operation)"
 msgstr ""
-"  (benutzen Sie \"git revert --abort\" um die Revert-Operation abzubrechen)"
+"  (benutzen Sie \"git revert --abort\", um die Revert-Operation abzubrechen)"
 
 #: wt-status.c:1127
 #, c-format
@@ -1802,7 +1802,7 @@ msgstr "Sie sind gerade bei einer binären Suche."
 #: wt-status.c:1134
 msgid "  (use \"git bisect reset\" to get back to the original branch)"
 msgstr ""
-"  (benutzen Sie \"git bisect reset\" um zum ursprünglichen Branch "
+"  (benutzen Sie \"git bisect reset\", um zum ursprünglichen Branch "
 "zurückzukehren)"
 
 #: wt-status.c:1309
@@ -1855,7 +1855,7 @@ msgstr "Unbeobachtete Dateien nicht aufgelistet%s"
 
 #: wt-status.c:1373
 msgid " (use -u option to show untracked files)"
-msgstr " (benutzen Sie die Option -u um unbeobachteten Dateien anzuzeigen)"
+msgstr " (benutzen Sie die Option -u, um unbeobachteten Dateien anzuzeigen)"
 
 #: wt-status.c:1379
 msgid "No changes"
@@ -2235,7 +2235,7 @@ msgstr[1] ""
 #: builtin/apply.c:2818
 #, c-format
 msgid "Context reduced to (%ld/%ld) to apply fragment at %d"
-msgstr "Kontext reduziert zu (%ld/%ld) um Patch-Bereich bei %d anzuwenden"
+msgstr "Kontext reduziert zu (%ld/%ld), um Patch-Bereich bei %d anzuwenden"
 
 #: builtin/apply.c:2824
 #, c-format
@@ -2691,7 +2691,7 @@ msgstr "Unterdrückt den Namen des Autors und den Zeitstempel (Standard: aus)"
 
 #: builtin/blame.c:2514
 msgid "Show author email instead of name (Default: off)"
-msgstr "Zeigt anstatt des Namens die Email-Adresse des Autors (Standard: aus)"
+msgstr "Zeigt anstatt des Namens die E-Mail-Adresse des Autors (Standard: aus)"
 
 #: builtin/blame.c:2515
 msgid "Ignore whitespace differences"
@@ -3085,7 +3085,7 @@ msgstr "zu viele Branches für eine Umbenennen-Operation angegeben"
 
 #: builtin/branch.c:952
 msgid "too many branches to set new upstream"
-msgstr "zu viele Branches angegeben um Upstream-Branch zu setzen"
+msgstr "zu viele Branches angegeben, um Upstream-Branch zu setzen"
 
 #: builtin/branch.c:956
 #, c-format
@@ -3108,7 +3108,7 @@ msgstr "Branch '%s' existiert nicht"
 #: builtin/branch.c:975
 msgid "too many branches to unset upstream"
 msgstr ""
-"zu viele Branches angegeben um Konfiguration zu Upstream-Branch zu entfernen"
+"zu viele Branches angegeben, um Konfiguration zu Upstream-Branch zu entfernen"
 
 #: builtin/branch.c:979
 msgid "could not unset upstream of HEAD when it does not point to any branch."
@@ -5071,7 +5071,7 @@ msgstr "gibt für jeden Commit das gesamte Verzeichnis aus"
 
 #: builtin/fast-export.c:718
 msgid "Use the done feature to terminate the stream"
-msgstr "Benutzt die \"done\"-Funktion um den Strom abzuschließen"
+msgstr "Benutzt die \"done\"-Funktion, um den Strom abzuschließen"
 
 #: builtin/fast-export.c:719
 msgid "Skip output of blob data"
@@ -5268,7 +5268,7 @@ msgid ""
 " 'git remote prune %s' to remove any old, conflicting branches"
 msgstr ""
 "Einige lokale Referenzen konnten nicht aktualisiert werden; versuchen Sie\n"
-"'git remote prune %s' um jeden Ã¤lteren, widersprüchlichen Branch zu löschen."
+"'git remote prune %s', um jeden Ã¤lteren, widersprüchlichen Branch zu löschen."
 
 #: builtin/fetch.c:759
 #, c-format
@@ -6535,7 +6535,7 @@ msgstr "zeigt Patchformat anstatt des Standards (Patch + Zusammenfassung)"
 
 #: builtin/log.c:1217
 msgid "Messaging"
-msgstr "Email-Einstellungen"
+msgstr "E-Mail-Einstellungen"
 
 #: builtin/log.c:1218
 msgid "header"
@@ -6543,11 +6543,11 @@ msgstr "Header"
 
 #: builtin/log.c:1219
 msgid "add email header"
-msgstr "fügt Email-Header hinzu"
+msgstr "fügt E-Mail-Header hinzu"
 
 #: builtin/log.c:1220 builtin/log.c:1222
 msgid "email"
-msgstr "Email"
+msgstr "E-Mail"
 
 #: builtin/log.c:1220
 msgid "add To: header"
@@ -6573,7 +6573,7 @@ msgstr "message-id"
 
 #: builtin/log.c:1228
 msgid "make first mail a reply to <message-id>"
-msgstr "macht aus erster Email eine Antwort zu <message-id>"
+msgstr "macht aus erster E-Mail eine Antwort zu <message-id>"
 
 #: builtin/log.c:1229 builtin/log.c:1232
 msgid "boundary"
@@ -6978,7 +6978,7 @@ msgstr "konnte nicht von '%s' lesen"
 #, c-format
 msgid "Not committing merge; use 'git commit' to complete the merge.\n"
 msgstr ""
-"Merge wurde nicht committet; benutzen Sie 'git commit' um den Merge "
+"Merge wurde nicht committet; benutzen Sie 'git commit', um den Merge "
 "abzuschließen.\n"
 
 #: builtin/merge.c:809
@@ -6990,7 +6990,7 @@ msgid ""
 "Lines starting with '%c' will be ignored, and an empty message aborts\n"
 "the commit.\n"
 msgstr ""
-"Bitte geben Sie eine Commit-Beschreibung ein um zu erklären, warum dieser\n"
+"Bitte geben Sie eine Commit-Beschreibung ein, um zu erklären, warum dieser\n"
 "Merge erforderlich ist, insbesondere wenn es einen aktualisierten\n"
 "Upstream-Branch mit einem Thema-Branch zusammenführt.\n"
 "\n"
@@ -7156,7 +7156,7 @@ msgstr "Merge mit Strategie %s fehlgeschlagen.\n"
 #: builtin/merge.c:1539
 #, c-format
 msgid "Using the %s to prepare resolving by hand.\n"
-msgstr "Benutzen Sie \"%s\" um die Auflösung per Hand vorzubereiten.\n"
+msgstr "Benutzen Sie \"%s\", um die Auflösung per Hand vorzubereiten.\n"
 
 #: builtin/merge.c:1551
 #, c-format
@@ -7299,7 +7299,7 @@ msgid "Please, stage your changes to .gitmodules or stash them to proceed"
 msgstr ""
 "Bitte merken Sie Ihre Ã„nderungen in .gitmodules zum Commit vor oder "
 "benutzen\n"
-"Sie \"stash\" um fortzufahren."
+"Sie \"stash\", um fortzufahren."
 
 #: builtin/mv.c:156
 #, c-format
@@ -7368,7 +7368,7 @@ msgstr "zeigt nur Namen an (keine SHA-1)"
 
 #: builtin/name-rev.c:310
 msgid "only use tags to name the commits"
-msgstr "verwendet nur Tags um die Commits zu benennen"
+msgstr "verwendet nur Tags, um die Commits zu benennen"
 
 #: builtin/name-rev.c:312
 msgid "only use refs matching <pattern>"
@@ -7621,7 +7621,7 @@ msgid ""
 "existing notes"
 msgstr ""
 "Konnte Notizen nicht hinzufügen. Existierende Notizen für Objekt %s "
-"gefunden. Verwenden Sie '-f' um die existierenden Notizen zu Ã¼berschreiben."
+"gefunden. Verwenden Sie '-f', um die existierenden Notizen zu Ã¼berschreiben."
 
 #: builtin/notes.c:460 builtin/notes.c:537
 #, c-format
@@ -7649,7 +7649,7 @@ msgid ""
 "existing notes"
 msgstr ""
 "Kann Notizen nicht kopieren. Existierende Notizen für Objekt %s gefunden. "
-"Verwenden Sie '-f' um die existierenden Notizen zu Ã¼berschreiben."
+"Verwenden Sie '-f', um die existierenden Notizen zu Ã¼berschreiben."
 
 #: builtin/notes.c:543
 #, c-format
@@ -9359,7 +9359,7 @@ msgid ""
 "(use -f to force removal)"
 msgstr ""
 "\n"
-"(benutzen Sie -f um die Löschung zu erzwingen)"
+"(benutzen Sie -f, um die Löschung zu erzwingen)"
 
 #: builtin/rm.c:240
 msgid "the following file has changes staged in the index:"
@@ -9373,7 +9373,7 @@ msgid ""
 "(use --cached to keep the file, or -f to force removal)"
 msgstr ""
 "\n"
-"(benutzen Sie --cached um die Datei zu behalten, oder -f um die Entfernung "
+"(benutzen Sie --cached, um die Datei zu behalten, oder -f, um die Entfernung "
 "zu erzwingen)"
 
 #: builtin/rm.c:252
@@ -9431,7 +9431,7 @@ msgstr "Unterdrückt Commit-Beschreibungen, liefert nur Anzahl der Commits"
 
 #: builtin/shortlog.c:234
 msgid "Show the email address of each author"
-msgstr "Zeigt die Email-Adresse von jedem Autor"
+msgstr "Zeigt die E-Mail-Adresse von jedem Autor"
 
 #: builtin/shortlog.c:235
 msgid "w[,i1[,i2]]"
@@ -9751,7 +9751,7 @@ msgstr "annotiertes und GPG-signiertes Tag"
 
 #: builtin/tag.c:605
 msgid "use another key to sign the tag"
-msgstr "verwendet einen anderen Schlüssel um das Tag zu signieren"
+msgstr "verwendet einen anderen Schlüssel, um das Tag zu signieren"
 
 #: builtin/tag.c:606
 msgid "replace the tag if exists"
@@ -10046,7 +10046,7 @@ msgid ""
 msgstr ""
 "'git help -a' und 'git help -g' listet verfügbare Unterkommandos und\n"
 "einige Anleitungen zu Git-Konzepten auf. Benutzen Sie 'git help <Kommando>'\n"
-"oder 'git help <Konzept>' um mehr Ã¼ber ein spezifisches Kommando oder\n"
+"oder 'git help <Konzept>', um mehr Ã¼ber ein spezifisches Kommando oder\n"
 "Konzept zu erfahren."
 
 #: parse-options.h:143
@@ -10200,7 +10200,7 @@ msgstr ""
 #: git-am.sh:141
 msgid "Using index info to reconstruct a base tree..."
 msgstr ""
-"Verwende Informationen aus der Staging-Area um einen Basisverzeichnis "
+"Verwende Informationen aus der Staging-Area, um einen Basisverzeichnis "
 "nachzustellen"
 
 #: git-am.sh:156
@@ -10257,7 +10257,7 @@ msgid ""
 "Use \"git am --abort\" to remove it."
 msgstr ""
 "Stray $dotest Verzeichnis gefunden.\n"
-"Benutzen Sie \"git am --abort\" um es zu entfernen."
+"Benutzen Sie \"git am --abort\", um es zu entfernen."
 
 #: git-am.sh:535
 msgid "Resolve operation not in progress, we are not resuming."
@@ -10284,7 +10284,7 @@ msgstr ""
 
 #: git-am.sh:732
 msgid "Patch does not have a valid e-mail address."
-msgstr "Patch enthält keine gültige Email-Adresse."
+msgstr "Patch enthält keine gültige E-Mail-Adresse."
 
 #: git-am.sh:779
 msgid "cannot be interactive without stdin connected to a terminal."
@@ -10515,7 +10515,7 @@ msgid ""
 msgstr ""
 "\"pull\" ist nicht möglich, weil Sie nicht zusammengeführte Dateien haben.\n"
 "Bitte korrigieren Sie dies im Arbeitsverzeichnis und benutzen Sie dann \n"
-"'git add/rm <Datei>' um die Auflösung entsprechend zu markieren, oder\n"
+"'git add/rm <Datei>', um die Auflösung entsprechend zu markieren, oder\n"
 "benutzen Sie 'git commit -a'."
 
 #: git-pull.sh:25
@@ -11014,7 +11014,7 @@ msgid ""
 "discard them"
 msgstr ""
 "Arbeitsverzeichnis von Submodul in '$displaypath' enthält lokale Ã„nderungen; "
-"verwenden Sie '-f' um diese zu verwerfen"
+"verwenden Sie '-f', um diese zu verwerfen"
 
 #: git-submodule.sh:701
 #, sh-format
index 31f2edef1106200761aff49758545972000d9c28..5fd9de6ce11da25b8ddf8ece9f718023394624e6 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1179,6 +1179,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                load_ref_decorations(DECORATE_SHORT_REFS);
                format_decorations(sb, commit, c->auto_color);
                return 1;
+       case 'D':
+               load_ref_decorations(DECORATE_SHORT_REFS);
+               format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
+               return 1;
        case 'g':               /* reflog info */
                switch(placeholder[1]) {
                case 'd':       /* reflog selector */
diff --git a/refs.c b/refs.c
index 2ce5d690907d33bda557f66150ef1317f39b4f93..ffd45e92922ec52dccccfaecf1ceaf29f9231337 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -784,37 +784,32 @@ static void prime_ref_dir(struct ref_dir *dir)
                        prime_ref_dir(get_ref_dir(entry));
        }
 }
-/*
- * Return true iff refname1 and refname2 conflict with each other.
- * Two reference names conflict if one of them exactly matches the
- * leading components of the other; e.g., "foo/bar" conflicts with
- * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
- * "foo/barbados".
- */
-static int names_conflict(const char *refname1, const char *refname2)
+
+static int entry_matches(struct ref_entry *entry, const char *refname)
 {
-       for (; *refname1 && *refname1 == *refname2; refname1++, refname2++)
-               ;
-       return (*refname1 == '\0' && *refname2 == '/')
-               || (*refname1 == '/' && *refname2 == '\0');
+       return refname && !strcmp(entry->name, refname);
 }
 
-struct name_conflict_cb {
-       const char *refname;
-       const char *oldrefname;
-       const char *conflicting_refname;
+struct nonmatching_ref_data {
+       const char *skip;
+       struct ref_entry *found;
 };
 
-static int name_conflict_fn(struct ref_entry *entry, void *cb_data)
+static int nonmatching_ref_fn(struct ref_entry *entry, void *vdata)
 {
-       struct name_conflict_cb *data = (struct name_conflict_cb *)cb_data;
-       if (data->oldrefname && !strcmp(data->oldrefname, entry->name))
+       struct nonmatching_ref_data *data = vdata;
+
+       if (entry_matches(entry, data->skip))
                return 0;
-       if (names_conflict(data->refname, entry->name)) {
-               data->conflicting_refname = entry->name;
-               return 1;
-       }
-       return 0;
+
+       data->found = entry;
+       return 1;
+}
+
+static void report_refname_conflict(struct ref_entry *entry,
+                                   const char *refname)
+{
+       error("'%s' exists; cannot create '%s'", entry->name, refname);
 }
 
 /*
@@ -823,21 +818,84 @@ static int name_conflict_fn(struct ref_entry *entry, void *cb_data)
  * oldrefname is non-NULL, ignore potential conflicts with oldrefname
  * (e.g., because oldrefname is scheduled for deletion in the same
  * operation).
+ *
+ * Two reference names conflict if one of them exactly matches the
+ * leading components of the other; e.g., "foo/bar" conflicts with
+ * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
+ * "foo/barbados".
  */
 static int is_refname_available(const char *refname, const char *oldrefname,
                                struct ref_dir *dir)
 {
-       struct name_conflict_cb data;
-       data.refname = refname;
-       data.oldrefname = oldrefname;
-       data.conflicting_refname = NULL;
+       const char *slash;
+       size_t len;
+       int pos;
+       char *dirname;
 
-       sort_ref_dir(dir);
-       if (do_for_each_entry_in_dir(dir, 0, name_conflict_fn, &data)) {
-               error("'%s' exists; cannot create '%s'",
-                     data.conflicting_refname, refname);
+       for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
+               /*
+                * We are still at a leading dir of the refname; we are
+                * looking for a conflict with a leaf entry.
+                *
+                * If we find one, we still must make sure it is
+                * not "oldrefname".
+                */
+               pos = search_ref_dir(dir, refname, slash - refname);
+               if (pos >= 0) {
+                       struct ref_entry *entry = dir->entries[pos];
+                       if (entry_matches(entry, oldrefname))
+                               return 1;
+                       report_refname_conflict(entry, refname);
+                       return 0;
+               }
+
+
+               /*
+                * Otherwise, we can try to continue our search with
+                * the next component; if we come up empty, we know
+                * there is nothing under this whole prefix.
+                */
+               pos = search_ref_dir(dir, refname, slash + 1 - refname);
+               if (pos < 0)
+                       return 1;
+
+               dir = get_ref_dir(dir->entries[pos]);
+       }
+
+       /*
+        * We are at the leaf of our refname; we want to
+        * make sure there are no directories which match it.
+        */
+       len = strlen(refname);
+       dirname = xmallocz(len + 1);
+       sprintf(dirname, "%s/", refname);
+       pos = search_ref_dir(dir, dirname, len + 1);
+       free(dirname);
+
+       if (pos >= 0) {
+               /*
+                * We found a directory named "refname". It is a
+                * problem iff it contains any ref that is not
+                * "oldrefname".
+                */
+               struct ref_entry *entry = dir->entries[pos];
+               struct ref_dir *dir = get_ref_dir(entry);
+               struct nonmatching_ref_data data;
+
+               data.skip = oldrefname;
+               sort_ref_dir(dir);
+               if (!do_for_each_entry_in_dir(dir, 0, nonmatching_ref_fn, &data))
+                       return 1;
+
+               report_refname_conflict(data.found, refname);
                return 0;
        }
+
+       /*
+        * There is no point in searching for another leaf
+        * node which matches it; such an entry would be the
+        * ref we are looking for, not a conflict.
+        */
        return 1;
 }
 
@@ -2190,25 +2248,12 @@ struct ref_lock *lock_any_ref_for_update(const char *refname,
  * Write an entry to the packed-refs file for the specified refname.
  * If peeled is non-NULL, write it as the entry's peeled value.
  */
-static void write_packed_entry(int fd, char *refname, unsigned char *sha1,
+static void write_packed_entry(FILE *fh, char *refname, unsigned char *sha1,
                               unsigned char *peeled)
 {
-       char line[PATH_MAX + 100];
-       int len;
-
-       len = snprintf(line, sizeof(line), "%s %s\n",
-                      sha1_to_hex(sha1), refname);
-       /* this should not happen but just being defensive */
-       if (len > sizeof(line))
-               die("too long a refname '%s'", refname);
-       write_or_die(fd, line, len);
-
-       if (peeled) {
-               if (snprintf(line, sizeof(line), "^%s\n",
-                            sha1_to_hex(peeled)) != PEELED_LINE_LENGTH)
-                       die("internal error");
-               write_or_die(fd, line, PEELED_LINE_LENGTH);
-       }
+       fprintf_or_die(fh, "%s %s\n", sha1_to_hex(sha1), refname);
+       if (peeled)
+               fprintf_or_die(fh, "^%s\n", sha1_to_hex(peeled));
 }
 
 /*
@@ -2216,13 +2261,12 @@ static void write_packed_entry(int fd, char *refname, unsigned char *sha1,
  */
 static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)
 {
-       int *fd = cb_data;
        enum peel_status peel_status = peel_entry(entry, 0);
 
        if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)
                error("internal error: %s is not a valid packed reference!",
                      entry->name);
-       write_packed_entry(*fd, entry->name, entry->u.value.sha1,
+       write_packed_entry(cb_data, entry->name, entry->u.value.sha1,
                           peel_status == PEEL_PEELED ?
                           entry->u.value.peeled : NULL);
        return 0;
@@ -2258,15 +2302,22 @@ int commit_packed_refs(void)
                get_packed_ref_cache(&ref_cache);
        int error = 0;
        int save_errno = 0;
+       FILE *out;
 
        if (!packed_ref_cache->lock)
                die("internal error: packed-refs not locked");
-       write_or_die(packed_ref_cache->lock->fd,
-                    PACKED_REFS_HEADER, strlen(PACKED_REFS_HEADER));
 
+       out = fdopen(packed_ref_cache->lock->fd, "w");
+       if (!out)
+               die_errno("unable to fdopen packed-refs descriptor");
+
+       fprintf_or_die(out, "%s", PACKED_REFS_HEADER);
        do_for_each_entry_in_dir(get_packed_ref_dir(packed_ref_cache),
-                                0, write_packed_entry_fn,
-                                &packed_ref_cache->lock->fd);
+                                0, write_packed_entry_fn, out);
+       if (fclose(out))
+               die_errno("write error");
+       packed_ref_cache->lock->fd = -1;
+
        if (commit_lock_file(packed_ref_cache->lock)) {
                save_errno = errno;
                error = -1;
@@ -3108,7 +3159,7 @@ static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,
        return 1;
 }
 
-int read_ref_at(const char *refname, unsigned long at_time, int cnt,
+int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time, int cnt,
                unsigned char *sha1, char **msg,
                unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
@@ -3126,8 +3177,12 @@ int read_ref_at(const char *refname, unsigned long at_time, int cnt,
 
        for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
 
-       if (!cb.reccnt)
-               die("Log for %s is empty.", refname);
+       if (!cb.reccnt) {
+               if (flags & GET_SHA1_QUIETLY)
+                       exit(128);
+               else
+                       die("Log for %s is empty.", refname);
+       }
        if (cb.found_it)
                return 0;
 
diff --git a/refs.h b/refs.h
index 10fc3a2634409571d38a1322b9853547d216945b..2328f06e77d34d76a1f4affedcca2c51ff9e0093 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -206,7 +206,8 @@ extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, cons
 int log_ref_setup(const char *refname, char *logfile, int bufsize);
 
 /** Reads log for the value of ref during at_time. **/
-extern int read_ref_at(const char *refname, unsigned long at_time, int cnt,
+extern int read_ref_at(const char *refname, unsigned int flags,
+                      unsigned long at_time, int cnt,
                       unsigned char *sha1, char **msg,
                       unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
 
index 0d3e4171ef73f0cfb58a4f396e17717f3b0bb5a3..e498b7c3394dda23cef3719ebf1f25877d613d4e 100644 (file)
@@ -1397,7 +1397,7 @@ static void prepare_show_merge(struct rev_info *revs)
                        continue;
                if (ce_path_match(ce, &revs->prune_data, NULL)) {
                        prune_num++;
-                       prune = xrealloc(prune, sizeof(*prune) * prune_num);
+                       REALLOC_ARRAY(prune, prune_num);
                        prune[prune_num-2] = ce->name;
                        prune[prune_num-1] = NULL;
                }
index 9ec744e9f2da294a21ac02b46f0ea0b35889ae54..31f4a749fbad73b9f7bc1f1ebf9b11fd743ab374 100644 (file)
@@ -4,45 +4,80 @@
 #include "commit.h"
 #include "tag.h"
 
-/* refs */
-static FILE *info_ref_fp;
+/*
+ * Create the file "path" by writing to a temporary file and renaming
+ * it into place. The contents of the file come from "generate", which
+ * should return non-zero if it encounters an error.
+ */
+static int update_info_file(char *path, int (*generate)(FILE *))
+{
+       char *tmp = mkpathdup("%s_XXXXXX", path);
+       int ret = -1;
+       int fd = -1;
+       FILE *fp = NULL;
+
+       safe_create_leading_directories(path);
+       fd = mkstemp(tmp);
+       if (fd < 0)
+               goto out;
+       fp = fdopen(fd, "w");
+       if (!fp)
+               goto out;
+       ret = generate(fp);
+       if (ret)
+               goto out;
+       if (fclose(fp))
+               goto out;
+       if (adjust_shared_perm(tmp) < 0)
+               goto out;
+       if (rename(tmp, path) < 0)
+               goto out;
+       ret = 0;
+
+out:
+       if (ret) {
+               error("unable to update %s: %s", path, strerror(errno));
+               if (fp)
+                       fclose(fp);
+               else if (fd >= 0)
+                       close(fd);
+               unlink(tmp);
+       }
+       free(tmp);
+       return ret;
+}
 
 static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
+       FILE *fp = cb_data;
        struct object *o = parse_object(sha1);
        if (!o)
                return -1;
 
-       fprintf(info_ref_fp, "%s        %s\n", sha1_to_hex(sha1), path);
+       if (fprintf(fp, "%s     %s\n", sha1_to_hex(sha1), path) < 0)
+               return -1;
+
        if (o->type == OBJ_TAG) {
                o = deref_tag(o, path, 0);
                if (o)
-                       fprintf(info_ref_fp, "%s        %s^{}\n",
-                               sha1_to_hex(o->sha1), path);
+                       if (fprintf(fp, "%s     %s^{}\n",
+                               sha1_to_hex(o->sha1), path) < 0)
+                               return -1;
        }
        return 0;
 }
 
+static int generate_info_refs(FILE *fp)
+{
+       return for_each_ref(add_info_ref, fp);
+}
+
 static int update_info_refs(int force)
 {
-       char *path0 = git_pathdup("info/refs");
-       int len = strlen(path0);
-       char *path1 = xmalloc(len + 2);
-
-       strcpy(path1, path0);
-       strcpy(path1 + len, "+");
-
-       safe_create_leading_directories(path0);
-       info_ref_fp = fopen(path1, "w");
-       if (!info_ref_fp)
-               return error("unable to update %s", path1);
-       for_each_ref(add_info_ref, NULL);
-       fclose(info_ref_fp);
-       adjust_shared_perm(path1);
-       rename(path1, path0);
-       free(path0);
-       free(path1);
-       return 0;
+       char *path = git_pathdup("info/refs");
+       int ret = update_info_file(path, generate_info_refs);
+       free(path);
+       return ret;
 }
 
 /* packs */
@@ -198,36 +233,36 @@ static void init_pack_info(const char *infofile, int force)
                info[i]->new_num = i;
 }
 
-static void write_pack_info_file(FILE *fp)
+static void free_pack_info(void)
 {
        int i;
        for (i = 0; i < num_pack; i++)
-               fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6);
-       fputc('\n', fp);
+               free(info[i]);
+       free(info);
 }
 
-static int update_info_packs(int force)
+static int write_pack_info_file(FILE *fp)
 {
-       char infofile[PATH_MAX];
-       char name[PATH_MAX];
-       int namelen;
-       FILE *fp;
+       int i;
+       for (i = 0; i < num_pack; i++) {
+               if (fprintf(fp, "P %s\n", info[i]->p->pack_name + objdirlen + 6) < 0)
+                       return -1;
+       }
+       if (fputc('\n', fp) == EOF)
+               return -1;
+       return 0;
+}
 
-       namelen = sprintf(infofile, "%s/info/packs", get_object_directory());
-       strcpy(name, infofile);
-       strcpy(name + namelen, "+");
+static int update_info_packs(int force)
+{
+       char *infofile = mkpathdup("%s/info/packs", get_object_directory());
+       int ret;
 
        init_pack_info(infofile, force);
-
-       safe_create_leading_directories(name);
-       fp = fopen(name, "w");
-       if (!fp)
-               return error("cannot open %s", name);
-       write_pack_info_file(fp);
-       fclose(fp);
-       adjust_shared_perm(name);
-       rename(name, infofile);
-       return 0;
+       ret = update_info_file(infofile, write_pack_info_file);
+       free_pack_info();
+       free(infofile);
+       return ret;
 }
 
 /* public */
index 6dd03a974ae9a5063c40cd50e0c6e7645afca971..2842a22d7fdda33d62d617d5ba9b826ad428c17e 100644 (file)
@@ -208,11 +208,8 @@ string_list_append (string_list_ty *slp, const char *s)
   /* Grow the list.  */
   if (slp->nitems >= slp->nitems_max)
     {
-      size_t nbytes;
-
       slp->nitems_max = slp->nitems_max * 2 + 4;
-      nbytes = slp->nitems_max * sizeof (slp->item[0]);
-      slp->item = (const char **) xrealloc (slp->item, nbytes);
+      REALLOC_ARRAY(slp->item, slp->nitems_max);
     }
 
   /* Add the string to the end of the list.  */
index 7098b10e3db0caef02ae2daef8f0624e641aada4..5b004f513b999b31b7968b22dde955c859704853 100644 (file)
@@ -432,7 +432,8 @@ static inline int upstream_mark(const char *string, int len)
 static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
 
-static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
+static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
+                         unsigned int flags)
 {
        static const char *warn_msg = "refname '%.*s' is ambiguous.";
        static const char *object_name_msg = N_(
@@ -511,7 +512,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
        if (!refs_found)
                return -1;
 
-       if (warn_ambiguous_refs &&
+       if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
            (refs_found > 1 ||
             !get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY)))
                warning(warn_msg, len, str);
@@ -545,7 +546,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                                return -1;
                        }
                }
-               if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
+               if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL,
                                &co_time, &co_tz, &co_cnt)) {
                        if (!len) {
                                if (starts_with(real_ref, "refs/heads/")) {
@@ -557,11 +558,16 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                                        len = 4;
                                }
                        }
-                       if (at_time)
-                               warning("Log for '%.*s' only goes "
-                                       "back to %s.", len, str,
-                                       show_date(co_time, co_tz, DATE_RFC2822));
-                       else {
+                       if (at_time) {
+                               if (!(flags & GET_SHA1_QUIETLY)) {
+                                       warning("Log for '%.*s' only goes "
+                                               "back to %s.", len, str,
+                                               show_date(co_time, co_tz, DATE_RFC2822));
+                               }
+                       } else {
+                               if (flags & GET_SHA1_QUIETLY) {
+                                       exit(128);
+                               }
                                die("Log for '%.*s' only has %d entries.",
                                    len, str, co_cnt);
                        }
@@ -801,7 +807,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
        if (!ret)
                return 0;
 
-       ret = get_sha1_basic(name, len, sha1);
+       ret = get_sha1_basic(name, len, sha1, lookup_flags);
        if (!ret)
                return 0;
 
index de07709e3358947062984970e85005ded224baf9..57f4afa6b40585c663d0df78494ce2108611ce4b 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -392,8 +392,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
        void *p;
        if (!info->slab_count || info->free + size > info->end) {
                info->slab_count++;
-               info->slab = xrealloc(info->slab,
-                                     info->slab_count * sizeof(*info->slab));
+               REALLOC_ARRAY(info->slab, info->slab_count);
                info->free = xmalloc(COMMIT_SLAB_SIZE);
                info->slab[info->slab_count - 1] = info->free;
                info->end = info->free + COMMIT_SLAB_SIZE;
index db38b62b46fd15d849ed405f0b60cb7c72eaee40..c5aa0765e8e0a044e9e84e43280d5964f232ef63 100644 (file)
@@ -43,8 +43,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string
 
        if (list->nr + 1 >= list->alloc) {
                list->alloc += 32;
-               list->items = xrealloc(list->items, list->alloc
-                               * sizeof(struct string_list_item));
+               REALLOC_ARRAY(list->items, list->alloc);
        }
        if (index < list->nr)
                memmove(list->items + index + 1, list->items + index,
index b52397afd3352b873c9c7fabb91eb850aaf0db3b..019fddd4e81ed7b2103f916a634f3e85e7291017 100755 (executable)
@@ -214,6 +214,44 @@ test_expect_success 'tag pointing to something else than its type' '
        test_must_fail git fsck --tags
 '
 
+test_expect_success 'tag with incorrect tag name & missing tagger' '
+       sha=$(git rev-parse HEAD) &&
+       cat >wrong-tag <<-EOF &&
+       object $sha
+       type commit
+       tag wrong name format
+
+       This is an invalid tag.
+       EOF
+
+       tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+       test_when_finished "remove_object $tag" &&
+       echo $tag >.git/refs/tags/wrong &&
+       test_when_finished "git update-ref -d refs/tags/wrong" &&
+       git fsck --tags 2>out &&
+       grep "invalid .tag. name" out &&
+       grep "expected .tagger. line" out
+'
+
+test_expect_success 'tag with bad tagger' '
+       sha=$(git rev-parse HEAD) &&
+       cat >wrong-tag <<-EOF &&
+       object $sha
+       type commit
+       tag not-quite-wrong
+       tagger Bad Tagger Name
+
+       This is an invalid tag.
+       EOF
+
+       tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
+       test_when_finished "remove_object $tag" &&
+       echo $tag >.git/refs/tags/wrong &&
+       test_when_finished "git update-ref -d refs/tags/wrong" &&
+       test_must_fail git fsck --tags 2>out &&
+       grep "error in tag .*: invalid author/committer" out
+'
+
 test_expect_success 'cleaned up' '
        git fsck >actual 2>&1 &&
        test_cmp empty actual
index 813cc1b3e29ec840deb63ad9c3c1dffd2187cdc5..823fe1d79924b68950a59ffde902b16db29205b6 100755 (executable)
@@ -72,15 +72,42 @@ test_expect_success 'fails with any bad rev or many good revs' '
 
 test_expect_success 'fails silently when using -q' '
        test_must_fail git rev-parse --verify --quiet 2>error &&
-       test -z "$(cat error)" &&
+       test_must_be_empty error &&
        test_must_fail git rev-parse -q --verify foo 2>error &&
-       test -z "$(cat error)" &&
+       test_must_be_empty error &&
        test_must_fail git rev-parse --verify -q HEAD bar 2>error &&
-       test -z "$(cat error)" &&
+       test_must_be_empty error &&
        test_must_fail git rev-parse --quiet --verify baz HEAD 2>error &&
-       test -z "$(cat error)" &&
+       test_must_be_empty error &&
        test_must_fail git rev-parse -q --verify $HASH2 HEAD 2>error &&
-       test -z "$(cat error)"
+       test_must_be_empty error
+'
+
+test_expect_success 'fails silently when using -q with deleted reflogs' '
+       ref=$(git rev-parse HEAD) &&
+       : >.git/logs/refs/test &&
+       git update-ref -m "message for refs/test" refs/test "$ref" &&
+       git reflog delete --updateref --rewrite refs/test@{0} &&
+       test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 &&
+       test_must_be_empty error
+'
+
+test_expect_success 'fails silently when using -q with not enough reflogs' '
+       ref=$(git rev-parse HEAD) &&
+       : >.git/logs/refs/test2 &&
+       git update-ref -m "message for refs/test2" refs/test2 "$ref" &&
+       test_must_fail git rev-parse -q --verify refs/test2@{999} >error 2>&1 &&
+       test_must_be_empty error
+'
+
+test_expect_success 'succeeds silently with -q and reflogs that do not go far back enough in time' '
+       ref=$(git rev-parse HEAD) &&
+       : >.git/logs/refs/test3 &&
+       git update-ref -m "message for refs/test3" refs/test3 "$ref" &&
+       git rev-parse -q --verify refs/test3@{1.year.ago} >actual 2>error &&
+       test_must_be_empty error &&
+       echo "$ref" >expect &&
+       test_cmp expect actual
 '
 
 test_expect_success 'no stdout output on error' '
index 141b0611eac306616078a599a216c6050dc45389..912a6635a808cbb6ae78dec545441d363bdeb0d0 100755 (executable)
@@ -130,4 +130,33 @@ test_expect_success 'implicit --list conflicts with modification options' '
 
 '
 
+# We want to set up a case where the walk for the tracking info
+# of one branch crosses the tip of another branch (and make sure
+# that the latter walk does not mess up our flag to see if it was
+# merged).
+#
+# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
+# same tip as master The name "zzz" must come alphabetically after "topic"
+# as we process them in that order.
+test_expect_success 'branch --merged with --verbose' '
+       git branch --track topic master &&
+       git branch zzz topic &&
+       git checkout topic &&
+       test_commit foo &&
+       git branch --merged topic >actual &&
+       cat >expect <<-\EOF &&
+         master
+       * topic
+         zzz
+       EOF
+       test_cmp expect actual &&
+       git branch --verbose --merged topic >actual &&
+       cat >expect <<-\EOF &&
+         master c77a0a9 second on master
+       * topic  2c939f4 [ahead 1] foo
+         zzz    c77a0a9 second on master
+       EOF
+       test_cmp expect actual
+'
+
 test_done
index 3a017bf437395526cf54403d4ea1db36a3cff0b3..aa9eb3a3e5ef0637615c6d958a29dbd9bbbf0895 100755 (executable)
@@ -11,7 +11,9 @@ semantic is still the same.
 '
 . ./test-lib.sh
 
-echo '[core] logallrefupdates = true' >>.git/config
+test_expect_success 'enable reflogs' '
+       git config core.logallrefupdates true
+'
 
 test_expect_success \
     'prepare a trivial repository' \
@@ -158,4 +160,31 @@ test_expect_success 'pack ref directly below refs/' '
        test_path_is_missing .git/refs/top
 '
 
+test_expect_success 'disable reflogs' '
+       git config core.logallrefupdates false &&
+       rm -rf .git/logs
+'
+
+test_expect_success 'create packed foo/bar/baz branch' '
+       git branch foo/bar/baz &&
+       git pack-refs --all --prune &&
+       test_path_is_missing .git/refs/heads/foo/bar/baz &&
+       test_path_is_missing .git/logs/refs/heads/foo/bar/baz
+'
+
+test_expect_success 'notice d/f conflict with existing directory' '
+       test_must_fail git branch foo &&
+       test_must_fail git branch foo/bar
+'
+
+test_expect_success 'existing directory reports concrete ref' '
+       test_must_fail git branch foo 2>stderr &&
+       grep refs/heads/foo/bar/baz stderr
+'
+
+test_expect_success 'notice d/f conflict with existing ref' '
+       test_must_fail git branch foo/bar/baz/extra &&
+       test_must_fail git branch foo/bar/baz/lots/of/extra/components
+'
+
 test_done
index 9b75399572b1cbe1bfcb00995e1660a93fe6a4c6..7398605e7b894259548f257aaf3e92d9481534eb 100755 (executable)
@@ -465,4 +465,15 @@ EOF
        test_cmp expected actual1
 '
 
+test_expect_success 'clean log decoration' '
+       git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
+       cat >expected <<EOF &&
+$head1 tag: refs/tags/tag2
+$head2 tag: refs/tags/message-one
+$old_head1 tag: refs/tags/message-two
+EOF
+       sort actual >actual1 &&
+       test_cmp expected actual1
+'
+
 test_done
index 4bbb718751738c3e913c25160d0fff52d8350bba..61bc8da56028625fa2525cc5b067d40367f2b1c6 100755 (executable)
@@ -243,4 +243,23 @@ test_expect_success 'running index-pack in the object store' '
     test -f .git/objects/pack/pack-${pack1}.idx
 '
 
+test_expect_success 'index-pack --strict warns upon missing tagger in tag' '
+    sha=$(git rev-parse HEAD) &&
+    cat >wrong-tag <<EOF &&
+object $sha
+type commit
+tag guten tag
+
+This is an invalid tag.
+EOF
+
+    tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+    pack1=$(echo $tag $sha | git pack-objects tag-test) &&
+    echo remove tag object &&
+    thirtyeight=${tag#??} &&
+    rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&
+    git index-pack --strict tag-test-${pack1}.pack 2>err &&
+    grep "^error:.* expected .tagger. line" err
+'
+
 test_done
index 17bcb0b04096eabb29c13a025fd2afe8d1e4623b..7f278d8ce932f34420c337571ec043ffb5e318e9 100755 (executable)
@@ -135,4 +135,17 @@ test_expect_success 'send-pack stderr contains hook messages' '
        test_cmp expect actual
 '
 
+test_expect_success 'pre-receive hook that forgets to read its input' '
+       write_script victim.git/hooks/pre-receive <<-\EOF &&
+       exit 0
+       EOF
+       rm -f victim.git/hooks/update victim.git/hooks/post-update &&
+
+       for v in $(test_seq 100 999)
+       do
+               git branch branch_$v master || return
+       done &&
+       git push ./victim.git "+refs/heads/*:refs/heads/*"
+'
+
 test_done
index f8d370913a8dcfb87d62ab994b4823dc84157f8b..18a67d33cb55b799f7784e52ceac214cf76e5d3e 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -228,8 +228,8 @@ int walker_targets_stdin(char ***target, const char ***write_ref)
 
                if (targets >= targets_alloc) {
                        targets_alloc = targets_alloc ? targets_alloc * 2 : 64;
-                       *target = xrealloc(*target, targets_alloc * sizeof(**target));
-                       *write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
+                       REALLOC_ARRAY(*target, targets_alloc);
+                       REALLOC_ARRAY(*write_ref, targets_alloc);
                }
                (*target)[targets] = xstrdup(tg_one);
                (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
index b50f99a9361926d2116c85e3e90a132fb9dab742..e7afe7a295e586d58313e82e87b22de347aef7a1 100644 (file)
@@ -49,6 +49,21 @@ void maybe_flush_or_die(FILE *f, const char *desc)
        }
 }
 
+void fprintf_or_die(FILE *f, const char *fmt, ...)
+{
+       va_list ap;
+       int ret;
+
+       va_start(ap, fmt);
+       ret = vfprintf(f, fmt, ap);
+       va_end(ap);
+
+       if (ret < 0) {
+               check_pipe(errno);
+               die_errno("write error");
+       }
+}
+
 void fsync_or_die(int fd, const char *msg)
 {
        if (fsync(fd) < 0) {