Mercurial command to identify files that match filespec and have changed since last update

StackOverflow https://stackoverflow.com/questions/5980602

  •  12-11-2019
  •  | 
  •  

Question

Ideally, I'm looking for a stateless way to do this since I'm using a batch file.

The scenario is that I have a repository on a server that receives pushes from users. The repo is also a working copy that is the source for wiki pages (dokuwiki), which are simply the text files that are in the repository, one for each page in the wiki.

Because this is on a web server, the working copy isn't used by anyone interactively. Rather, a batch file runs periodically and issues the appropriate commands to keep the working copy updated with the latest changes that have been pushed to the repo. As a side note to the implementation, it also accepts changes to the working copy from the wiki and tries to merge and commit them at the same stroke.

The batch file looks like this:

@echo off
cd \dokuwiki\data\directory
start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"
for /r %%x in (*.jpg *.png *.gif) do copy /y "%%x" ..\..\media\directory

This works fine for the text files, but dokuwiki requires that media such as graphics be stored in another directory, which is what the last for statement is for.

Note that I'm not concerned with improvements to the script up to that point. It's been vetted as our desired way to do the update in this environment.

The issue with the copy at the end is that it copies all graphics irrespective of whether they've changed or not. Obviously, it would be better to only copy the graphics which have changed. Since there may have been more than one push into this repository since the last update, I want to identify and copy only those graphics which have changed since the last time this working copy was updated, i.e. the last time this script ran hg update.

I can't think of an intuitive way to do this off-hand. It would be best if information didn't need to be persisted manually between script runs, but it's not out of the question.

Was it helpful?

Solution

You may be able to get away with using xcopy and its /D switch, which copies only source files that are newer than files in the destination.

OTHER TIPS

I have no idea about the syntax of Windows batch files, but Mercurial's hg status --rev REV is probably what you're looking for:

@echo off
cd \dokuwiki\data\directory

ORIG_REV = hg log --rev . --template="{node}"

start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"

CHANGED_FILES = hg status --no-status --added --modified --rev ORIG_REV -I '*.jpg' -I '*.png' -I '*.gif'

for /r %%x in (CHANGED_FILES) do copy /y "%%x" ..\..\media\directory
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top