Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:54:36+00:00 2026-05-25T05:54:36+00:00

I am trying to write a small Mercurial extension, which, given the path to

  • 0

I am trying to write a small Mercurial extension, which, given the path to an object stored within the repository, it will tell you the revision it’s at. So far, I’m working on the code from the WritingExtensions article, and I have something like this:

cmdtable = {
    # cmd name        function call
    "whichrev": (whichrev,[],"hg whichrev FILE")
}

and the whichrev function has almost no code:

def whichrev(ui, repo, node, **opts):
    # node will be the file chosen at the command line
    pass

So , for example:

hg whichrev text_file.txt

Will call the whichrev function with node being set to text_file.txt. With the use of the debugger, I found that I can access a filelog object, by using this:

repo.file("text_file.txt")

But I don’t know what I should access in order to get to the sha1 of the file.I have a feeling I may not be working with the right function.

Given a path to a tracked file ( the file may or may not appear as modified under hg status ), how can I get it’s sha1 from my extension?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:54:36+00:00Added an answer on May 25, 2026 at 5:54 am

    A filelog object is pretty low level, you probably want a filectx:

    A filecontext object makes access to data related to a particular filerevision convenient.

    You can get one through a changectx:

    ctx = repo['.']
    fooctx = ctx['foo']
    print fooctx.filenode()
    

    Or directly through the repo:

    fooctx = repo.filectx('foo', '.')
    

    Pass None instead of . to get the working copy ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a small wsgi application which will put some objects to
I've been trying to write a small application which will work with mysql in
I am trying to write a small demo which will maintain a fixed number
I'm trying to write a small Python module which contain some mathematical functions. For
I'm trying to write a small Powershell function that will return some summary data
I am trying to write a small program which has to store and retrieve
I'm trying to write a small ruby script that detects if a given argument
I'm trying to write a small batch script that will delete files old files
i'm trying to write a small java class. I have an object called BigNumber.
I'm trying to write a small app which can be used in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.