monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone: 3af2ed4ffe4d0d0a787666ff6e


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone: 3af2ed4ffe4d0d0a787666ff6e36047b6359bd4e
Date: Sun, 5 Dec 2010 17:18:08 GMT

revision:            3af2ed4ffe4d0d0a787666ff6e36047b6359bd4e
date:                2010-12-05T17:17:57
author:              address@hidden
branch:              net.venge.monotone
changelog:
Added the mtn-cleanup Perl script to the contrib directory and updated the
corresponding README file.

manifest:
format_version "1"

new_manifest [271d007487e1b94ff0a103da29ea70bab518435b]

old_revision [4510a77f169a686131072b6db8e42942c8220b28]

add_file "contrib/mtn-cleanup"
 content [822d3765de19217b4c0273ee4d169a582fc08cdd]

patch "NEWS"
 from [82e6621761e40979b4cdf7be2d5e500db32bb43d]
   to [732a6a6e3f7861d4941df4407664f3c5806e2354]

patch "contrib/README"
 from [7c9f4bc113328aed148c7a09a73a0979b0b0d431]
   to [ae0c22f6e14507960ff42ab224de495e0bec3675]

  set "contrib/mtn-cleanup"
 attr "mtn:execute"
value "true"
============================================================
--- NEWS	82e6621761e40979b4cdf7be2d5e500db32bb43d
+++ NEWS	732a6a6e3f7861d4941df4407664f3c5806e2354
@@ -46,7 +46,13 @@ XXX XXX XX XX:XX:XX UTC 2010
 
         Internal
 
+        Other
 
+        - Added the mtn-cleanup Perl script that returns a workspace to its
+          pristine state with the minimum amount of change. This script is
+          under the contrib directory.
+
+
 Sun Oct 31 21:51:16 UTC 2010
 
         0.99.1 release.
============================================================
--- contrib/README	7c9f4bc113328aed148c7a09a73a0979b0b0d431
+++ contrib/README	ae0c22f6e14507960ff42ab224de495e0bec3675
@@ -25,6 +25,10 @@ See individual files for licenses.
      For a manual, do `perl Notify.pl --man'.
      To get a help text, do `perl Notify.pl --help'.
 
+  -- mtn-cleanup: A Perl script for returning a workspace to its pristine state
+     with the minimum of change (i.e. missing files are restored, changed files
+     are reverted and new files are removed).
+
   -- Monotone.pm: A Perl module to access a 'mtn automate stdio' subprocess.
 
   -- monoprof.sh: A simple monotone profiling script.
============================================================
--- /dev/null	
+++ contrib/mtn-cleanup	822d3765de19217b4c0273ee4d169a582fc08cdd
@@ -0,0 +1,238 @@
+#!/usr/bin/perl -w
+##############################################################################
+#
+#   File Name    - mtn-clean-revert
+#
+#   Description  - Remove all extra files from a Monotone workspace and then
+#                  revert the revision based files.
+#
+#   Author       - A.E.Cooper.
+#
+#   Legal Stuff  - Copyright (c) 2007 Anthony Edward Cooper
+#                  <address@hidden>.
+#
+#                  This program is free software; you can redistribute it
+#                  and/or modify it under the terms of the GNU General Public
+#                  License as published by the Free Software Foundation;
+#                  either version 3 of the License, or (at your option) any
+#                  later version.
+#
+#                  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 software; if not, write to the Free
+#                  Software Foundation, Inc., 59 Temple Place - Suite 330,
+#                  Boston, MA 02111-1307 USA.
+#
+##############################################################################
+#
+##############################################################################
+#
+#   GLOBAL DATA FOR THIS MODULE
+#
+##############################################################################
+
+
+
+# ***** DIRECTIVES *****
+
+require 5.008005;
+
+use strict;
+use English;
+use integer;
+
+# ***** REQUIRED PACKAGES *****
+
+use File::Basename;
+use File::Spec;
+
+# ***** GLOBAL DATA DECLARATIONS *****
+
+# The name of this script.
+
+use constant SCRIPT => basename($PROGRAM_NAME);
+
+# The manifest hit list hash. The key is the file name relative to the
+# work-space, the value is unimportant. If you do a lookup of a file against
+# this hash and the result is defined then that file exists in the Monotone
+# manifest.
+
+my %manifest;
+
+# ***** FUNCTIONAL PROTOTYPES FOR THIS FILE *****
+
+sub cleanup_workspace($);
+sub get_manifest_hit_list($);
+#
+##############################################################################
+#
+#   Routine      - Main Body Of Code
+#
+#   Description  - This is the main body of code for the tools script.
+#
+#   Data         - @_           : The command line arguments.
+#                  Return Value : Unix exit code.
+#
+##############################################################################
+
+
+
+my $response;
+
+# First check that we are at the top level of a Monotone work-space.
+
+if (! -d "_MTN")
+{
+    printf(STDERR
+	   "%s: This command must be run from the work-space's base "
+	       . "directory.\n",
+	   SCRIPT);
+    exit(1);
+}
+
+# This is a dangerous command to run, so warn the user.
+
+printf("%s: Warning - This will remove all files that have not been "
+           . "committed.\n",
+       SCRIPT);
+printf("Proceed (Y/N)[N]: ");
+$response = readline(STDIN);
+chomp($response);
+if ($response =~ m/^[yY]$/)
+{
+    get_manifest_hit_list(\%manifest);
+    cleanup_workspace("");
+    printf("Now reverting files...\n");
+    system("mtn", "revert", ".");
+}
+
+exit 0;
+#
+##############################################################################
+#
+#   Routine      - cleanup_workspace
+#
+#   Description  - Traverse the workspace removing anything that isn't listed
+#                  in the manifest.
+#
+#   Data         - $directory : The directory that is to be cleaned.
+#
+##############################################################################
+
+
+
+sub cleanup_workspace($)
+{
+
+    my ($directory) = @_;
+
+    my ($dir_handle,
+	$file,
+	@files,
+	$rel_path);
+
+    if ($directory eq "")
+    {
+	opendir($dir_handle, ".") or die("opendir failed: $!");
+    }
+    else
+    {
+	opendir($dir_handle, $directory) or die("opendir failed: $!");
+    }
+    @files = sort readdir($dir_handle);
+    close($dir_handle);
+
+    foreach $file (@files)
+    {
+	if ($directory eq "")
+	{
+	    $rel_path = $file;
+	}
+	else
+	{
+	    $rel_path = File::Spec->catfile($directory, $file);
+	}
+	if (-d $rel_path)
+	{
+	    if ($file ne "." && $file ne ".." && $file ne "_MTN")
+	    {
+		if ($manifest{$rel_path})
+		{
+		    cleanup_workspace($rel_path);
+		}
+		else
+		{
+		    printf("Removing directory %s...\n", $rel_path);
+		    system("/bin/rm", "-rf", $rel_path);
+		}
+	    }
+	}
+	else
+	{
+	    if (! $manifest{$rel_path})
+	    {
+		printf("Removing file %s...\n", $rel_path);
+		unlink($rel_path);
+	    }
+	}
+    }
+
+}
+#
+##############################################################################
+#
+#   Routine      - get_manifest_hit_list
+#
+#   Description  - Generates a boolean hash keyed on manifest file names, the
+#                  value is not important but is just set to 1.
+#
+#   Data         - $manifest_ref : A reference to a hash that is to contain
+#                                  the manifest hit list hash.
+#
+##############################################################################
+
+
+
+sub get_manifest_hit_list($)
+{
+
+    my ($manifest_ref) = @_;
+
+    my ($entry,
+	$handle,
+        $line,
+        $rev_id);
+
+    %$manifest_ref = ();
+
+    $rev_id = `mtn automate get_base_revision_id 2> /dev/null`
+	or die("mtn automate get_base_revision_id failed: $!");
+    chomp($rev_id);
+
+    open($handle, "-|", "mtn automate get_manifest_of " . $rev_id)
+	or die("open failed: $!");
+    for ($line = readline($handle); $line; $line = readline($handle))
+    {
+	chomp($line);
+	$entry = undef;
+	if ($line =~ m/^   file \"/)
+	{
+	    ($entry) = ($line =~ m/^   file \"([^\"]+)\"$/);
+	}
+	if ($line =~ m/^dir \"/)
+	{
+	    ($entry) = ($line =~ m/^dir \"([^\"]+)\"$/);
+	}
+	if ($entry)
+	{
+	    $$manifest_ref{$entry} = 1;
+	}
+    }
+    close($handle);
+
+}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]