From 5941a9e9d882b12dcc2a80e55acb25c180475529 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 Apr 2006 15:18:48 -0700 Subject: [PATCH 1/4] contrib/git-svn: ensure repo-config returns a value before using it fetching from repos without an authors-file defined was broken. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index edfb19c39e..e7fff46d22 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -77,10 +77,13 @@ $arg .= ' --bool' if ($o !~ /=[sfi]$/); $arg .= " svn.$key"; # $key only matches [a-z\-], always shell-safe if (ref $v eq 'ARRAY') { - chomp(@$v = `$arg`); + chomp(my @tmp = `$arg`); + @$v = @tmp if @tmp; } else { - chomp($$v = `$arg`); - $$v = 0 if $$v eq 'false'; + chomp(my $tmp = `$arg`); + if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) { + $$v = $tmp; + } } } From 5f2f4240022418e9a75505f11298db54a5da12d2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 Apr 2006 15:18:49 -0700 Subject: [PATCH 2/4] contrib/git-svn: make sure our git-svn is up-to-date for test Bugs like the last one could've been avoided if it weren't for this... Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/git-svn/Makefile b/contrib/git-svn/Makefile index d7f1643bf7..acedf7305e 100644 --- a/contrib/git-svn/Makefile +++ b/contrib/git-svn/Makefile @@ -28,7 +28,7 @@ git-svn.xml : git-svn.txt git-svn.html : git-svn.txt asciidoc -b xhtml11 -d manpage \ -f ../../Documentation/asciidoc.conf $< -test: +test: git-svn cd t && $(SHELL) ./t0000-contrib-git-svn.sh clean: From fc9957b0052df6a8248420395bc9febd66194252 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 Apr 2006 17:41:44 -0700 Subject: [PATCH 3/4] contrib/git-svn: handle array values correctly Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index e7fff46d22..7c44450d72 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -75,12 +75,11 @@ my $arg = 'git-repo-config'; $arg .= ' --int' if ($o =~ /=i$/); $arg .= ' --bool' if ($o !~ /=[sfi]$/); - $arg .= " svn.$key"; # $key only matches [a-z\-], always shell-safe if (ref $v eq 'ARRAY') { - chomp(my @tmp = `$arg`); + chomp(my @tmp = `$arg --get-all svn.$key`); @$v = @tmp if @tmp; } else { - chomp(my $tmp = `$arg`); + chomp(my $tmp = `$arg --get svn.$key`); if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) { $$v = $tmp; } From ca557afff9f7dad7a8739cd193ac0730d872e282 Mon Sep 17 00:00:00 2001 From: Davide Libenzi Date: Mon, 3 Apr 2006 18:47:55 -0700 Subject: [PATCH 4/4] Clean-up trivially redundant diff. Also corrects the line numbers in unified output when using zero lines context. --- xdiff/xdiffi.c | 7 +----- xdiff/xprepare.c | 59 ++++++++++++++++++++++++++++++++++++------------ xdiff/xutils.c | 17 ++++++++++++-- xdiff/xutils.h | 1 + 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 8ea04837ec..e81bca633e 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -349,12 +349,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, kvdf += xe->xdf2.nreff + 1; kvdb += xe->xdf2.nreff + 1; - /* - * Classical integer square root approximation using shifts. - */ - xenv.mxcost = 1; - for (; ndiags; ndiags >>= 2) - xenv.mxcost <<= 1; + xenv.mxcost = xdl_bogosqrt(ndiags); if (xenv.mxcost < XDL_MAX_COST_MIN) xenv.mxcost = XDL_MAX_COST_MIN; xenv.snake_cnt = XDL_SNAKE_CNT; diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c index 27a08791a2..add5a75c77 100644 --- a/xdiff/xprepare.c +++ b/xdiff/xprepare.c @@ -25,6 +25,7 @@ #define XDL_KPDIS_RUN 4 +#define XDL_MAX_EQLIMIT 1024 @@ -305,26 +306,48 @@ void xdl_free_env(xdfenv_t *xe) { static int xdl_clean_mmatch(char const *dis, long i, long s, long e) { - long r, rdis, rpdis; + long r, rdis0, rpdis0, rdis1, rpdis1; - for (r = 1, rdis = 0, rpdis = 1; (i - r) >= s; r++) { + /* + * Scans the lines before 'i' to find a run of lines that either + * have no match (dis[j] == 0) or have multiple matches (dis[j] > 1). + * Note that we always call this function with dis[i] > 1, so the + * current line (i) is already a multimatch line. + */ + for (r = 1, rdis0 = 0, rpdis0 = 1; (i - r) >= s; r++) { if (!dis[i - r]) - rdis++; + rdis0++; else if (dis[i - r] == 2) - rpdis++; + rpdis0++; else break; } - for (r = 1; (i + r) <= e; r++) { + /* + * If the run before the line 'i' found only multimatch lines, we + * return 0 and hence we don't make the current line (i) discarded. + * We want to discard multimatch lines only when they appear in the + * middle of runs with nomatch lines (dis[j] == 0). + */ + if (rdis0 == 0) + return 0; + for (r = 1, rdis1 = 0, rpdis1 = 1; (i + r) <= e; r++) { if (!dis[i + r]) - rdis++; + rdis1++; else if (dis[i + r] == 2) - rpdis++; + rpdis1++; else break; } + /* + * If the run after the line 'i' found only multimatch lines, we + * return 0 and hence we don't make the current line (i) discarded. + */ + if (rdis1 == 0) + return 0; + rdis1 += rdis0; + rpdis1 += rpdis0; - return rpdis * XDL_KPDIS_RUN < (rpdis + rdis); + return rpdis1 * XDL_KPDIS_RUN < (rpdis1 + rdis1); } @@ -334,34 +357,40 @@ static int xdl_clean_mmatch(char const *dis, long i, long s, long e) { * might be potentially discarded if they happear in a run of discardable. */ static int xdl_cleanup_records(xdfile_t *xdf1, xdfile_t *xdf2) { - long i, rhi, nreff; + long i, nm, rhi, nreff, mlim; unsigned long hav; xrecord_t **recs; xrecord_t *rec; char *dis, *dis1, *dis2; - if (!(dis = (char *) xdl_malloc((xdf1->nrec + xdf2->nrec + 2) * sizeof(char)))) { + if (!(dis = (char *) xdl_malloc(xdf1->nrec + xdf2->nrec + 2))) { return -1; } - memset(dis, 0, (xdf1->nrec + xdf2->nrec + 2) * sizeof(char)); + memset(dis, 0, xdf1->nrec + xdf2->nrec + 2); dis1 = dis; dis2 = dis1 + xdf1->nrec + 1; + if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT) + mlim = XDL_MAX_EQLIMIT; for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) { hav = (*recs)->ha; rhi = (long) XDL_HASHLONG(hav, xdf2->hbits); - for (rec = xdf2->rhash[rhi]; rec; rec = rec->next) - if (rec->ha == hav && ++dis1[i] == 2) + for (nm = 0, rec = xdf2->rhash[rhi]; rec; rec = rec->next) + if (rec->ha == hav && ++nm == mlim) break; + dis1[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1; } + if ((mlim = xdl_bogosqrt(xdf2->nrec)) > XDL_MAX_EQLIMIT) + mlim = XDL_MAX_EQLIMIT; for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) { hav = (*recs)->ha; rhi = (long) XDL_HASHLONG(hav, xdf1->hbits); - for (rec = xdf1->rhash[rhi]; rec; rec = rec->next) - if (rec->ha == hav && ++dis2[i] == 2) + for (nm = 0, rec = xdf1->rhash[rhi]; rec; rec = rec->next) + if (rec->ha == hav && ++nm == mlim) break; + dis2[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1; } for (nreff = 0, i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; diff --git a/xdiff/xutils.c b/xdiff/xutils.c index afaada1edf..21ab8e7e26 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -29,6 +29,19 @@ +long xdl_bogosqrt(long n) { + long i; + + /* + * Classical integer square root approximation using shifts. + */ + for (i = 1; n > 0; n >>= 2) + i <<= 1; + + return i; +} + + int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, xdemitcb_t *ecb) { mmbuffer_t mb[3]; @@ -244,7 +257,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, memcpy(buf, "@@ -", 4); nb += 4; - nb += xdl_num_out(buf + nb, c1 ? s1: 0); + nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1); if (c1 != 1) { memcpy(buf + nb, ",", 1); @@ -256,7 +269,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, memcpy(buf + nb, " +", 2); nb += 2; - nb += xdl_num_out(buf + nb, c2 ? s2: 0); + nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1); if (c2 != 1) { memcpy(buf + nb, ",", 1); diff --git a/xdiff/xutils.h b/xdiff/xutils.h index 55b0d39f49..ea38ee903f 100644 --- a/xdiff/xutils.h +++ b/xdiff/xutils.h @@ -24,6 +24,7 @@ #define XUTILS_H +long xdl_bogosqrt(long n); int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, xdemitcb_t *ecb); int xdl_cha_init(chastore_t *cha, long isize, long icount);