CVSTrac Legacy Code

Check-in [8c8238f05e]
Login

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

Overview
Comment:*: Download tarball is now directory browse action, rather than separate link *: Tarball now contains version and subdirectory only if necessary *: Determines modification date using filechng table *: Subversion now fixed for UNIX environment, also supports pure =tar=, =tar.gz= and =tar.bz2= *: GIT implementation using =git archive=
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8c8238f05e6069ab31faffa3dcd7804eabb19601
User & Date: ono 2009-05-15 12:32:47
Context
2009-05-15
13:55
(#797) make sure we get latest change date relative to specified directory check-in: 1bdc8232d2 user: ono tags: trunk
12:32
*: Download tarball is now directory browse action, rather than separate link *: Tarball now contains version and subdirectory only if necessary *: Determines modification date using filechng table *: Subversion now fixed for UNIX environment, also supports pure =tar=, =tar.gz= and =tar.bz2= *: GIT implementation using =git archive= check-in: 8c8238f05e user: ono tags: trunk
2009-05-14
12:25
(#799) properly escape %%. check-in: dab276db97 user: ono tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to browse.c.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
452
453
454
455
456
457
458



459
460
461
462
463
464
465
...
718
719
720
721
722
723
724



725
726
727
728
729
730
731
...
974
975
976
977
978
979
980
981
982
983
984
985
986
987

988
989
990
991

992















993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012



1013
1014
1015
1016
1017
1018
1019
*/
static void output_breadcrumb(const char *zPath, int isdir){
  if( zPath && zPath[0] ){
    const char* zDef = default_browse_url();
    char *zDirUrl;
    char *zDirName;
    int i;
    if( isdir && g.scm.pxDownload ){
      @ <a class="download" href="download?d=%T(zPath)">Download</a>
    }
    @ <ul id="breadcrumb">
    @ <li><a class="root" href="%T(zDef)">/</a></li>

    zDirUrl = mprintf("%s", zPath);
    zDirName = zDirUrl;
    for(i=0; zDirUrl[i]; i++){
      if( zDirUrl[i]=='/' ){
................................................................................
    */
    common_add_action_item("dir", "Top");
    common_add_action_item(mprintf("dir?d=%T",zDir), "Up");
    common_add_action_item(mprintf("dirview?d=%T&sc=1",zName), "Long");
  }else{
    common_add_action_item("dirview?sc=1","Long");
  }



  az = db_query("SELECT base, isdir FROM file WHERE dir='%q' ORDER BY base",
                 zName);
  for(n=0; az[n*2]; n++){}
  if( zName[0] ) n++;
  nRow = (n+3)/4;
  if( zName[0] ){ zName = mprintf("%s/",zName); }
  common_header("Directory /%h", zName);
................................................................................
      mprintf("dirview%s%s",(zSortUrl[0])?"?":"",zSortUrl), "Top");
    common_add_action_item(
      mprintf("dirview?d=%T%s%s",zDir,(zSortUrl[0])?"&":"",zSortUrl), "Up");
    common_add_action_item(mprintf("dir?d=%T&sc=1",zName), "Short");
  }else{
    common_add_action_item("dir?sc=1", "Short");
  }



  common_add_help_item("CvstracBrowse");
  
  zNameNS = mprintf("%s",zName);
  if( zName[0] ){ zName = mprintf("%s/",zName); }
  
  db_add_functions();
  az = db_query(
................................................................................
void browse_download(void){
  char *zDir = (char *)(g.zExtra ? g.zExtra : P("d"));
  const char *zVers = P("v");
  char *zName, *zTmp;
  char *zMime = "application/x-bzip-compressed-tar";  /* The default MIME type */

  login_check_credentials();
  if( !g.okCheckout || zDir==0 ){ login_needed(); return; }
  throttle(1,0);

  if( zVers!= 0 ){
    /* A database query is almost definitely going to be faster than having
    ** to pull from from the repository, so we might as well try this first.
    */

    char *z = db_short_query("SELECT chng.date FROM filechng, chng "
                             "WHERE filechng.filename='%q' "
                             "      AND filechng.vers='%q' "
                             "      AND filechng.cn=chng.cn ",

                             zDir, zVers);















    if( z ){
      cgi_modified_since(atoi(z));
      cgi_append_header(mprintf("Last-Modified: %h\r\n",
                        cgi_rfc822_datestamp(atoi(z))));
      free(z);
    }
  }

  if( dump_version(zVers,zDir,1) ){
    cgi_redirect("index");
    return;
  }

  /* Remove trailing slashes from directory */
  if( (zTmp = strrchr(zDir, '/')) ){
    while( zTmp >= zDir && (*zTmp == '/') ){
      *(zTmp--) = 0;
    }
  }
  zTmp = zName = mprintf("%s-%s.tar.bz2", g.zName, (*zDir == '/') ? (zDir + 1) : zDir);



  /* Change slashes into dashes */
  while( *zTmp ){
    if( *zTmp == '/' ){
      *zTmp = '-';
    }
    zTmp++;
  }







<
<
<







 







>
>
>







 







>
>
>







 







|


<
|
|
|
>
|
|
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
|
>
>
>







38
39
40
41
42
43
44



45
46
47
48
49
50
51
...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
...
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
977
978
979
980
981
982
983
984
985
986

987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018












1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
*/
static void output_breadcrumb(const char *zPath, int isdir){
  if( zPath && zPath[0] ){
    const char* zDef = default_browse_url();
    char *zDirUrl;
    char *zDirName;
    int i;



    @ <ul id="breadcrumb">
    @ <li><a class="root" href="%T(zDef)">/</a></li>

    zDirUrl = mprintf("%s", zPath);
    zDirName = zDirUrl;
    for(i=0; zDirUrl[i]; i++){
      if( zDirUrl[i]=='/' ){
................................................................................
    */
    common_add_action_item("dir", "Top");
    common_add_action_item(mprintf("dir?d=%T",zDir), "Up");
    common_add_action_item(mprintf("dirview?d=%T&sc=1",zName), "Long");
  }else{
    common_add_action_item("dirview?sc=1","Long");
  }
  if( g.scm.pxDownload ){
    common_add_action_item(zName[0] ? mprintf("download?d=%T",zName) : "download", "Download");
  }
  az = db_query("SELECT base, isdir FROM file WHERE dir='%q' ORDER BY base",
                 zName);
  for(n=0; az[n*2]; n++){}
  if( zName[0] ) n++;
  nRow = (n+3)/4;
  if( zName[0] ){ zName = mprintf("%s/",zName); }
  common_header("Directory /%h", zName);
................................................................................
      mprintf("dirview%s%s",(zSortUrl[0])?"?":"",zSortUrl), "Top");
    common_add_action_item(
      mprintf("dirview?d=%T%s%s",zDir,(zSortUrl[0])?"&":"",zSortUrl), "Up");
    common_add_action_item(mprintf("dir?d=%T&sc=1",zName), "Short");
  }else{
    common_add_action_item("dir?sc=1", "Short");
  }
  if( g.scm.pxDownload ){
    common_add_action_item(zName[0] ? mprintf("download?d=%T",zName) : "download", "Download");
  }
  common_add_help_item("CvstracBrowse");
  
  zNameNS = mprintf("%s",zName);
  if( zName[0] ){ zName = mprintf("%s/",zName); }
  
  db_add_functions();
  az = db_query(
................................................................................
void browse_download(void){
  char *zDir = (char *)(g.zExtra ? g.zExtra : P("d"));
  const char *zVers = P("v");
  char *zName, *zTmp;
  char *zMime = "application/x-bzip-compressed-tar";  /* The default MIME type */

  login_check_credentials();
  if( !g.okCheckout ){ login_needed(); return; }
  throttle(1,0);


  /* A database query is almost definitely going to be faster than having
  ** to pull from from the repository, so we might as well try this first.
  */
  char *z = zDir && zVers ?
            db_short_query("SELECT chng.date FROM filechng, chng "
                           "WHERE filechng.filename LIKE '%q/%%' "
                           "  AND filechng.vers='%q' "
                           "  AND filechng.cn=chng.cn "
                           "ORDER BY filename ASC, vers DESC LIMIT 1",
                           zDir, zVers) :
            zDir ?
            db_short_query("SELECT chng.date FROM filechng, chng "
                           "WHERE filechng.filename LIKE '%q/%%' "
                           "  AND filechng.cn=chng.cn "
                           "ORDER BY filename ASC, vers DESC LIMIT 1",
                           zDir) :
            zVers ?
            db_short_query("SELECT chng.date FROM filechng, chng "
                           "WHERE filechng.vers='%q' "
                           "  AND filechng.cn=chng.cn "
                           "ORDER BY filename ASC, vers DESC LIMIT 1",
                           zVers) :
            db_short_query("SELECT chng.date FROM filechng, chng "
                           "WHERE filechng.cn=chng.cn "
                           "ORDER BY filename ASC, vers DESC LIMIT 1");
  if( z ){
    cgi_modified_since(atoi(z));
    cgi_append_header(mprintf("Last-Modified: %h\r\n",
                      cgi_rfc822_datestamp(atoi(z))));
    free(z);
  }













  zTmp = zName = mprintf("%s%s%s%s%s.tar.bz2",
                         g.zName,
                         zDir ? "-" : "", zDir ? zDir : "",
                         zVers ? "-" : "", zVers ? zVers : "");
  /* Change slashes into dashes */
  while( *zTmp ){
    if( *zTmp == '/' ){
      *zTmp = '-';
    }
    zTmp++;
  }

Changes to git.c.

825
826
827
828
829
830
831
















































832
833
834
835
836
837
838
839
840
841

842
843
    output_pipe_as_html(in,0);
    @ </div>
  }
  pclose(in);
  
  return 0;
}

















































void init_git(void){
  g.scm.zSCM = "git";
  g.scm.zName = "GIT";
  g.scm.pxHistoryUpdate = git_history_update;
  g.scm.pxHistoryReconstructPrep = git_history_reconstruct;
  g.scm.pxDiffVersions = git_diff_versions;
  g.scm.pxDiffChng = git_diff_chng;
  g.scm.pxIsFileAvailable = 0;  /* use the database */
  g.scm.pxDumpVersion = git_dump_version;

}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>

<
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

    output_pipe_as_html(in,0);
    @ </div>
  }
  pclose(in);
  
  return 0;
}

static int git_download(const char *zDir, const char *zVersion, int compression){
  FILE *in;
  char *zCmd, zBuf[1024], *zCompression = "", *zFormat = "";
  size_t nRead;
  const char *zRoot = db_config("cvsroot","");
  if( zRoot[0]==0 ) return -1;

  switch( compression ){
  case COMPRESSION_TAR:
    zFormat = "--format=tar";
    break;
  case COMPRESSION_TAR_GZ:
    zFormat = "--format=tar";
    zCompression = " | gzip";
    break;
  case COMPRESSION_TAR_BZ2:
    zFormat = "--format=tar";
    zCompression = " | bzip2";
    break;
  case COMPRESSION_ZIP:
    zFormat = "--format=zip";
    break;
  default:
    return -1;
  }

  zCmd = mprintf(OS_VAL("GIT_DIR='%s' git archive %s %s %s%s 2>/dev/null",
                        "GIT_DIR=\"%s\" git archive %s %s %s%s 2>NUL"),
                        quotable_string(zRoot),
                        quotable_string(zFormat),
                        zVersion ? quotable_string(zVersion) : "HEAD",
                        zDir ? quotable_string(zDir) : "",
                        quotable_string(zCompression));
  in = popen(zCmd, OS_VAL("r","rb"));
  if( in==0 ){
    return -1;
  }
  free(zCmd);
  while( (nRead = fread(zBuf, 1, sizeof(zBuf), in)) ){
    if( (fwrite(zBuf, 1, nRead, stdout) < nRead) || (nRead < sizeof(zBuf)) ){
      break;
    }
    fflush(stdout);
  }
  pclose(in);
  return 0;
}

void init_git(void){
  g.scm.zSCM = "git";
  g.scm.zName = "GIT";
  g.scm.pxHistoryUpdate = git_history_update;
  g.scm.pxHistoryReconstructPrep = git_history_reconstruct;
  g.scm.pxDiffVersions = git_diff_versions;
  g.scm.pxDiffChng = git_diff_chng;
  g.scm.pxIsFileAvailable = 0;  /* use the database */
  g.scm.pxDumpVersion = git_dump_version;
  g.scm.pxDownload = git_download;
}

Changes to svn.c.

953
954
955
956
957
958
959
960
961
962
963






964



965
966
967
968
969
970
971
972




973


974
975
976
977
978
979
980
981
982
    "COMMIT;"
  );
  return 0;
}

static int svn_download(const char *zDir, const char *zVersion, int compression){
  FILE *in;
  char *zCmd, zBuf[1024];
  size_t nRead;
  char *zSvnRoot = (char *)db_config("cvsroot",""), *zTmp = zSvnRoot;







  if( compression != COMPRESSION_TAR_BZ2 ){



    return -1;
  }
  /* Ensure we got only slashes in SVNROOT which is expected format for svntar */
  while( *zTmp ){
    if( *zTmp == '\\' ) *zTmp = '/';
    zTmp ++;
  }
  zCmd = mprintf(OS_VAL("svntar -j -- - 'file:%s/%s' 2>/dev/null",




                        "svntar -j -- - \"file:%s/%s\" 2>NUL"), quotable_string(zSvnRoot), quotable_string(zDir));


  in = popen(zCmd, "rb");
  if( in==0 ){
    return -1;
  }
  free(zCmd);
  while( (nRead = fread(zBuf, 1, sizeof(zBuf), in)) ){
    if( (fwrite(zBuf, 1, nRead, stdout) < nRead) || (nRead < sizeof(zBuf)) ){
      break;
    }







|



>
>
>
>
>
>
|
>
>
>







|
>
>
>
>
|
>
>
|
|







953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
    "COMMIT;"
  );
  return 0;
}

static int svn_download(const char *zDir, const char *zVersion, int compression){
  FILE *in;
  char *zCmd, zBuf[1024], *zCompression;
  size_t nRead;
  char *zSvnRoot = (char *)db_config("cvsroot",""), *zTmp = zSvnRoot;

  switch( compression ){
  case COMPRESSION_TAR:
    break;
  case COMPRESSION_TAR_GZ:
    zCompression = " --gzip";
    break;
  case COMPRESSION_TAR_BZ2:
    zCompression = " --bzip2";
    break;
  default:
    return -1;
  }
  /* Ensure we got only slashes in SVNROOT which is expected format for svntar */
  while( *zTmp ){
    if( *zTmp == '\\' ) *zTmp = '/';
    zTmp ++;
  }
  zCmd = mprintf(OS_VAL("svntar%s%s%s -- - 'file://%s%s%s' 2>/dev/null",
                        "svntar%s%s%s -- - \"file:%s%s%s\" 2>NUL"),
                        zCompression,
                        zVersion ? " -r " : "",
                        zVersion ? quotable_string(zVersion) : "",
                        quotable_string(zSvnRoot),
                        zDir ? "/" : "",
                        zDir ? quotable_string(zDir) : "");
  in = popen(zCmd, OS_VAL("r","rb"));
  if( in==NULL ){
    return -1;
  }
  free(zCmd);
  while( (nRead = fread(zBuf, 1, sizeof(zBuf), in)) ){
    if( (fwrite(zBuf, 1, nRead, stdout) < nRead) || (nRead < sizeof(zBuf)) ){
      break;
    }