Sunday, 24 February 2013

Unable to load module entry point class com.google.gwt.user.client.UserAgentAsserter

gwt Issue#7233 : On Dev mode Tab 

11:57:14.507 [ERROR] [eccount] Unable to load module entry point class com.google.gwt.user.client.UserAgentAsserter (see associated exception for details)
java.lang.RuntimeException: Deferred binding failed for 'com.google.gwt.user.client.UserAgentAsserter$UserAgentProperty' (did you forget to inherit a required module?)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
    at com.google.gwt.core.client.GWT.create(GWT.java:97)
    at com.google.gwt.user.client.UserAgentAsserter.onModuleLoad(UserAgentAsserter.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    at com.google.gwt.core.client.GWT.create(GWT.java:97)
    at com.google.gwt.user.client.UserAgentAsserter.onModuleLoad(UserAgentAsserter.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Thread.java:662)


Stacktrace on eclipse console

Exception in thread "Thread-0" java.lang.NullPointerException
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.JavaScriptException.getName0(JavaScriptException.java)
at com.google.gwt.core.client.JavaScriptException.getName(JavaScriptException.java:64)
at com.google.gwt.core.client.JavaScriptException.init(JavaScriptException.java:179)
at com.google.gwt.core.client.JavaScriptException.getMessage(JavaScriptException.java:162)
at com.google.gwt.dev.util.log.AbstractTreeLogger.getStackTraceAsString(AbstractTreeLogger.java:70)
at com.google.gwt.dev.shell.remoteui.ViewerServiceClient.generateLogData(ViewerServiceClient.java:296)
at com.google.gwt.dev.shell.remoteui.ViewerServiceClient.addLogEntry(ViewerServiceClient.java:118)
at com.google.gwt.dev.shell.remoteui.ViewerServiceTreeLogger.sendEntry(ViewerServiceTreeLogger.java:158)
at com.google.gwt.dev.shell.remoteui.ViewerServiceTreeLogger$PendingLog.send(ViewerServiceTreeLogger.java:72)
at com.google.gwt.dev.shell.remoteui.ViewerServiceTreeLogger.initLogHandle(ViewerServiceTreeLogger.java:134)
at com.google.gwt.dev.shell.remoteui.ViewerServiceTreeLogger$1.onDone(ViewerServiceTreeLogger.java:145)
at com.google.gwt.dev.shell.remoteui.ViewerServiceTreeLogger$1.onDone(ViewerServiceTreeLogger.java:143)
at com.google.gwt.dev.shell.remoteui.ViewerServiceClient$1.onDone(ViewerServiceClient.java:96)
at com.google.gwt.dev.shell.remoteui.ViewerServiceClient$1.onDone(ViewerServiceClient.java:94)
at com.google.gwt.dev.shell.remoteui.MessageTransport$PendingRequest.setResponse(MessageTransport.java:124)
at com.google.gwt.dev.shell.remoteui.MessageTransport.processServerResponse(MessageTransport.java:423)
at com.google.gwt.dev.shell.remoteui.MessageTransport.processMessage(MessageTransport.java:399)
at com.google.gwt.dev.shell.remoteui.MessageTransport.access$400(MessageTransport.java:44)
at com.google.gwt.dev.shell.remoteui.MessageTransport$3.run(MessageTransport.java:322)
at java.lang.Thread.run(Thread.java:662)



SOLUTION
UserAgentAsserter (as listed below) is actually a Helper class, which, during startup, asserts that the specified user.agent. So, issue is related to user.agent.

package com.google.gwt.user.client;

import com.google.gwt.core.client.EntryPoint;

import com.google.gwt.core.client.GWT;

/**

 * Helper class, which, during startup, asserts that the specified user.agent
 * selection property value indeed matches the expected value for this browser /
 * user agent, thus avoid long hours debugging strange error messages when a
 * single user agent compile, typically created for testing purposes, ends up
 * being executed in the wrong browser.
 */
public class UserAgentAsserter implements EntryPoint {

  /**

   * Interface to provide both the compile time and runtime
   * <code>user.agent</code> selection property value.
   */
  interface UserAgentProperty {
    boolean getUserAgentRuntimeWarning();
    
    String getCompileTimeValue();

    String getRuntimeValue();

  }

  public void onModuleLoad() {

    UserAgentProperty impl = GWT.create(UserAgentProperty.class);
    if (!impl.getUserAgentRuntimeWarning()) {
      return;
    }
    
    String compileTimeValue = impl.getCompileTimeValue();
    String runtimeValue = impl.getRuntimeValue();

    if (!compileTimeValue.equals(runtimeValue)) {

      displayMismatchWarning(runtimeValue, compileTimeValue);
    }
  }

  /**

   * Implemented as a JSNI method to avoid potentially using any user agent
   * specific deferred binding code, since this method is called precisely when
   * we're somehow executing code from the wrong user.agent permutation.
   */
  private native void displayMismatchWarning(String runtimeValue,
      String compileTimeValue) /*-{
    $wnd.alert("ERROR: Possible problem with your *.gwt.xml module file."
        + "\nThe compile time user.agent value (" + compileTimeValue
        + ") does not match the runtime user.agent value (" + runtimeValue
        + "). Expect more errors.\n");
  }-*/;
}

I tried removing src/main/webapp/gwt-unitCache/

$ ls -l eccount-server/src/main/webapp/
total 48
drwxrwxr-x 3 prayag prayag 4096 Feb 20 19:11 eccount
drwxrwxr-x 2 prayag prayag 4096 Jan 30 14:59 gwt-unitCache
drwxrwxr-x 5 prayag prayag 4096 Feb 18 15:55 images
drwxrwxr-x 2 prayag prayag 4096 Jan 30 14:59 js
drwxrwxr-x 2 prayag prayag 4096 Jan 30 16:12 styles
drwxrwxr-x 7 prayag prayag 4096 Feb 25 10:23 WEB-INF

 $ sudo rm -r eccount-server/src/main/webapp/gwt-unitCache/


But, worked only when  
<set-property name="user.agent" value="safari"/>  is specified in eccount.gwt.xml.

References
GWT 2.5.0-rc1 and eclipse (3.7 and 4.2) problems, https://groups.google.com/d/msg/google-web-toolkit/bmXJvON1KOg/WhV4W9br2WEJ



Wednesday, 20 February 2013

APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

My c3p0 version is
compile 'com.mchange:c3p0:0.9.1.2'

[1] Error 
WARN   run, com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@c3d2e5 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
WARN   run, com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@c3d2e5 -- APPARENT DEADLOCK!!! Complete Status: 
 Managed Threads: 3
 Active Threads: 3
 Active Tasks: 
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1556819 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@254f54 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@17b15ec (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
 Pending Tasks: 
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1dc5047
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@11a9ca3
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@21b8e1
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1f0c306
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@193e3d0
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5174ad
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1c325b7
Pool thread stack traces:
 Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
  java.lang.Thread.sleep(Native Method)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
  com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
 Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
  java.lang.Thread.sleep(Native Method)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
  com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
 Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
  java.lang.Thread.sleep(Native Method)
  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
  com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)




[2] Pooled DataSource / jpa-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
 default-autowire="byName">


  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  <property name="driverClass" value="${db.driver}"/>
  <property name="jdbcUrl" value="${db.url}"/>
  <property name="user" value="${db.username}"/>
  <property name="password" value="${db.password}"/>
  <property name="minPoolSize" value="${db.poolsize.min}"/>
  <property name="maxPoolSize" value="${db.poolsize.max}"/>
  <property name="maxStatementsPerConnection" value="15"/>
  <property name="idleConnectionTestPeriod" value="3000"/>
 </bean>

</beans>


hibernate.cfg.xml is : 

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.default_batch_fetch_size">16</property>
  <property name="hibernate.max_fetch_depth">5</property>

   <property name="hibernate.cache.use_query_cache">false</property>
  <property name="hibernate.cache.use_second_level_cache">false</property>
  <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> 
  
  <!-- property name="show_sql">true</property-->
        <!--property name="format_sql">true</property-->
        <!--property name="use_sql_comments">true</property-->

  </session-factory>
</hibernate-configuration>



db.properties
db.username=root
db.password=mysql55
db.url=jdbc:mysql://localhost/eccount
db.dialect=org.hibernate.dialect.MySQL5Dialect
db.driver=com.mysql.jdbc.Driver
db.generateDdl=false
db.showSql=false

db.persistenceUnit=eccount

db.generateDdl=true
db.poolsize.max=100
db.poolsize.min=10
# turn on statement pooling


[3] PROPOSED SOLUTION

For version 0.9.2 of c3p0 (compile 'com.mchange:c3p0:0.9.2'), 

[1] Configure Statement Pooling
1.1 statementCacheNumDeferredCloseThreads="1"

If statementCacheNumDeferredCloseThreads is > zero, 
the Statement pool will defer physically close()ing cached Statements until its parent Connection is not   in use by any client or internally (in e.g. a test) by the pool itself.
For some JDBC drivers (especially Oracle), attempts to close a Statement freeze if the parent Connection is in use.
This parameter defaults to 0.

Set it to a positive value if you observe "APPARENT DEADLOCKS" realted to Connection close tasks.
Almost always, that value should be one: if you need more than one Thread dedicated solely to Statement destruction, you probably should set maxStatements and/or maxStatementsPerConnection to higher values so you don't churn through cached Statements so quickly.



SOLUTION IN MY CASE
Restart mysql server.

REFERENCES
Configuring Statement Pooling
http://www.mchange.com/projects/c3p0/#configuring_statement_pooling

c3p0 - JDBC3 Connection and Statement Pooling,  http://www.mchange.com/projects/c3p0/#numHelperThreads

What are the required C3P0 settings for hibernate in order to avoid Deadlocks, http://stackoverflow.com/a/3731978/432903

c3p0 apparent deadlock / creating emergency threads, https://forum.hibernate.org/viewtopic.php?t=947246&highlight=apparent+deadlock+c3p0

java+hibernate webservice - apperant deadlock,
http://stackoverflow.com/a/11669290/432903

c3p0 - JDBC3 Connection and Statement Pooling, http://www.mchange.com/projects/c3p0/#configuration_files

Best way of database pooling in spring for production system,
http://stackoverflow.com/a/14548122/432903

http://stackoverflow.com/a/12088523/432903


Monday, 18 February 2013

Spring SOAP Server


STEP 1

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ServiceRequest", namespace = EccountServiceEndpoint.NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class ServiceRequest implements Serializable {

private static final long serialVersionUID = 1L;

public static final String NAMESPACE = "http://www.eccount.com/eccount/ews/schemas";

private String username;

private String password;

private String serviceCode;

private List<EccountMapEntry> requestFields;
}


STEP 2

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "EccountMapEntry", namespace = EccountServiceEndpoint.NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class EccountMapEntry implements Serializable {

private static final long serialVersionUID = -1068419604611623560L;

public static final String NAMESPACE = "http://www.eccount.com/eccount/ews/schemas";

private String key;
private String value;
}


STEP 3

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ServiceResponse", namespace = EccountServiceEndpoint.NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class ServiceResponse implements Serializable {
private static final long serialVersionUID = 1L;

public static final String NAMESPACE = "http://www.eccount.com/eccount/ews/schemas";

private String serviceInfoId;

private String responseCode;

private String responseMessage;

private EccountServiceStatus status;

private List<EccountMapEntry> responseFields;
}


STEP 4

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "EccountServiceStatus", namespace = EccountServiceEndpoint.NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public enum EccountServiceStatus {
SUCCESS, FAILURE
}



STEP 5


<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.eccount.com/eccount/ews/schemas"
targetNamespace="http://www.eccount.com/eccount/ews/schemas">
<element name="ServiceRequest">
<complexType>
<sequence>
<element name="username" type="string"></element>
<element name="password" type="string"></element>
<element name="serviceCode" type="string"></element>
<element name="originatingUniqueId" type="string"></element>
<element name="requestFields" type="tns:EccountMapEntry" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</complexType>
</element>
<element name="ServiceResponse">
<complexType>
<sequence>
<element name="serviceInfoId" type="string" minOccurs="0"></element>
<element name="status" type="tns:EccountServiceStatus"></element>
<element name="responseCode" type="string"></element>
<element name="responseMessage" type="string"></element>
<element name="responseFields" type="tns:EccountMapEntry" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</complexType>
</element>

<complexType name="EccountMapEntry">
<sequence>
<element name="key" type="string" />
<element name="value" type="string" />
</sequence>
</complexType>

<simpleType name="EccountServiceStatus">
<restriction base="string">
<enumeration value="SUCCESS" />
<enumeration value="FAILURE" />
</restriction>
</simpleType>

</schema>



STEP 6  implementing the @Endpoint
Implement Endpoints to handle incoming XML messages. 
An @Endpoint is typically created by annotating a class with the @Endpoint annotation.

The @PayloadRoot annotation tells Spring-WS that the handleServiceRequest() method is suitable for handling XML messages.

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class EccountServiceEndpoint {

public static final String NAMESPACE_URI = "http://www.eccount.com/eccount/ews/schemas";

private final IWsRequestProcessingApi wsRequestProcessingApi;

public EccountServiceEndpoint(IWsRequestProcessingApi wsRequestProcessingApi) {
this.wsRequestProcessingApi = wsRequestProcessingApi;
}

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "ServiceRequest")
public @ResponsePayload
ServiceInfoResponse handleServiceRequest(@RequestPayload ServiceRequest request) {

try {
return wsRequestProcessingApi.processServiceInfo(request);
} catch (Exception exception) {
ServiceResponse response = new ServiceResponse();
//set response message
return response;
}
}
}


STEP 7 configure ws-context.xml and publishing the WSDL
configure the above classes in ws-context.xml Spring XML configuration file.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
  http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<sws:annotation-driven />

<sws:dynamic-wsdl id="eccountservice"
portTypeName="EccountService" locationUri="/ews/eccountservice"
targetNamespace="http://www.eccount.com/eccount/ews/schemas">
<sws:xsd location="classpath:/WEB-INF/xsds/ews.xsd" />
</sws:dynamic-wsdl>

<oxm:jaxb2-marshaller id="marshaller">
<oxm:class-to-be-bound
name=" com.zazzercode.eccount.server.ws.schemas.ServiceRequest" />
<oxm:class-to-be-bound
name="com.zazzercode.eccount.server.ws.schemas.ServiceResponse" />
<oxm:class-to-be-bound
name="com.zazzercode.eccount.server.ws.schemas.EccountMapEntry" />
<oxm:class-to-be-bound
name="com.zazzercode.eccount.server.ws.schemas.EccountServiceStatus" />
</oxm:jaxb2-marshaller>

<bean id="eccountServiceEndpoint"
class="com.zazzercode.eccount.server.ws.endpoints.EccountServiceEndpoint">
<constructor-arg ref="wsRequestProcessingApi" />
</bean>

</beans>



REFERENCES
3.6. Implementing the Endpoint, http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html

Spring Web Services: SOAP vs. REST by Sam Brannen, http://www.slideshare.net/sbrannen/spring-web-services-soap-vs-rest

Tuesday, 12 February 2013

Mercurial in daily use



@tednaleid
In his book, The Productive Programmer, NealFord(@neal4d) talks about using shims or jigs to help productivity. Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they’re worth doing. They’re little tools that help make your job easier and let you avoid using brute force to solve all of your problems.

[1] hg color extension
add [extension] color=  to ~/.hgrc
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ vi /home/prayag/.hgrc

[ui]
username = prayag

[extensions]
color =
progress =
hgext.extdiff =
hgext.purge=
graphlog =

[extdiff]
cmd.vimdiff =


[2.1] list the repository's named branches
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg branches
default           721:88ddd68c8bd9
feat-x            687:97ace77757da (inactive)


[2.2] show the current branch name
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg branch
default

[3.1] incoming changes with files that will be changed
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg incoming --stat -v
http authorization required
realm: Mercurial repositories
user: prayag
password:
comparing with http://10.X.XXX.X/hg/zazzercode-hg/
searching for changes

all local heads known remotely
changeset:   9:a788c9d9556c

tag:         tip
user:        pra
date:        Thu Feb 28 13:27:56 2013 +0545
files:       src/main/java/com/zazzercode/eccount/server/api/ITransactionApi.java
description : REFACTOR transactionAPI

src/main/java/com/zazzercode/eccount/server/api/ITransactionApi.java | 4 +++
1 files changed, 3 insertions(+), 0 deletions(-)


OR
[3.2] incoming changes for a particular branch with patch(=changed code)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg incoming -b default -v --patch

[4.1] restore a file to it's checkout state
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg revert src/main/java/com/zazzercode/eccount/server/api/ITransactionApi.java -r-1

[4.2] revert all changes

prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg revert --all
reverting src/main/java/com/zazzercode/eccount/server/api/impl/TransactionApiImpl.java
reverting src/main/java/com/zazzercode/eccount/server/api/ITransactionApi.java


[5] Pull changes from a remote repository to a local one
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg pull -v
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg upadate -v

OR a single equivalent command
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg pull -u


_______________________________________________________________________________
_______________________________________________________________________________

[6] hg merge pulled change to local head
It's useful when I have a commit(1693) to push which I did before hg pull(1694).
Verify with commit log

prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -G --limit 3
o  changeset:   1694:c055f66f64c2
|  branch:      eccount_merchant
|  tag:         tip
|  parent:      1692:7eef95617dde
|  user:        albert
|  date:        Fri Aug 23 17:56:19 2013 +0545
|  summary:     UPDATE search ui, i18 text, search query condition
|
| @  changeset:   1693:a14ffdea264f
|/   branch:      eccount_merchant
|    user:        prayag<prayag.upd@gmail.com>
|    date:        Sun Aug 25 11:55:27 2013 +0545
|    summary:     REFACTOR api-context to fix multiple spring component scan




prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg merge


If throws 
abort: crosses branches (merge branches or use --clean to discard changes)
OR
abort : outstanding uncommitted changes (use 'hg status' to list changes)
commit changes, revert un-necessary changes and then merge.

$ hg revert -a
$ hg merge

hg status will now show pulled files as uncommited changes, commit them first and then push the previous commit with this new one.
$ hg commit -m "ADD merged files"; //this will commit all modified files
$ hg push

Verify after all these steps are performed correctly, 
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -G --limit 3

@    changeset:   1695:11ea43c99d0c
|\   branch:      eccount_merchant
| |  tag:         tip
| |  parent:      1693:a14ffdea264f
| |  parent:      1694:c055f66f64c2
| |  user:        prayag<prayag.upd@gmail.com>
| |  date:        Sun Aug 25 12:33:48 2013 +0545
| |  summary:     ADD merged changes
| |
| o  changeset:   1694:c055f66f64c2
| |  branch:      eccount_merchant
| |  parent:      1692:7eef95617dde
| |  user:        albert
| |  date:        Fri Aug 23 17:56:19 2013 +0545
| |  summary:     UPDATE search ui, i18 text, search query condition
| |
o |  changeset:   1693:a14ffdea264f
|/   branch:      eccount_merchant
|    user:        prayag<prayag.upd@gmail.com>
|    date:        Sun Aug 25 11:55:27 2013 +0545
|    summary:     REFACTOR api-context to fix multiple component scan



[7] show changed files in the working directory
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg status

OR : show changed files sorting by date
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ ls -t1 `hg st -n -a -m -u` > modified.log

OR
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg diff --git

OR add following conf to ~/.hgrc to enable hg diff for vimdiff

[extensions]
hgext.extdiff =


[extdiff]
cmd.vimdiff =

And then fire command like as below
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg vimdiff build.gradle



[8] commit the specified files
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg commit zazzercode-gwt/src/main/java/com/zazzercode/client/admin/presenter/UserRolesPresenter.java   -m "REMOVE FEATURE of searching User Role, ADD FEATURE of Creating User" -u prayag;



[9] roll back the last transaction (dangerous)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg rollback
repository tip rolled back to revision 736 (undo commit)




[10] Show changesets not found in the specified destination repository
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg outgoing --stat -p


[11] Push changesets from the local repository to the specified destination
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg push -v

OR to track errors during push
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg push -v --debug --traceback


[12] hg log with --limit
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log --verbose --limit 1
changeset:   839:fd570795d841
tag:         tip
user:        prayag
date:        Mon Mar 11 11:56:33 2013 +0545
files: *.*, *.*
summary:     FIX slow reporting

OR log with -v (=verbose)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -v --limit 1

OR enable graphLOG extension 
[extensions]
color =
graphlog =

and then fire : 
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -G --limit 1

OR log of {modified files} for a spec revision(-r)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -r 839 --template '{files}\n'
equivalent to 
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -r839 --template '{files}\n'
zazzercode-gwt/src/main/java/com/zazzercode/client/admin/presenter/UserRolesPresenter.java


OR diffs in a spec changeset(-r)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -p -r 839
equivalent to 

prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg log -p -r839


OR log of all the changesets in the repository
$ hg log --template '{rev}:{node|short} {desc|firstline}\n' --limit 3
1053:2192d77f22ed ADD if PhoneNumber belongs to a User
1052:7f0d51d09ed4 FIX mobile messages 
1051:6da264634482 FIX password to raw

OR search log user wise 
$ hg log -b default -u prayag --keyword "agent"

hg log --template "{author|person}\n" | sort | uniq -c | sort -nr

136 prayag
104 hex


OR counting changed lines of code over time

$ echo `hg log -pr tip $@ | grep "^+" | wc -l` Additions; 
  echo `hg log -pr tip $@ | grep "^-" | wc -l` Deletions
528 Additions
37 Deletions


OR, alias it to .hgrc
[alias]
lines = !echo `hg log -pr $@ | grep "^+" | wc -l` Additions; echo `hg log -pr $@ | grep "^-" | wc -l` Deletions;



[14] search by a commit message
Use -k option followed by search query.
$ log -k FIX --template "{author|person} | {desc}\n"


[14] hg merge from a branch feat-x
Switch to a branch that needs to be merged (say default needs to get changes from branch feat-x)
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg checkout default

prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg merge feat-x

prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg commit -m "MERGE from feat-x to default";

[15] hg list conflicted files
prayag@Prayag:~/workspace_zazzercodehg/zazzercode-hg$ hg resolve --list




Keyboard Shortcuts for vimdiff
Diff copying
do                        - Get changes from other window into the current window.
dp                        - Put the changes from current window into the other window.

Jump-to-diffs
]c                          - Jump to the next change.
[c                          - Jump to the previous change.

Ctrl W + Ctrl W - Switch to the other split window.


[20] fix hg lock



$ rm -r wlock

References
[1] Mercurial: The Definitive Guideby Bryan O'Sullivan http://hgbook.red-bean.com/read/mercurial-in-daily-use.html

[2] http://tortoisehg.bitbucket.org/manual/0.9/changelog.html#sync-bar


[3] Chapter 5 Mercurial in daily use, http://foozy.bitbucket.org/hgbook-ja/d6ca1334a19d/hgbookch5.html

[4] http://stackoverflow.com/a/9617214/432903

[5] Counting changed lines of code over time, http://stackoverflow.com/a/10252342

[6] Mercurial Diff Merge: What tool is this and how do I use it?, http://stackoverflow.com/a/6097728/432903

[7] Quick and Dirty : vimdiff Tutorial, http://amjith.blogspot.com/2008/08/quick-and-dirty-vimdiff-tutorial.html

[8] http://stackoverflow.com/a/2913154/432903

[9]My Mercurial Setup (Plus Some Useful Shims and Jigs), @tednaleid, http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/