From 64da3ae5c188b2b09bc1ed1eedca7e84c1aff940 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 6 Jan 2010 23:51:47 -0800 Subject: [PATCH 1/4] checkout -m: do not try to fall back to --merge from an unborn branch If switching from an unborn branch (= empty tree) to a valid commit failed without -m, it would fail with -m option as well. Signed-off-by: Junio C Hamano --- builtin-checkout.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/builtin-checkout.c b/builtin-checkout.c index c107fd643a..b76cd22776 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -272,7 +272,7 @@ static int merge_working_tree(struct checkout_opts *opts, topts.initial_checkout = is_cache_unborn(); topts.update = 1; topts.merge = 1; - topts.gently = opts->merge; + topts.gently = opts->merge && old->commit; topts.verbose_update = !opts->quiet; topts.fn = twoway_merge; topts.dir = xcalloc(1, sizeof(*topts.dir)); @@ -294,7 +294,13 @@ static int merge_working_tree(struct checkout_opts *opts, struct tree *work; if (!opts->merge) return 1; - parse_commit(old->commit); + + /* + * Without old->commit, the below is the same as + * the two-tree unpack we already tried and failed. + */ + if (!old->commit) + return 1; /* Do more real merge */ From 75b7e16b6ea49d0a0da821373ae5ee3a0ee36f2e Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Fri, 8 Jan 2010 14:39:58 +0100 Subject: [PATCH 2/4] base85 debug code: Fix length byte calculation Signed-off-by: Andreas Gruenbacher Signed-off-by: Junio C Hamano --- base85.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base85.c b/base85.c index b88270f908..7b76542531 100644 --- a/base85.c +++ b/base85.c @@ -118,7 +118,7 @@ int main(int ac, char **av) int len = strlen(av[2]); encode_85(buf, av[2], len); if (len <= 26) len = len + 'A' - 1; - else len = len + 'a' - 26 + 1; + else len = len + 'a' - 26 - 1; printf("encoded: %c%s\n", len, buf); return 0; } From b0bec518aa4a90485c411cebc7260425271af949 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Fri, 8 Jan 2010 17:22:18 +0100 Subject: [PATCH 3/4] base85: encode_85() does not use the decode table Signed-off-by: Andreas Gruenbacher Signed-off-by: Junio C Hamano --- base85.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/base85.c b/base85.c index 7b76542531..f2b9a24d5e 100644 --- a/base85.c +++ b/base85.c @@ -84,8 +84,6 @@ int decode_85(char *dst, const char *buffer, int len) void encode_85(char *buf, const unsigned char *data, int bytes) { - prep_base85(); - say("encode 85"); while (bytes) { unsigned acc = 0; From 0606c36a73449e76d8f6133253c1eff291ee8c97 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Fri, 8 Jan 2010 14:40:00 +0100 Subject: [PATCH 4/4] base85: Make the code more obvious instead of explaining the non-obvious Here is another cleanup ... Signed-off-by: Andreas Gruenbacher Signed-off-by: Junio C Hamano --- base85.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/base85.c b/base85.c index f2b9a24d5e..24ddf60eb0 100644 --- a/base85.c +++ b/base85.c @@ -57,14 +57,8 @@ int decode_85(char *dst, const char *buffer, int len) de = de85[ch]; if (--de < 0) return error("invalid base85 alphabet %c", ch); - /* - * Detect overflow. The largest - * 5-letter possible is "|NsC0" to - * encode 0xffffffff, and "|NsC" gives - * 0x03030303 at this point (i.e. - * 0xffffffff = 0x03030303 * 85). - */ - if (0x03030303 < acc || + /* Detect overflow. */ + if (0xffffffff / 85 < acc || 0xffffffff - de < (acc *= 85)) return error("invalid base85 sequence %.5s", buffer-5); acc += de;