Esempio n. 1
0
void BuildIgnoredList(std::vector<std::string> & ignlist, const std::string& path,
                      DWORD *timeStamp, FileChangeParams *fcp)
{
   TDEBUG_ENTER("BuildIgnoredList");
   bool doUpdate = false;

   std::string ignPath(path);
   ignPath = EnsureTrailingDelimiter(ignPath);
   ignPath += ".cvsignore";
   FileChangeParams myFcp;
   if (fcp)
      myFcp = GetFileChangeParams(ignPath);

   // Update default ignored list
   BuildDefaultIgnoredList();
   if (timeStamp)
   {
      if ((*timeStamp != defIgnoreListTimeStamp) || (*timeStamp == 0))
         doUpdate = true;
   }
   else
   {
      doUpdate = true;
   }

   // check directory ignored file
   if (fcp)
   {
      if ((fcp->IsNull()) || (*fcp != myFcp))
      {
         doUpdate = true;
      }
   }
   else
   {
      doUpdate = true;
   }

   // Do we have to update
   if (doUpdate)
   {
      ignlist.clear();
      ignlist = defIgnoredList;

      // TODO: read $CVSROOT/CVSROOT/cvsignore
      
      // Read .cvsignore from current directory
      ReadIgnoredFile(ignPath, ignlist);
      if (fcp)
         *fcp = myFcp;
      if (timeStamp)
         *timeStamp = defIgnoreListTimeStamp;
   }
}
Esempio n. 2
0
// Build default ignored list
void BuildDefaultIgnoredList()
{
   TDEBUG_ENTER("BuildDefaultIgnoredList");
   CSHelper csHelper(myCriticalSection, true);
   std::string userCvsIgnoreFile;
   GetHomeDirectory(userCvsIgnoreFile);
   userCvsIgnoreFile = EnsureTrailingDelimiter(userCvsIgnoreFile) + ".cvsignore";
   FileChangeParams myFcp = GetFileChangeParams(userCvsIgnoreFile);

   // Update every dwUpdateIgnoredListInterval seconds
   if (GetTickCount() > defIgnoreListTimeStamp + 1000 * dwUpdateIgnoredListInterval)
   {
      DoUpdateIgnoredList();
      fcpCvsignore = myFcp;
   }
   // Update if .cvsignore in home dir has changed
   else if (fcpCvsignore != myFcp)
   {
      DoUpdateIgnoredList();
      fcpCvsignore = myFcp;
   }
}
Esempio n. 3
0
/* Read the entries file into a list, hashing on the file name.

   UPDATE_DIR is the name of the current directory, for use in error
   messages, or NULL if not known (that is, noone has gotten around
   to updating the caller to pass in the information).  */
bool Entries_Open(EntnodeMap& entries,
                  const char* fullpath,
                  FileChangeParams* fcp)
{
   TDEBUG_ENTER("Entries_Open");
   std::string cvsdir(fullpath);
   cvsdir = EnsureTrailingDelimiter(cvsdir);
   cvsdir += "CVS";
   cvsdir = EnsureTrailingDelimiter(cvsdir);

   if (fcp)
   {
      FileChangeParams myFcp = GetFileChangeParams(cvsdir + "Entries");
      if ((!(fcp->IsNull())) && (myFcp == *fcp))
      {
         return true;
      }
      *fcp = myFcp;
   }

   entries.clear();
   unsigned long sizeextra = 0;
   FILE* fpinx = fopen((cvsdir + "Entries.Extra").c_str(), "r");
   if (fpinx)
   {
      FileChangeParams myFcp = GetFileChangeParams(cvsdir + "Entries.Extra");
      sizeextra = myFcp.dwFileSizeLow;
   }
   FILE* fpin = fopen((cvsdir + "Entries").c_str(), "r");
   if (!fpin)
   {
      if (fpinx)
         fclose (fpinx);
      return false;
   }

   // Read contents of CVS/Rename into a set for easy lookup
   std::ifstream cvsRename((cvsdir + "Rename").c_str());
   std::set<std::string> renameEntries;
   while (cvsRename.good())
   {
      std::string file;
      // Each entry is
      //    newname
      //    (blank)
      //    newname
      //    oldname
      // We are only interested in the new name.
      std::getline(cvsRename, file);
      file = ExtractLastPart(file);
      renameEntries.insert(file);
      for (int i = 0; i < 3; ++i)
         std::getline(cvsRename, file);
   }
   EntnodeData* ent;
   char* extrabuf = 0;
   size_t lenreadx;
   if (fpinx && (sizeextra > 0))
   {
      extrabuf = (char*) malloc((sizeextra*2)+10);
      fseek(fpinx, 0, SEEK_SET);
      lenreadx = fread(extrabuf, sizeof(char), (sizeextra*2)+9, fpinx);
      *(extrabuf+lenreadx) = '\0';
      if (!feof(fpinx))
      {
         // could not read the whole file for some reason...
         free(extrabuf);
         extrabuf = 0;
      }
   }

   while ((ent = fgetentent(fpin, extrabuf, fullpath, 0, sizeextra)) != 0)
   {
      ENTNODE newnode(ent);
      ent->UnRef();

      std::string name = newnode.Data()->GetName();
      EntnodeMap::iterator it = entries.find(name);
      if (it != entries.end())
      {
         _ASSERT(false);
         TDEBUG_TRACE("Warning : duplicated entry in the 'CVS/Entries' file in folder " << fullpath);
      }
      std::set<std::string>::iterator renameIter = renameEntries.find(name);
      ent->SetRenamed(renameIter != renameEntries.end());
      entries[name] = newnode;
   }

   fclose (fpin);
   if (fpinx)
      fclose (fpinx);
   if (extrabuf)
      free (extrabuf);

   fpin = fopen((cvsdir + "Entries.log").c_str(), "r");
   if (fpin)
   {
      char cmd;

      while ((ent = fgetentent(fpin, extrabuf, fullpath, &cmd, sizeextra)) != 0)
      {
         ENTNODE newnode(ent);
         ent->UnRef();

         std::string name = newnode.Data()->GetName();

         switch (cmd)
         {
         case 'A':
            entries[name] = newnode;
            break;
         case 'R':
            entries.erase(std::string(name));
            break;
         default:
            /* Ignore unrecognized commands.  */
            TDEBUG_TRACE("Warning: Unrecognized command '" << cmd << "'");
            break;
         }
      }
      fclose (fpin);
   }
   return true;
}