]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'pb/regex' into next
authorJunio C Hamano <junkio@cox.net>
Tue, 4 Apr 2006 20:45:29 +0000 (13:45 -0700)
committerJunio C Hamano <junkio@cox.net>
Tue, 4 Apr 2006 20:45:29 +0000 (13:45 -0700)
* pb/regex:
  Support for pickaxe matching regular expressions

git-clone.sh
xdiff/xdiffi.c
xdiff/xprepare.c
xdiff/xutils.c
xdiff/xutils.h

index 823c74b9139d4a77eb5430674bf0237fb573c14c..c013e481d044b3b11155d970f785766bc4c18613 100755 (executable)
@@ -52,7 +52,8 @@ Perhaps git-update-server-info needs to be run there?"
                git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
        done <"$clone_tmp/refs"
        rm -fr "$clone_tmp"
-       http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD"
+       http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
+       rm -f "$GIT_DIR/REMOTE_HEAD"
 }
 
 # Read git-fetch-pack -k output and store the remote branches.
@@ -324,7 +325,7 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp"
 
 if test -f "$GIT_DIR/CLONE_HEAD"
 then
-       # Figure out where the remote HEAD points at.
+       # Read git-fetch-pack -k output and store the remote branches.
        perl -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin"
 fi
 
@@ -332,22 +333,25 @@ cd "$D" || exit
 
 if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
 then
-       head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
        # Figure out which remote branch HEAD points at.
        case "$use_separate_remote" in
        '')     remote_top=refs/heads ;;
        *)      remote_top="refs/remotes/$origin" ;;
        esac
 
-       # What to use to track the remote primary branch
-       if test -n "$use_separate_remote"
-       then
-               origin_tracking="remotes/$origin/master"
-       else
-               origin_tracking="heads/$origin"
-       fi
+       head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+       case "$head_sha1" in
+       'ref: refs/'*)
+               # Uh-oh, the remote told us (http transport done against
+               # new style repository with a symref HEAD).
+               # Ideally we should skip the guesswork but for now
+               # opt for minimum change.
+               head_sha1=`expr "$head_sha1" : 'ref: refs/heads/\(.*\)'`
+               head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"`
+               ;;
+       esac
 
-       # The name under $remote_top the remote HEAD seems to point at
+       # The name under $remote_top the remote HEAD seems to point at.
        head_points_at=$(
                (
                        echo "master"
@@ -368,23 +372,28 @@ then
                )
        )
 
-       # Write out remotes/$origin file.
+       # Write out remotes/$origin file, and update our "$head_points_at".
        case "$head_points_at" in
        ?*)
                mkdir -p "$GIT_DIR/remotes" &&
-               echo >"$GIT_DIR/remotes/$origin" \
-               "URL: $repo
-Pull: refs/heads/$head_points_at:refs/$origin_tracking" &&
+               git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
                case "$use_separate_remote" in
-               t) git-update-ref HEAD "$head_sha1" ;;
-               *) git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) ;;
+               t)      origin_track="$remote_top/$head_points_at"
+                       git-update-ref HEAD "$head_sha1" ;;
+               *)      origin_track="$remote_top/$origin"
+                       git-update-ref "refs/heads/$origin" "$head_sha1" ;;
                esac &&
+               echo >"$GIT_DIR/remotes/$origin" \
+               "URL: $repo
+Pull: refs/heads/$head_points_at:$origin_track" &&
                (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
                while read dotslref
                do
                        name=`expr "$dotslref" : './\(.*\)'` &&
-                       test "$head_points_at" = "$name" ||
-                       test "$origin" = "$name" ||
+                       test "$use_separate_remote" = '' && {
+                               test "$head_points_at" = "$name" ||
+                               test "$origin" = "$name"
+                       } ||
                        echo "Pull: refs/heads/${name}:$remote_top/${name}"
                done >>"$GIT_DIR/remotes/$origin" &&
                case "$use_separate_remote" in
index 8ea04837ec14b776aaa9d4a400c48072235fafa6..e81bca633ec33e75e909e14b89e805a1ac86b9ba 100644 (file)
@@ -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;
index 27a08791a2eee9f5f0565509e2c6bf2aa7b768c8..add5a75c77f1164703138a3cc781d87bd0d72b82 100644 (file)
@@ -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;
-
-       for (r = 1, rdis = 0, rpdis = 1; (i - r) >= s; r++) {
+       long r, rdis0, rpdis0, rdis1, rpdis1;
+
+       /*
+        * 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;
        }
-
-       return rpdis * XDL_KPDIS_RUN < (rpdis + rdis);
+       /*
+        * 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 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];
index afaada1edf72c8797d3d7bbd24303638accd6c24..21ab8e7e263983b54c07e44150cedc5c43963a35 100644 (file)
 
 
 
+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);
index 55b0d39f49d656576f83ccee8961ce5ea05e950e..ea38ee903fa142742797feb600b691b5a22b8165 100644 (file)
@@ -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);