[PATCH] umask for multiple commiters

Aurelien Jacobs aurel at gnuage.org
Tue Nov 7 19:01:49 CST 2006


On Thu, 2 Nov 2006 00:47:10 +0100
Aurelien Jacobs <aurel at gnuage.org> wrote:

> On Thu, 26 Oct 2006 11:08:04 +0200
> Thomas Arendsen Hein <thomas at intevation.de> wrote:
> 
> > * Aurelien Jacobs <aurel at gnuage.org> [20061025 23:34]:
> > 
> > > # 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.
> 
> First let me say that this previous patch was already doing a chmod
> only for file/directory creation, not for simple file write.
> 
> But I agree with you that a stat for each file creation might be a bit
> too much. So I improved this.
> I still kept chmod instead of changing umask. I guess that doing a chmod
> on a just created (ie. buffered) file is not worst than doing 2 umask call.
> 
> About the complexity for creating N files:
>   * previous patch:
>      - N stat()
>      - N chmod()
>   * new patch:
>      - 1 stat() if N > 0
>      - N chmod() only if needed (ie. if current umask is not enough)
> 
> I hope this patch is now ok.

Did anyone had a look at it ?

Aurel


More information about the Mercurial-devel mailing list