[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Syncing a non-versioned directory tree into the repository

From: Henderson, Michael D <michael.d.henderson_at_lmco.com>
Date: 2004-08-28 00:09:55 CEST

I have a directory tree where end-users dump data files that I need to add to the repository. I was looking at vendor drop in the book, but it isn't quite what I'm looking for. This isn't a two way process, the repository should only be updated via that data-dump directory tree. I can't version the data-dump tree, so I've created a process that uses a script to sync up the directory. It's pretty slow, though. The constant calls to diff seem to be the problem.

I replaced diff with cmp. That dropped the run time by about 10%, but it's still taking too long. So, I had the bright idea of just comparing the timestamps. Since I'm syncing the timestamps everytime I update the repository, it should only change if the source file is updated. If it has, I can copy the file, do the touch -r and then let svn commit figure out if the file has really changed.

I can write a program to do the stat and compare the timestamps, but I'm wondering two things - has this already been done and is there a better approach?

Thanks,
Mike

##############################################################################
# SyncFiles
#
# Compare directory and files in sourceDir to targetDir, assuming that
# sourceDir is not in the current repository. If the directory or file is
# in sourceDir and not in targetDir, add it. If it is and it's a file,
# compare the two files. If they differ, copy the file from sourceDir to
# targetDir, preserving the date/time stamp.
#
# NOTE: Use PurgeFiles to remove directories and files from targetDir that
# don't exist in the sourceDir.
#
SyncFiles() {
  sourceDir="$1"
  targetDir="$2"

  echo "comparing source $sourceDir"
  echo " target $targetDir"

  cd $targetDir || return 2
  cd $sourceDir || return 2

  #
  # compare directory structure and content
  #
  for dirName in $( SubDir )
  do
    if [ ! -d "$targetDir/$dirName" ]
    then
      echo "missing: $targetDir/$dirName"
      retVal=1
    else
      for fileName in $dirName/*
      do
        if [ -f "$fileName" ]
        then
          if [ -f "$targetDir/$fileName" ]
          then
           #diff "$fileName" "$targetDir/$fileName" 2>&- >&-
            cmp -s "$fileName" "$targetDir/$fileName" 2>&- >&-
            if [ $? != 0 ]
            then
              echo " update: $targetDir/$fileName"
              cp "$fileName" "$targetDir/$fileName" || return 2
              touch -r "$fileName" "$targetDir/$fileName" 2>&-
              retVal=1
            fi
          else
            cp "$fileName" "$targetDir/$fileName" || return 2
            touch -r "$fileName" "$targetDir/$fileName" 2>&-
            svn add $targetDir/$fileName
            retVal=1
          fi
        fi
      done
    fi
  done
  [ $retVal == 0 ] || return $retVal
  return 0
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sat Aug 28 00:10:19 2004

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.