I'd like to "re-sort" the commits in a repository by age (completely for visualization purposes, i don't want to functionally change anything at all). The "Rev" number is there only for convenience, and is currently dependent on when the commits were pushed into the repository. This means we've got commits from a half hour ago "earlier" than commits from a month, and it would be easier to show when things got done with a simple resort that doesn't change the structure at all. This would keep the repository exactly the same, but make repository appear that each change set was pushed immediately after each commit.Is there a way to do this?
3 回答
You can use revsets to help with that! In particular the sort
function.
This will return the last 10 changesets from tip
(by the local changeset id) and return them sorted by date:
hg log -r "sort(last(:tip, 10), date)"
Someone upvoted the question and reminded me about it. I ended up writing the following batch script (sorry, I was in windows, it should be pretty easy to translate to bash)
REM clone_sorted.bat
REM usage: clone_sorted source destination
@echo off
echo "Cloning from %1 to %2"
hg clone -r 0 %1 %2
cd %2
@echo on
for /F %%h in ('hg log -R %1 -r "sort(1:tip, date)" --template "{rev}\n"') DO hg pull %1 -r %%h
Look at hg help convert
in particular using hg convert --datesort SOURCE DEST
. But be warned that the resulting repository could be huge compared to using the other sort methods.
Note that you should generally not use hg convert
on a repository that has been created using hgsubversion or hg-git as you will lose the extra metadata that is needed to maintain the link to the original repository. It might be possible to rebuild the metadata (I haven't tried).