Fossil

Check-in [ae6f2700]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use function more specific to detecting collisions to catch events, tickets and other types in blob.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | short-uuid
Files: files | file ages | folders
SHA1:ae6f27004b4210dc6cb60fae806efa11acebccac
User & Date: andybradford 2014-04-08 04:32:39
Context
2014-04-08
04:34
This function also is no longer needed at this point. check-in: 8b9b4451 user: andybradford tags: short-uuid
04:32
Use function more specific to detecting collisions to catch events, tickets and other types in blob. check-in: ae6f2700 user: andybradford tags: short-uuid
2014-04-06
04:51
Show short UUID collisions also for tickets and not just ticket changes. Reported on ML. check-in: 0066d6c6 user: andybradford tags: short-uuid
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/info.c.

1888
1889
1890
1891
1892
1893
1894

1895
1896
1897

1898





1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920









1921
1922
1923
1924
1925
1926
1927
** Figure out what the artifact ID is and jump to it.
*/
void info_page(void){
  const char *zName;
  Blob uuid;
  int rid;
  int rc;


  zName = P("name");
  if( zName==0 ) fossil_redirect_home();

  blob_set(&uuid, zName);





  rc = name_to_uuid3(&uuid, -1, "*");
  if( rc==1 ){
    if( validate16(zName, strlen(zName)) &&
        db_exists("SELECT 1 FROM tag"
                  " WHERE tagname GLOB 'event-%q*'", zName) ){
      event_page();
      return;
    }else{
      style_header("No Such Object");
      @ <p>No such object: %h(zName)</p>
      style_footer();
      return;
    }
  }else if( rc==2 ){
    cgi_set_parameter("src","info");
    ambiguous_page();
    return;
  }else if( rc==3 && validate16(zName, strlen(zName)) ){
    if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
      tktview_page();
      return;
    }









  }
  zName = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zName);
  if( rid==0 ){
    style_header("Broken Link");
    @ <p>No such object: %h(zName)</p>
    style_footer();







>



>

>
>
>
>
>
|

|
|



<
<
<
<
<
|
<
<
<
<
<




>
>
>
>
>
>
>
>
>







1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912





1913





1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
** Figure out what the artifact ID is and jump to it.
*/
void info_page(void){
  const char *zName;
  Blob uuid;
  int rid;
  int rc;
  int nLen;

  zName = P("name");
  if( zName==0 ) fossil_redirect_home();
  nLen = strlen(zName);
  blob_set(&uuid, zName);
  if( name_collisions(zName) ){
    cgi_set_parameter("src","info");
    ambiguous_page();
    return;
  }
  rc = name_to_uuid(&uuid, -1, "*");
  if( rc==1 ){
    if( validate16(zName, nLen) ){
      if( db_exists("SELECT 1 FROM tag"
                    " WHERE tagname GLOB 'event-%q*'", zName) ){
        event_page();
        return;





      }





      if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
        tktview_page();
        return;
      }
    }
    style_header("No Such Object");
    @ <p>No such object of length %d(nLen): %h(zName)</p>
    style_footer();
    return;
  }else if( rc==2 ){
    cgi_set_parameter("src","info");
    ambiguous_page();
    return;
  }
  zName = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zName);
  if( rid==0 ){
    style_header("Broken Link");
    @ <p>No such object: %h(zName)</p>
    style_footer();

Changes to src/name.c.

335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369


370
371
372
373
374
375
376
int name_to_uuid2(char const *zName, const char *zType, char **pUuid){
  int rid = symbolic_name_to_rid(zName, zType);
  if((rid>0) && pUuid){
    *pUuid = db_text(NULL, "SELECT uuid FROM blob WHERE rid=%d", rid);
  }
  return rid;
}

/*
** This routine is similar to name_to_uuid() except it also accounts for
** collisions in tickets which don't have an entry in blob (only associated
** ticket changes).
** Return 0 if rid is found.  Return 1 if neither rid nor tkt_id is found.
** Return 2 if name is ambiguous.  Return 3 if tkt_id is found.
*/
int name_to_uuid3(Blob *pName, int iErrPriority, const char *zType){
  char *zName = blob_str(pName);
  int tkt_id = 0;
  int rid = symbolic_name_to_rid(zName, zType);
  if( zType && zType[0]=='*' ){
    tkt_id = symbolic_name_to_tktid(zName);
  }
  if( rid<0 || tkt_id<0 || (rid>0 && tkt_id>0) ){
    fossil_error(iErrPriority, "ambiguous name: %s", zName);
    return 2;
  }else if( rid==0 && tkt_id==0 ){
    fossil_error(iErrPriority, "not found: %s", zName);
    return 1;
  }else if( tkt_id>0 ){
    return 3;
  }else{
    blob_reset(pName);
    db_blob(pName, "SELECT uuid FROM blob WHERE rid=%d", rid);
    return 0;
  }


}

/*
** COMMAND:  test-name-to-id
**
** Convert a name to a full artifact ID.
*/







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
int name_to_uuid2(char const *zName, const char *zType, char **pUuid){
  int rid = symbolic_name_to_rid(zName, zType);
  if((rid>0) && pUuid){
    *pUuid = db_text(NULL, "SELECT uuid FROM blob WHERE rid=%d", rid);
  }
  return rid;
}


/*
** name_collisions searches through events, blobs, and tickets for
** collisions of a given UUID based on its length on UUIDs no shorter
** than 4 characters in length.
*/
int name_collisions(const char *zName){
  Stmt q;
  int c = 0;         /* count of collisions for zName */
  int nLen;          /* length of zName */
  nLen = strlen(zName);
  if( nLen>=4 && nLen<=UUID_SIZE && validate16(zName, nLen) ){
    db_prepare(&q,
      "SELECT count(uuid) FROM"
      "  (SELECT substr(tkt_uuid, 1, %d) AS uuid FROM ticket"
      "   UNION ALL SELECT * FROM"
      "     (SELECT substr(tagname, 7, %d) FROM"
      "       tag WHERE tagname GLOB 'event-*')"
      "   UNION ALL SELECT * FROM"
      "     (SELECT substr(uuid, 1, %d) FROM blob))"
      "  WHERE uuid GLOB '%q*'"
      "  GROUP BY uuid HAVING count(uuid) > 1;",
      nLen, nLen, nLen, zName);
    if( db_step(&q)==SQLITE_ROW ){
      c = db_column_int(&q, 0);
    }
    db_finalize(&q);
  }
  return c;
}

/*
** COMMAND:  test-name-to-id
**
** Convert a name to a full artifact ID.
*/