[PATCH] umask for multiple commiters

Thomas Arendsen Hein thomas at intevation.de
Thu Oct 26 09:08:04 UTC 2006


* Aurelien Jacobs <aurel at gnuage.org> [20061025 23:34]:
> It now only affect file/directory creation inside .hg.
> Mode setting on .hg itself must still be done by hand.
> So this should really be safe.

Good.

> # HG changeset patch
> # User Aurelien Jacobs <aurel at gnuage.org>
> # Date 1161811194 -7200
> # Node ID dae3a8fc0522fe8af4678676ae5424e756b4ef0e
> # Parent  9383af6f236d1e9c5dcbc7d9b6145adb1aff0eb8
> inherit parent directory mode when creating new file

> +        os.chmod(name,os.stat(parent).st_mode)

> +                st_mode = os.stat(d).st_mode & 0666

> +        if st_mode is not None:
> +            os.chmod(f, st_mode)

Maybe there are still too many stat/chmod calls, I suggest the
following:

On repo object creation, look at the mode of the .hg and check if
the user's umask is permissive enough to create it.
Something like this code:

    umask = os.umask(0)
    os.umask(umask)
    repomask = umask & ~st.st_mode
    if repomask != umask:
        self.ui.warn("Overriding your umask %04o with $04o for repository\n"
                % (umask, repomask))
        self.repomask = repomask
    else:
        self.repomask = None

And whenever writing to the repository (i.e. below .hg):

    if self.repomask is not None:
        umask = os.umask(self.repomask)
    else:
        umask = None
    foo(bar, whatever)
    if umask is not None:
        os.umask(umask)

Instead of changing with the umask, I can imagine doing a chmod on
file or directory creation, too, but only on creation, not every
time writing to a file.

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/



More information about the Mercurial-devel mailing list