Mercurial: listing files modified in incoming changesets, and guessing conflicts...

Yesterday my colleague Shanliang asked me whether there was a way to see which files had been modified in the changesets that would be pulled in by 'hg pull', and whether they would conflicts with the files currently being edited in his workspace.

After poking here and there with 'hg help', and with the help of Luis-Miguel, we finally came up with this solution:

hglistin
#!/usr/bin/bash
#
# lists the files that have been modified in the changesets that will
# be imported by 'hg pull'
#
# syntax: hglistin [parent-path]
#

hg in -v  "$@" | grep 'files:' | sed 's,files:,,' \\
   | sed 's,\^[ ]\*,,' | tr ' ' '\\012' | sort | uniq

hgconflicts
#!/usr/bin/bash
#
# lists the files that have been modified in the changesets that will
# be imported by 'hg pull', and that are also edited in this workspace.
#
# syntax: hgconflicts [parent-path]
#

list1() {
  hg in -v  "$@" | grep 'files:' | sed 's,files:,,' \\
    | sed 's,\^[ ]\*,,' | tr ' ' '\\012' | sort | uniq
}

list2() {
  hg status -nmr | sort | uniq
}

(list1  "$@" ; list2 ) | sort | uniq -d

The result of 'hgconflicts' is valid only when you have nothing committed to push (that is, when 'hg out' reports nothing).

Well, there's probably better ways to do that, and I promise, one of these days I'll take the time to figure out how to do the same thing in python ;-).
Hope you'll find it useful nonetheless!

Cheers,

-- daniel

Comments:

Have you tried using --template to just get the files? e.g. something like

hg in --quiet --template '{files}\\n' | sort | uniq

Or is that getting you the same list?

-kto

Posted by guest on September 19, 2008 at 03:25 PM CEST #

Hi Kelly,

Yes, this works, but you still need the 'tr' bit:

hg in --quiet --template '{files}\\n' | tr ' ' '\\012'| sort | uniq

I didn't know how the --template option worked. This is good to remember, thanks!

-- daniel

Posted by daniel on September 22, 2008 at 09:38 AM CEST #

If you use a template map file you can tell hg to separate each file name with a newline:

cat >mystyle <<EOF
changeset = "{files}"
file = "{file}\\n"
EOF
hg in --quiet --template mystyle

Posted by Eric Hawicz on March 12, 2010 at 01:00 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Daniel Fuchs blogs on Scene Builder, JMX, SNMP, Java, etc...

The views expressed on this blog are those of the author and do not necessarily reflect the views of Oracle.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today