git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] "stg cp", and StGIT doc updates
@ 2007-03-09 23:18 Yann Dirson
  2007-03-09 23:18 ` [PATCH 1/3] Add 'stg cp' command Yann Dirson
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Yann Dirson @ 2007-03-09 23:18 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git

"stg cp" comes to complement "add" and "rm".  I originally thought to
complement the whole with "stg mv", but I wonder whether the all 4 of
them eally have a place in StGIT.  Shouldn't we just use git/cogito
for such operations ?  In this case, this patch should indeed be
retargetted to be a git-cp command (it has anyway no real dependency
on StGIT, and the feature would be more generally useful).

The 2 other patches just try to improve the docs.

-- 
Yann Dirson    <ydirson@altern.org> |
Debian-related: <dirson@debian.org> |   Support Debian GNU/Linux:
                                    |  Freedom, Power, Stability, Gratis
     http://ydirson.free.fr/        | Check <http://www.debian.org/>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] Add 'stg cp' command.
  2007-03-09 23:18 [PATCH 0/3] "stg cp", and StGIT doc updates Yann Dirson
@ 2007-03-09 23:18 ` Yann Dirson
  2007-03-09 23:18 ` [PATCH 2/3] Do not link to docs that will never be written Yann Dirson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Yann Dirson @ 2007-03-09 23:18 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git


Supports copying several files and dirs into existing dir, as well as
copying single file or dir with a new name.

In the case of directory copying, only copies files known to git (ie,
no generated files).  Should maybe add --all as alternative.

Does not check whether we're going to lose data (overwriting any
modified file, or any file not tracked by git).  This should probably
be done first, before doing any real change (preparing the changes
in-memory, then do the work if OK).  Will give us --dry-run at no
additional cost.

Signed-off-by: Yann Dirson <ydirson@altern.org>
---

 Documentation/stg-cp.txt      |   59 +++++++++++++++++++++++++++++++++++++++++
 Documentation/stg.txt         |    2 +
 contrib/stgit-completion.bash |    1 +
 stgit/commands/copy.py        |   44 +++++++++++++++++++++++++++++++
 stgit/git.py                  |   57 ++++++++++++++++++++++++++++++++++++++++
 stgit/main.py                 |    2 +
 6 files changed, 165 insertions(+), 0 deletions(-)

diff --git a/Documentation/stg-cp.txt b/Documentation/stg-cp.txt
new file mode 100644
index 0000000..f499309
--- /dev/null
+++ b/Documentation/stg-cp.txt
@@ -0,0 +1,59 @@
+stg-cp(1)
+=========
+Yann Dirson <ydirson@altern.org>
+v0.13, March 2007
+
+NAME
+----
+stg-cp - stgdesc:cp[]
+
+SYNOPSIS
+--------
+stg cp [OPTIONS] <file|dir> <newname>
+
+stg cp [OPTIONS] <files|dirs...> <dir>
+
+DESCRIPTION
+-----------
+
+Make git-controlled copies of git-controlled files.  The copies are
+added to the Git index, so you can add them to a patch with
+stglink:refresh[].
+
+In the first form, copy a single file or a single directory, with a
+new name.  The parent directory of <newname> must already exist;
+<newname> itself must not already exist, or the command will be
+interpreted as one of the second form.
+
+In the second form, copy one or several files and/or directories, into
+an existing directory.
+
+Directories are copied recursively.  Only the git-controlled files
+under the named directories are copied and added to the index.  Any
+file not known to Git will not be copied.
+
+CAVEATS
+-------
+
+The first form doesn't allow yet to overwrite an existing file
+(whether it could be recovered from Git or not), and the second form
+does not check before overwriting any file, possibly leading to loss
+of non-committed modifications.
+
+FUTURE OPTIONS
+--------------
+
+--all::
+	Also copy files not known to Git when copying a directory.
+
+--force::
+	Force overwriting of target files, even if overwritten files
+	have non-committed changes or are not known to Git.
+
+--dry-run::
+	Show which files would be added, and which would be modified
+	if --force would be added.
+
+StGIT
+-----
+Part of the StGIT suite - see gitlink:stg[7].
diff --git a/Documentation/stg.txt b/Documentation/stg.txt
index 571e53a..002606f 100644
--- a/Documentation/stg.txt
+++ b/Documentation/stg.txt
@@ -185,6 +185,8 @@ stglink:add[]::
 	stgdesc:add[]
 stglink:rm[]::
 	stgdesc:rm[]
+stglink:cp[]::
+	stgdesc:cp[]
 stglink:status[]::
 	stgdesc:status[]
 stglink:diff[]::
diff --git a/contrib/stgit-completion.bash b/contrib/stgit-completion.bash
index 18645dc..09614dc 100644
--- a/contrib/stgit-completion.bash
+++ b/contrib/stgit-completion.bash
@@ -20,6 +20,7 @@ _stg_commands="
     clean
     clone
     commit
+    cp
     export
     files
     float
diff --git a/stgit/commands/copy.py b/stgit/commands/copy.py
new file mode 100644
index 0000000..76e3bf9
--- /dev/null
+++ b/stgit/commands/copy.py
@@ -0,0 +1,44 @@
+
+__copyright__ = """
+Copyright (C) 2007, Yann Dirson <ydirson@altern.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'copy files inside the repository'
+usage = """%prog [options] [<file/dir> <newname> | <files/dirs...> <dir>]
+
+Copy of the files and dirs passed as arguments under another name or
+location inside the same repository."""
+
+options = []
+
+def func(parser, options, args):
+    """Copy files inside the repository
+    """
+    if len(args) < 1:
+        parser.error('incorrect number of arguments')
+
+    if not crt_series.get_current():
+        raise CmdException, 'No patches applied'
+
+    git.copy(args[0:-1], args[-1])
diff --git a/stgit/git.py b/stgit/git.py
index f9094cd..9129c92 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os, popen2, re, gitmergeonefile
+from shutil import copyfile
 
 from stgit import basedir
 from stgit.utils import *
@@ -428,6 +429,62 @@ def add(names):
         if __run('git-update-index --add --', files):
             raise GitException, 'Unable to add file'
 
+def __copy_single(source, target, target2=''):
+    """Copy file or dir named 'source' to name target+target2"""
+
+    # "source" (file or dir) must match one or more git-controlled file
+    realfiles = _output_lines(['git-ls-files', source])
+    if len(realfiles) == 0:
+        raise GitException, '"%s" matches no git-controled files' % source
+
+    if os.path.isdir(source):
+        # physically copy the files, and record them to add them in one run
+        newfiles = []
+        re_string='^'+source+'/(.*)$'
+        prefix_regexp = re.compile(re_string)
+        for f in [f.strip() for f in realfiles]:
+            m = prefix_regexp.match(f)
+            if not m:
+                print '"%s" does not match "%s"' % (f, re_string)
+                assert(m)
+            newname = target+target2+'/'+m.group(1)
+            if not os.path.exists(os.path.dirname(newname)):
+                os.makedirs(os.path.dirname(newname))
+            copyfile(f, newname)
+            newfiles.append(newname)
+
+        add(newfiles)
+    else: # files, symlinks, ...
+        newname = target+target2
+        copyfile(source, newname)
+        add([newname])
+
+
+def copy(filespecs, target):
+    if os.path.isdir(target):
+        # target is a directory: copy each entry on the command line,
+        # with the same name, into the target
+        for filespec in filespecs:
+            filespec = filespec.rstrip('/')
+            basename = '/' + os.path.basename(filespec)
+            __copy_single(filespec, target, basename)
+
+    elif os.path.exists(target):
+        raise GitException, 'Target "%s" exists but is not a directory' % target
+    elif len(filespecs) != 1:
+        raise GitException, 'Cannot copy more than one file to non-directory'
+
+    else:
+        # at this point: len(filespecs)==1 and target does not exist
+
+        # check target directory
+        targetdir = os.path.dirname(target)
+        if targetdir != '' and not os.path.isdir(targetdir):
+            raise GitException, 'Target directory "%s" does not exist' % targetdir
+
+        __copy_single(filespecs[0].rstrip('/'), target)
+        
+
 def rm(files, force = False):
     """Remove a file from the repository
     """
diff --git a/stgit/main.py b/stgit/main.py
index 9fcbbc2..856b868 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -68,6 +68,7 @@ commands = Commands({
     'clean':            'clean',
     'clone':            'clone',
     'commit':           'commit',
+    'cp':		'copy',
     'export':           'export',
     'files':            'files',
     'float':            'float',
@@ -143,6 +144,7 @@ patchcommands = (
     )
 wccommands = (
     'add',
+    'cp',
     'diff',
     'resolved',
     'rm',

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] Do not link to docs that will never be written.
  2007-03-09 23:18 [PATCH 0/3] "stg cp", and StGIT doc updates Yann Dirson
  2007-03-09 23:18 ` [PATCH 1/3] Add 'stg cp' command Yann Dirson
@ 2007-03-09 23:18 ` Yann Dirson
  2007-03-09 23:18 ` [PATCH 3/3] Some clarifications to the main doc Yann Dirson
  2007-03-12 16:20 ` [PATCH 0/3] "stg cp", and StGIT doc updates Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Yann Dirson @ 2007-03-09 23:18 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git




Signed-off-by: Yann Dirson <ydirson@altern.org>
---

 Documentation/stg.txt |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/stg.txt b/Documentation/stg.txt
index 002606f..60a6f9c 100644
--- a/Documentation/stg.txt
+++ b/Documentation/stg.txt
@@ -65,11 +65,11 @@ Generic commands
 
 User-support commands not touching the repository.
 
-stglink:help[]::
+stg help::
 	stgdesc:help[]
-stglink:version[]::
+stg version::
 	stgdesc:version[]
-stglink:copyright[]::
+stg copyright::
 	stgdesc:copyright[]
 
 Repository commands

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Some clarifications to the main doc.
  2007-03-09 23:18 [PATCH 0/3] "stg cp", and StGIT doc updates Yann Dirson
  2007-03-09 23:18 ` [PATCH 1/3] Add 'stg cp' command Yann Dirson
  2007-03-09 23:18 ` [PATCH 2/3] Do not link to docs that will never be written Yann Dirson
@ 2007-03-09 23:18 ` Yann Dirson
  2007-03-12 16:20 ` [PATCH 0/3] "stg cp", and StGIT doc updates Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Yann Dirson @ 2007-03-09 23:18 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git




Signed-off-by: Yann Dirson <ydirson@altern.org>
---

 Documentation/stg.txt |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Documentation/stg.txt b/Documentation/stg.txt
index 60a6f9c..7d92356 100644
--- a/Documentation/stg.txt
+++ b/Documentation/stg.txt
@@ -21,19 +21,33 @@ GIT. These operations are performed using GIT commands and the patches
 are stored as GIT commit objects, allowing easy merging of the StGIT
 patches into other repositories using standard GIT functionality.
 
+An StGIT stack is a GIT branch with additional information to help
+making changes to individual patches you already committed, rather
+than making changes by adding new commits.  It is thus a
+non-forwarding, or rewinding branch: the old head of the branch is
+often not reachable as one of the new head's ancestors.
+
 Typical uses of StGIT include:
 
 Tracking branch::
-	Maintaining modifications against a remote branch, possibly
-	with the intent of sending some patches upstream.  StGIT
-	assists in preparing and cleaning up patches until they are
-	acceptable upstream, as well as maintaining local patches not
-	meant to be sent upstream.
+	Tracking changes from a remote branch, while maintaining local
+	modifications against that branch, possibly with the intent of
+	sending some patches upstream.  StGIT assists in preparing and
+	cleaning up patches until they are acceptable upstream, as
+	well as maintaining local patches not meant to be sent
+	upstream.
++
+In such a setup, typically all commits on your branch are StGIT
+patches; the stack base is the branch point where your changes "fork"
+off their parent branch.
 
 Development branch::
 	Preparing and testing your commits before publishing them,
 	separating your features from unrelated bugfixes collected
 	while developping.
++
+In such a setup, not all commits on your branch need to be StGIT
+patches; there may be regular GIT commits below your stack base.
 
 OPTIONS
 -------

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] "stg cp", and StGIT doc updates
  2007-03-09 23:18 [PATCH 0/3] "stg cp", and StGIT doc updates Yann Dirson
                   ` (2 preceding siblings ...)
  2007-03-09 23:18 ` [PATCH 3/3] Some clarifications to the main doc Yann Dirson
@ 2007-03-12 16:20 ` Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2007-03-12 16:20 UTC (permalink / raw)
  To: Yann Dirson; +Cc: git

On 09/03/07, Yann Dirson <ydirson@altern.org> wrote:
> "stg cp" comes to complement "add" and "rm".  I originally thought to
> complement the whole with "stg mv", but I wonder whether the all 4 of
> them eally have a place in StGIT.  Shouldn't we just use git/cogito
> for such operations ?  In this case, this patch should indeed be
> retargetted to be a git-cp command (it has anyway no real dependency
> on StGIT, and the feature would be more generally useful).

I think we should have these commands in StGIT, even if they would
just call the corresponding git commands. The reason is that we may
later decide to implement some other behaviour (i.e. use a separate
index when working on a patch).

-- 
Catalin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-12 16:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-09 23:18 [PATCH 0/3] "stg cp", and StGIT doc updates Yann Dirson
2007-03-09 23:18 ` [PATCH 1/3] Add 'stg cp' command Yann Dirson
2007-03-09 23:18 ` [PATCH 2/3] Do not link to docs that will never be written Yann Dirson
2007-03-09 23:18 ` [PATCH 3/3] Some clarifications to the main doc Yann Dirson
2007-03-12 16:20 ` [PATCH 0/3] "stg cp", and StGIT doc updates Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).