Fossil SCM
If the diff type (unified vs. side-by-side) is not specified by a query parameter or cookie, then determine the diff type based on the "preferred-diff-type" setting, if there is one, or on a guess whether or not the requesting agent is a mobile device based on the User-Agent parameter in the HTTP request.
Commit
29bab2748bdb775fe85cf0e3f6935bc06a3f214cc6e495a2cbdac9f912673cad
Parent
722073a15719cb2…
2 files changed
+37
-6
+17
+37
-6
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -657,12 +657,11 @@ | ||
| 657 | 657 | " AND event.objid=%d", |
| 658 | 658 | rid, rid |
| 659 | 659 | ); |
| 660 | 660 | zBrName = branch_of_rid(rid); |
| 661 | 661 | |
| 662 | - cookie_link_parameter("diff","diff","2"); | |
| 663 | - diffType = atoi(PD("diff","2")); | |
| 662 | + diffType = preferred_diff_type(); | |
| 664 | 663 | if( db_step(&q1)==SQLITE_ROW ){ |
| 665 | 664 | const char *zUuid = db_column_text(&q1, 0); |
| 666 | 665 | int nUuid = db_column_bytes(&q1, 0); |
| 667 | 666 | char *zEUser, *zEComment; |
| 668 | 667 | const char *zUser; |
| @@ -1185,12 +1184,11 @@ | ||
| 1185 | 1184 | ReCompiled *pRe = 0; |
| 1186 | 1185 | login_check_credentials(); |
| 1187 | 1186 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1188 | 1187 | login_anonymous_available(); |
| 1189 | 1188 | load_control(); |
| 1190 | - cookie_link_parameter("diff","diff","2"); | |
| 1191 | - diffType = atoi(PD("diff","2")); | |
| 1189 | + diffType = preferred_diff_type(); | |
| 1192 | 1190 | cookie_render(); |
| 1193 | 1191 | zRe = P("regex"); |
| 1194 | 1192 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1195 | 1193 | zBranch = P("branch"); |
| 1196 | 1194 | if( zBranch && zBranch[0]==0 ) zBranch = 0; |
| @@ -1634,10 +1632,44 @@ | ||
| 1634 | 1632 | tag_private_status(rid); |
| 1635 | 1633 | } |
| 1636 | 1634 | return objType; |
| 1637 | 1635 | } |
| 1638 | 1636 | |
| 1637 | +/* | |
| 1638 | +** SETTING: preferred-diff-type width=16 default=0 | |
| 1639 | +** | |
| 1640 | +** Determines the preferred diff format on web pages if the format is not | |
| 1641 | +** otherwise specified, for example by a query parameter or cookie. | |
| 1642 | +** The value may be 1 to mean unified diff, or 2 to mean side-by-side | |
| 1643 | +** diff. | |
| 1644 | +*/ | |
| 1645 | +/* | |
| 1646 | +** Return the preferred diff type. | |
| 1647 | +** | |
| 1648 | +** 0 = No diff at all. | |
| 1649 | +** 1 = unified diff | |
| 1650 | +** 2 = side-by-side diff | |
| 1651 | +** | |
| 1652 | +** To determine the preferred diff type, the following values are | |
| 1653 | +** consulted in the order shown. The first available source wins. | |
| 1654 | +** | |
| 1655 | +** * The "diff" query parameter | |
| 1656 | +** * The "diff" field of the user display cookie | |
| 1657 | +** * The "preferred-diff-type" setting | |
| 1658 | +** * 1 for mobile and 2 for desktop, based on the UserAgent | |
| 1659 | +*/ | |
| 1660 | +int preferred_diff_type(void){ | |
| 1661 | + int dflt; | |
| 1662 | + char zDflt[2]; | |
| 1663 | + dflt = db_get_int("preferred-diff-type",-99); | |
| 1664 | + if( dflt<=0 ) dflt = user_agent_is_likely_mobile() ? 1 : 2; | |
| 1665 | + zDflt[0] = dflt + '0'; | |
| 1666 | + zDflt[1] = 0; | |
| 1667 | + cookie_link_parameter("diff","diff", zDflt); | |
| 1668 | + return atoi(PD("diff",zDflt)); | |
| 1669 | +} | |
| 1670 | + | |
| 1639 | 1671 | |
| 1640 | 1672 | /* |
| 1641 | 1673 | ** WEBPAGE: fdiff |
| 1642 | 1674 | ** URL: fdiff?v1=HASH&v2=HASH |
| 1643 | 1675 | ** |
| @@ -1673,12 +1705,11 @@ | ||
| 1673 | 1705 | u32 objdescFlags = 0; |
| 1674 | 1706 | int verbose = PB("verbose"); |
| 1675 | 1707 | |
| 1676 | 1708 | login_check_credentials(); |
| 1677 | 1709 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1678 | - cookie_link_parameter("diff","diff","2"); | |
| 1679 | - diffType = atoi(PD("diff","2")); | |
| 1710 | + diffType = preferred_diff_type(); | |
| 1680 | 1711 | cookie_render(); |
| 1681 | 1712 | if( P("from") && P("to") ){ |
| 1682 | 1713 | v1 = artifact_from_ci_and_filename("from"); |
| 1683 | 1714 | v2 = artifact_from_ci_and_filename("to"); |
| 1684 | 1715 | }else{ |
| 1685 | 1716 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -657,12 +657,11 @@ | |
| 657 | " AND event.objid=%d", |
| 658 | rid, rid |
| 659 | ); |
| 660 | zBrName = branch_of_rid(rid); |
| 661 | |
| 662 | cookie_link_parameter("diff","diff","2"); |
| 663 | diffType = atoi(PD("diff","2")); |
| 664 | if( db_step(&q1)==SQLITE_ROW ){ |
| 665 | const char *zUuid = db_column_text(&q1, 0); |
| 666 | int nUuid = db_column_bytes(&q1, 0); |
| 667 | char *zEUser, *zEComment; |
| 668 | const char *zUser; |
| @@ -1185,12 +1184,11 @@ | |
| 1185 | ReCompiled *pRe = 0; |
| 1186 | login_check_credentials(); |
| 1187 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1188 | login_anonymous_available(); |
| 1189 | load_control(); |
| 1190 | cookie_link_parameter("diff","diff","2"); |
| 1191 | diffType = atoi(PD("diff","2")); |
| 1192 | cookie_render(); |
| 1193 | zRe = P("regex"); |
| 1194 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1195 | zBranch = P("branch"); |
| 1196 | if( zBranch && zBranch[0]==0 ) zBranch = 0; |
| @@ -1634,10 +1632,44 @@ | |
| 1634 | tag_private_status(rid); |
| 1635 | } |
| 1636 | return objType; |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | /* |
| 1641 | ** WEBPAGE: fdiff |
| 1642 | ** URL: fdiff?v1=HASH&v2=HASH |
| 1643 | ** |
| @@ -1673,12 +1705,11 @@ | |
| 1673 | u32 objdescFlags = 0; |
| 1674 | int verbose = PB("verbose"); |
| 1675 | |
| 1676 | login_check_credentials(); |
| 1677 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1678 | cookie_link_parameter("diff","diff","2"); |
| 1679 | diffType = atoi(PD("diff","2")); |
| 1680 | cookie_render(); |
| 1681 | if( P("from") && P("to") ){ |
| 1682 | v1 = artifact_from_ci_and_filename("from"); |
| 1683 | v2 = artifact_from_ci_and_filename("to"); |
| 1684 | }else{ |
| 1685 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -657,12 +657,11 @@ | |
| 657 | " AND event.objid=%d", |
| 658 | rid, rid |
| 659 | ); |
| 660 | zBrName = branch_of_rid(rid); |
| 661 | |
| 662 | diffType = preferred_diff_type(); |
| 663 | if( db_step(&q1)==SQLITE_ROW ){ |
| 664 | const char *zUuid = db_column_text(&q1, 0); |
| 665 | int nUuid = db_column_bytes(&q1, 0); |
| 666 | char *zEUser, *zEComment; |
| 667 | const char *zUser; |
| @@ -1185,12 +1184,11 @@ | |
| 1184 | ReCompiled *pRe = 0; |
| 1185 | login_check_credentials(); |
| 1186 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1187 | login_anonymous_available(); |
| 1188 | load_control(); |
| 1189 | diffType = preferred_diff_type(); |
| 1190 | cookie_render(); |
| 1191 | zRe = P("regex"); |
| 1192 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1193 | zBranch = P("branch"); |
| 1194 | if( zBranch && zBranch[0]==0 ) zBranch = 0; |
| @@ -1634,10 +1632,44 @@ | |
| 1632 | tag_private_status(rid); |
| 1633 | } |
| 1634 | return objType; |
| 1635 | } |
| 1636 | |
| 1637 | /* |
| 1638 | ** SETTING: preferred-diff-type width=16 default=0 |
| 1639 | ** |
| 1640 | ** Determines the preferred diff format on web pages if the format is not |
| 1641 | ** otherwise specified, for example by a query parameter or cookie. |
| 1642 | ** The value may be 1 to mean unified diff, or 2 to mean side-by-side |
| 1643 | ** diff. |
| 1644 | */ |
| 1645 | /* |
| 1646 | ** Return the preferred diff type. |
| 1647 | ** |
| 1648 | ** 0 = No diff at all. |
| 1649 | ** 1 = unified diff |
| 1650 | ** 2 = side-by-side diff |
| 1651 | ** |
| 1652 | ** To determine the preferred diff type, the following values are |
| 1653 | ** consulted in the order shown. The first available source wins. |
| 1654 | ** |
| 1655 | ** * The "diff" query parameter |
| 1656 | ** * The "diff" field of the user display cookie |
| 1657 | ** * The "preferred-diff-type" setting |
| 1658 | ** * 1 for mobile and 2 for desktop, based on the UserAgent |
| 1659 | */ |
| 1660 | int preferred_diff_type(void){ |
| 1661 | int dflt; |
| 1662 | char zDflt[2]; |
| 1663 | dflt = db_get_int("preferred-diff-type",-99); |
| 1664 | if( dflt<=0 ) dflt = user_agent_is_likely_mobile() ? 1 : 2; |
| 1665 | zDflt[0] = dflt + '0'; |
| 1666 | zDflt[1] = 0; |
| 1667 | cookie_link_parameter("diff","diff", zDflt); |
| 1668 | return atoi(PD("diff",zDflt)); |
| 1669 | } |
| 1670 | |
| 1671 | |
| 1672 | /* |
| 1673 | ** WEBPAGE: fdiff |
| 1674 | ** URL: fdiff?v1=HASH&v2=HASH |
| 1675 | ** |
| @@ -1673,12 +1705,11 @@ | |
| 1705 | u32 objdescFlags = 0; |
| 1706 | int verbose = PB("verbose"); |
| 1707 | |
| 1708 | login_check_credentials(); |
| 1709 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1710 | diffType = preferred_diff_type(); |
| 1711 | cookie_render(); |
| 1712 | if( P("from") && P("to") ){ |
| 1713 | v1 = artifact_from_ci_and_filename("from"); |
| 1714 | v2 = artifact_from_ci_and_filename("to"); |
| 1715 | }else{ |
| 1716 |
+17
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -426,10 +426,27 @@ | ||
| 426 | 426 | if( strncmp(zAgent, "Safari/", 7)==0 ) return 1; |
| 427 | 427 | if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1; |
| 428 | 428 | if( strncmp(zAgent, "NetSurf/", 8)==0 ) return 1; |
| 429 | 429 | return 0; |
| 430 | 430 | } |
| 431 | + | |
| 432 | +/* | |
| 433 | +** Make a guess at whether or not the requestor is a mobile device or | |
| 434 | +** a desktop device (narrow screen vs. wide screen) based the HTTP_USER_AGENT | |
| 435 | +** parameter. Return true for mobile and false for desktop. | |
| 436 | +** | |
| 437 | +** Caution: This is only a guess. | |
| 438 | +*/ | |
| 439 | +int user_agent_is_likely_mobile(void){ | |
| 440 | + const char *zAgent = P("HTTP_USER_AGENT"); | |
| 441 | + if( zAgent==0 ) return 0; | |
| 442 | + if( sqlite3_strglob("*droid*", zAgent)==0 ) return 1; | |
| 443 | + if( sqlite3_strglob("*mobile*", zAgent)==0 ) return 1; | |
| 444 | + if( sqlite3_strglob("*iOS*", zAgent)==0 ) return 1; | |
| 445 | + if( sqlite3_strglob("*iPhone*", zAgent)==0 ) return 1; | |
| 446 | + return 0; | |
| 447 | +} | |
| 431 | 448 | |
| 432 | 449 | /* |
| 433 | 450 | ** COMMAND: test-ishuman |
| 434 | 451 | ** |
| 435 | 452 | ** Read lines of text from standard input. Interpret each line of text |
| 436 | 453 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -426,10 +426,27 @@ | |
| 426 | if( strncmp(zAgent, "Safari/", 7)==0 ) return 1; |
| 427 | if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1; |
| 428 | if( strncmp(zAgent, "NetSurf/", 8)==0 ) return 1; |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | ** COMMAND: test-ishuman |
| 434 | ** |
| 435 | ** Read lines of text from standard input. Interpret each line of text |
| 436 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -426,10 +426,27 @@ | |
| 426 | if( strncmp(zAgent, "Safari/", 7)==0 ) return 1; |
| 427 | if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1; |
| 428 | if( strncmp(zAgent, "NetSurf/", 8)==0 ) return 1; |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | ** Make a guess at whether or not the requestor is a mobile device or |
| 434 | ** a desktop device (narrow screen vs. wide screen) based the HTTP_USER_AGENT |
| 435 | ** parameter. Return true for mobile and false for desktop. |
| 436 | ** |
| 437 | ** Caution: This is only a guess. |
| 438 | */ |
| 439 | int user_agent_is_likely_mobile(void){ |
| 440 | const char *zAgent = P("HTTP_USER_AGENT"); |
| 441 | if( zAgent==0 ) return 0; |
| 442 | if( sqlite3_strglob("*droid*", zAgent)==0 ) return 1; |
| 443 | if( sqlite3_strglob("*mobile*", zAgent)==0 ) return 1; |
| 444 | if( sqlite3_strglob("*iOS*", zAgent)==0 ) return 1; |
| 445 | if( sqlite3_strglob("*iPhone*", zAgent)==0 ) return 1; |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | ** COMMAND: test-ishuman |
| 451 | ** |
| 452 | ** Read lines of text from standard input. Interpret each line of text |
| 453 |